Class NettyHttpServer
java.lang.Object
eu.cloudnetservice.driver.network.netty.NettySslServer
eu.cloudnetservice.driver.network.netty.http.NettyHttpServer
- All Implemented Interfaces:
HttpComponent<HttpServer>,HttpServer,AutoCloseable
The default implementation of the web server, using netty as its backing mechanism.
- Since:
- 4.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordRepresents a registered http handler, holding all the information needed for later calling of it. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final HttpAnnotationParser<HttpServer>protected final io.netty5.channel.EventLoopGroupprotected final Map<HostAndPort,io.netty5.util.concurrent.Future<Void>> private static final eu.cloudnetservice.common.log.Loggerprotected final Collection<NettyHttpServer.HttpHandlerEntry>protected final io.netty5.channel.EventLoopGroupFields inherited from class eu.cloudnetservice.driver.network.netty.NettySslServer
sslConfiguration, sslContext -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new instance of a netty http server instance.NettyHttpServer(@Nullable SSLConfiguration sslConfiguration) Constructs a new netty http server instance with the given ssl configuration. -
Method Summary
Modifier and TypeMethodDescriptionaddListener(int port) Binds this http server to the given port on any local address (ipv6 form:::/0) if no other listener is already listening to that port.addListener(@NonNull HostAndPort hostAndPort) Binds this network server to the given host and port if no listener is already listening on the given address.Get a http annotation parser which is associated with this component and can therefore be used to register annotated handlers to this component.Removes all handlers which were previously registered to this component.voidclose()Get all handlers which were registered to this component.registerHandler(@NonNull String path, int priority, HttpHandler... handlers) Registers the given handlers to this component.registerHandler(@NonNull String path, @Nullable Integer port, int priority, @NonNull HttpHandler... handlers) Registers the given handlers to this component.registerHandler(@NonNull String path, HttpHandler... handlers) Registers the given handlers to this component.removeHandler(@NonNull HttpHandler handler) Unregisters the given handler from this component if it was registered previously.removeHandler(@NonNull ClassLoader classLoader) Removes all registered handlers from this component whose classes were loaded by the given class loader.booleanGets whether this component has ssl enabled or not.Methods inherited from class eu.cloudnetservice.driver.network.netty.NettySslServer
init
-
Field Details
-
LOGGER
private static final eu.cloudnetservice.common.log.Logger LOGGER -
channelFutures
-
registeredHandlers
-
bossGroup
protected final io.netty5.channel.EventLoopGroup bossGroup -
workerGroup
protected final io.netty5.channel.EventLoopGroup workerGroup -
annoParser
-
-
Constructor Details
-
NettyHttpServer
public NettyHttpServer()Constructs a new instance of a netty http server instance. Equivalent tonew NettyHttpServer(null). -
NettyHttpServer
Constructs a new netty http server instance with the given ssl configuration.- Parameters:
sslConfiguration- the ssl configuration to use, null for no ssl.
-
-
Method Details
-
sslEnabled
public boolean sslEnabled()Gets whether this component has ssl enabled or not.- Specified by:
sslEnabledin interfaceHttpComponent<HttpServer>- Returns:
- whether this component has ssl enabled or not.
-
annotationParser
Get a http annotation parser which is associated with this component and can therefore be used to register annotated handlers to this component.- Specified by:
annotationParserin interfaceHttpComponent<HttpServer>- Returns:
- the associated http annotation parser instance.
-
addListener
Binds this http server to the given port on any local address (ipv6 form:::/0) if no other listener is already listening to that port.- Specified by:
addListenerin interfaceHttpServer- Parameters:
port- the port to which the listener should get bound.- Returns:
- a future completed exceptionally if the bind fails, normally if the bind succeeded.
-
addListener
@NonNull public @NonNull eu.cloudnetservice.common.concurrent.Task<Void> addListener(@NonNull @NonNull HostAndPort hostAndPort) Binds this network server to the given host and port if no listener is already listening on the given address.- Specified by:
addListenerin interfaceHttpServer- Parameters:
hostAndPort- the address to which a listener should get bound.- Returns:
- a future completed exceptionally if the bind fails, normally if the bind succeeded.
-
registerHandler
@NonNull public @NonNull HttpServer registerHandler(@NonNull @NonNull String path, HttpHandler... handlers) Registers the given handlers to this component. The given handlers will get called when a request matches the given path. Equivalent tocomponent.registerHandler(path, HttpHandler.PRIORITY_NORMAL, handlers).- Specified by:
registerHandlerin interfaceHttpComponent<HttpServer>- Parameters:
path- the path to register the handler to.handlers- the handlers to register.- Returns:
- the same component instance as used to call the method, for chaining.
-
registerHandler
@NonNull public @NonNull HttpServer registerHandler(@NonNull @NonNull String path, int priority, HttpHandler... handlers) Registers the given handlers to this component. The given handlers will get called when a request matches the given path. Equivalent tocomponent.registerHandler(path, null, priority, handlers).- Specified by:
registerHandlerin interfaceHttpComponent<HttpServer>- Parameters:
path- the path to register the handler to.priority- the priority of the given handlers.handlers- the handlers to register.- Returns:
- the same component instance as used to call the method, for chaining.
-
registerHandler
@NonNull public @NonNull HttpServer registerHandler(@NonNull @NonNull String path, @Nullable @Nullable Integer port, int priority, @NonNull @NonNull HttpHandler... handlers) Registers the given handlers to this component. The given handlers will get called when a request matches the given path and (if provided) gets called on the same port as set here. The path may contain the following placeholders:*: Represents a wildcard character which matches anything provided in the path.{name}: Represents a path parameter you want to retrieve when handling the request.
- Specified by:
registerHandlerin interfaceHttpComponent<HttpServer>- Parameters:
path- the path to register the handler to.port- the port on which the handlers should get called, null represents all ports.priority- the priority of the given handlers.handlers- the handlers to register.- Returns:
- the same component instance as used to call the method, for chaining.
-
removeHandler
Unregisters the given handler from this component if it was registered previously.- Specified by:
removeHandlerin interfaceHttpComponent<HttpServer>- Parameters:
handler- the handler to unregister.- Returns:
- the same component instance as used to call the method, for chaining.
-
removeHandler
Removes all registered handlers from this component whose classes were loaded by the given class loader.- Specified by:
removeHandlerin interfaceHttpComponent<HttpServer>- Parameters:
classLoader- the loader of the handler classes to unregister.- Returns:
- the same component instance as used to call the method, for chaining.
-
httpHandlers
Get all handlers which were registered to this component.- Specified by:
httpHandlersin interfaceHttpComponent<HttpServer>- Returns:
- all handlers which were registered to this component.
-
clearHandlers
Removes all handlers which were previously registered to this component.- Specified by:
clearHandlersin interfaceHttpComponent<HttpServer>- Returns:
- the same component instance as used to call the method, for chaining.
-
close
public void close()- Specified by:
closein interfaceAutoCloseable
-