Package io.micronaut.http.server.netty
Class NettyHttpServer
java.lang.Object
io.micronaut.http.server.netty.NettyHttpServer
- All Implemented Interfaces:
io.micronaut.context.ApplicationContextLifeCycle<io.micronaut.runtime.server.EmbeddedServer>,io.micronaut.context.ApplicationContextProvider,io.micronaut.context.event.ApplicationEventListener<io.micronaut.runtime.context.scope.refresh.RefreshEvent>,io.micronaut.context.LifeCycle,io.micronaut.core.order.Ordered,io.micronaut.http.netty.channel.ChannelPipelineCustomizer,io.micronaut.http.netty.websocket.WebSocketSessionRepository,NettyEmbeddedServer,NettyServerCustomizer.Registry,io.micronaut.runtime.context.scope.refresh.RefreshEventListener,io.micronaut.runtime.EmbeddedApplication<io.micronaut.runtime.server.EmbeddedServer>,io.micronaut.runtime.server.EmbeddedServer,Closeable,AutoCloseable,EventListener
Implements the bootstrap and configuration logic for the Netty implementation of
EmbeddedServer.- Since:
- 1.0
- See Also:
-
RoutingInBoundHandler
-
Field Summary
FieldsFields inherited from interface io.micronaut.http.netty.channel.ChannelPipelineCustomizer
HANDLER_ACCESS_LOGGER, HANDLER_ACTIVITY_LISTENER, HANDLER_CONNECT_TTL, HANDLER_FLOW_CONTROL, HANDLER_HTTP_AGGREGATOR, HANDLER_HTTP_CHUNK, HANDLER_HTTP_CLIENT_CODEC, HANDLER_HTTP_CLIENT_INIT, HANDLER_HTTP_COMPRESSOR, HANDLER_HTTP_DECODER, HANDLER_HTTP_DECOMPRESSOR, HANDLER_HTTP_KEEP_ALIVE, HANDLER_HTTP_PROXY, HANDLER_HTTP_SERVER_CODEC, HANDLER_HTTP_STREAM, HANDLER_HTTP_TO_HTTPS_REDIRECT, HANDLER_HTTP2_CONNECTION, HANDLER_HTTP2_PROTOCOL_NEGOTIATOR, HANDLER_HTTP2_SETTINGS, HANDLER_HTTP2_UPGRADE_REQUEST, HANDLER_IDLE_STATE, HANDLER_INITIAL_ERROR, HANDLER_MICRONAUT_FULL_HTTP_RESPONSE, HANDLER_MICRONAUT_HTTP_RESPONSE_FULL, HANDLER_MICRONAUT_HTTP_RESPONSE_STREAM, HANDLER_MICRONAUT_INBOUND, HANDLER_MICRONAUT_SSE_CONTENT, HANDLER_MICRONAUT_SSE_EVENT_STREAM, HANDLER_MICRONAUT_WEBSOCKET_CLIENT, HANDLER_READ_TIMEOUT, HANDLER_SOCKS_5_PROXY, HANDLER_SSL, HANDLER_WEBSOCKET_UPGRADEFields inherited from interface io.micronaut.core.order.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCEFields inherited from interface io.micronaut.runtime.context.scope.refresh.RefreshEventListener
DEFAULT_POSITION -
Constructor Summary
ConstructorsConstructorDescriptionNettyHttpServer(NettyHttpServerConfiguration serverConfiguration, NettyEmbeddedServices nettyEmbeddedServices, NettyCustomizableResponseTypeHandlerRegistry handlerRegistry, boolean isDefault) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddChannel(io.netty.channel.Channel channel) io.netty.channel.embedded.EmbeddedChannelbuildEmbeddedChannel(boolean ssl) Builds Embedded Channel.voidbuildEmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel prototype, boolean ssl) Builds Embedded Channel.protected io.netty.channel.EventLoopGroupprotected io.netty.bootstrap.ServerBootstrapprotected io.netty.channel.EventLoopGroupcreateWorkerEventLoopGroup(io.micronaut.http.netty.channel.EventLoopGroupConfiguration workerConfig) voiddoOnConnect(io.micronaut.http.netty.channel.ChannelPipelineListener listener) io.micronaut.runtime.ApplicationConfigurationio.micronaut.context.ApplicationContextGets the set of all ports this Netty server is bound to.io.netty.channel.group.ChannelGroupgetHost()intgetPort()getURI()getURL()io.micronaut.http.netty.websocket.WebSocketSessionRepositorybooleanbooleanbooleanvoidonApplicationEvent(io.micronaut.runtime.context.scope.refresh.RefreshEvent event) voidregister(NettyServerCustomizer customizer) Register a new customizer with this server.voidremoveChannel(io.netty.channel.Channel channel) start()stop()Stops the Netty instance, but keeps the ApplicationContext running.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.micronaut.http.netty.channel.ChannelPipelineCustomizer
isServerChannelMethods inherited from interface io.micronaut.runtime.EmbeddedApplication
getEnvironment, isForceExitMethods inherited from interface io.micronaut.runtime.server.EmbeddedServer
isServerMethods inherited from interface io.micronaut.context.LifeCycle
close, refreshMethods inherited from interface io.micronaut.runtime.context.scope.refresh.RefreshEventListener
getOrder, supports
-
Field Details
-
OUTBOUND_KEY
- See Also:
-
-
Constructor Details
-
NettyHttpServer
public NettyHttpServer(NettyHttpServerConfiguration serverConfiguration, NettyEmbeddedServices nettyEmbeddedServices, NettyCustomizableResponseTypeHandlerRegistry handlerRegistry, boolean isDefault) - Parameters:
serverConfiguration- The Netty HTTP server configurationnettyEmbeddedServices- The embedded server contexthandlerRegistry- The handler registryisDefault- Is this the default server
-
-
Method Details
-
isKeepAlive
public boolean isKeepAlive()- Specified by:
isKeepAlivein interfaceio.micronaut.runtime.server.EmbeddedServer
-
getServerConfiguration
- Returns:
- The configuration for the server
-
isRunning
public boolean isRunning()- Specified by:
isRunningin interfaceio.micronaut.context.LifeCycle
-
start
- Specified by:
startin interfaceio.micronaut.context.ApplicationContextLifeCycle<io.micronaut.runtime.server.EmbeddedServer>- Specified by:
startin interfaceio.micronaut.context.LifeCycle- Specified by:
startin interfaceNettyEmbeddedServer
-
stop
- Specified by:
stopin interfaceio.micronaut.context.ApplicationContextLifeCycle<io.micronaut.runtime.server.EmbeddedServer>- Specified by:
stopin interfaceio.micronaut.context.LifeCycle- Specified by:
stopin interfaceNettyEmbeddedServer
-
stopServerOnly
Description copied from interface:NettyEmbeddedServerStops the Netty instance, but keeps the ApplicationContext running. This for CRaC checkpointing purposes.- Specified by:
stopServerOnlyin interfaceNettyEmbeddedServer- Returns:
- The stopped NettyEmbeddedServer
-
register
Description copied from interface:NettyServerCustomizer.RegistryRegister a new customizer with this server. Note that this method must be called before the server is started: When a listener launches, it may only respect the customizers that were registered at the time, and ignore future additions.- Specified by:
registerin interfaceNettyEmbeddedServer- Specified by:
registerin interfaceNettyServerCustomizer.Registry- Parameters:
customizer- The customizer to register.
-
getPort
public int getPort()- Specified by:
getPortin interfaceio.micronaut.runtime.server.EmbeddedServer
-
getHost
- Specified by:
getHostin interfaceio.micronaut.runtime.server.EmbeddedServer
-
getScheme
- Specified by:
getSchemein interfaceio.micronaut.runtime.server.EmbeddedServer
-
getURL
- Specified by:
getURLin interfaceio.micronaut.runtime.server.EmbeddedServer
-
getURI
- Specified by:
getURIin interfaceio.micronaut.runtime.server.EmbeddedServer
-
getApplicationContext
public io.micronaut.context.ApplicationContext getApplicationContext()- Specified by:
getApplicationContextin interfaceio.micronaut.context.ApplicationContextProvider- Specified by:
getApplicationContextin interfaceio.micronaut.runtime.EmbeddedApplication<io.micronaut.runtime.server.EmbeddedServer>
-
getApplicationConfiguration
public io.micronaut.runtime.ApplicationConfiguration getApplicationConfiguration()- Specified by:
getApplicationConfigurationin interfaceio.micronaut.runtime.EmbeddedApplication<io.micronaut.runtime.server.EmbeddedServer>
-
getBoundPorts
Description copied from interface:NettyEmbeddedServerGets the set of all ports this Netty server is bound to.- Specified by:
getBoundPortsin interfaceNettyEmbeddedServer- Returns:
- An immutable set of bound ports if the server has been started with
NettyEmbeddedServer.start()an empty set otherwise.
-
createParentEventLoopGroup
protected io.netty.channel.EventLoopGroup createParentEventLoopGroup()- Returns:
- The parent event loop group
-
createWorkerEventLoopGroup
protected io.netty.channel.EventLoopGroup createWorkerEventLoopGroup(@Nullable io.micronaut.http.netty.channel.EventLoopGroupConfiguration workerConfig) - Parameters:
workerConfig- The worker configuration- Returns:
- The worker event loop group
-
createServerBootstrap
protected io.netty.bootstrap.ServerBootstrap createServerBootstrap()- Returns:
- The Netty server bootstrap
-
addChannel
public void addChannel(io.netty.channel.Channel channel) - Specified by:
addChannelin interfaceio.micronaut.http.netty.websocket.WebSocketSessionRepository
-
removeChannel
public void removeChannel(io.netty.channel.Channel channel) - Specified by:
removeChannelin interfaceio.micronaut.http.netty.websocket.WebSocketSessionRepository
-
getChannelGroup
public io.netty.channel.group.ChannelGroup getChannelGroup()- Specified by:
getChannelGroupin interfaceio.micronaut.http.netty.websocket.WebSocketSessionRepository
-
getWebSocketSessionRepository
public io.micronaut.http.netty.websocket.WebSocketSessionRepository getWebSocketSessionRepository()- Returns:
NettyHttpServerwhich implementsWebSocketSessionRepository
-
isClientChannel
public boolean isClientChannel()- Specified by:
isClientChannelin interfaceio.micronaut.http.netty.channel.ChannelPipelineCustomizer
-
doOnConnect
public void doOnConnect(@NonNull io.micronaut.http.netty.channel.ChannelPipelineListener listener) - Specified by:
doOnConnectin interfaceio.micronaut.http.netty.channel.ChannelPipelineCustomizer
-
getObservedConfigurationPrefixes
- Specified by:
getObservedConfigurationPrefixesin interfaceio.micronaut.runtime.context.scope.refresh.RefreshEventListener
-
onApplicationEvent
public void onApplicationEvent(io.micronaut.runtime.context.scope.refresh.RefreshEvent event) - Specified by:
onApplicationEventin interfaceio.micronaut.context.event.ApplicationEventListener<io.micronaut.runtime.context.scope.refresh.RefreshEvent>
-
buildEmbeddedChannel
@Internal public io.netty.channel.embedded.EmbeddedChannel buildEmbeddedChannel(boolean ssl) Builds Embedded Channel.- Parameters:
ssl- whether to enable SSL- Returns:
- The embedded channel with our server handlers
-
buildEmbeddedChannel
@Internal public void buildEmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel prototype, boolean ssl) Builds Embedded Channel.- Parameters:
prototype- The embedded channel to add our handlers tossl- whether to enable SSL
-