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

@Internal public class NettyHttpServer extends Object implements NettyEmbeddedServer
Implements the bootstrap and configuration logic for the Netty implementation of EmbeddedServer.
Since:
1.0
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
     

    Fields 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_PING_SENDER, 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, 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_UPGRADE

    Fields inherited from interface io.micronaut.core.order.Ordered

    HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE

    Fields inherited from interface io.micronaut.runtime.context.scope.refresh.RefreshEventListener

    DEFAULT_POSITION
  • Constructor Summary

    Constructors
    Constructor
    Description
    NettyHttpServer(NettyHttpServerConfiguration serverConfiguration, NettyEmbeddedServices nettyEmbeddedServices, boolean isDefault)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addChannel(io.netty.channel.Channel channel)
     
    io.netty.channel.embedded.EmbeddedChannel
    buildEmbeddedChannel(boolean ssl)
    Builds Embedded Channel.
    void
    buildEmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel prototype, boolean ssl)
    Builds Embedded Channel.
    protected io.netty.channel.EventLoopGroup
     
    protected io.netty.bootstrap.ServerBootstrap
     
    protected io.netty.channel.EventLoopGroup
    createWorkerEventLoopGroup(@Nullable io.micronaut.http.netty.channel.EventLoopGroupConfiguration workerConfig)
     
    void
    doOnConnect(@NonNull io.micronaut.http.netty.channel.ChannelPipelineListener listener)
     
    io.micronaut.runtime.ApplicationConfiguration
     
    io.micronaut.context.ApplicationContext
     
    final Set<Integer>
    Gets the set of all ports this Netty server is bound to.
    io.netty.channel.group.ChannelGroup
     
     
     
     
    int
     
     
     
     
     
    io.micronaut.http.netty.websocket.WebSocketSessionRepository
     
    boolean
     
    boolean
     
    boolean
     
    void
    onApplicationEvent(io.micronaut.runtime.context.scope.refresh.RefreshEvent event)
     
    void
    register(@NonNull NettyServerCustomizer customizer)
    Register a new customizer with this server.
    void
    removeChannel(io.netty.channel.Channel channel)
     
     
     
    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, wait

    Methods inherited from interface io.micronaut.http.netty.channel.ChannelPipelineCustomizer

    isServerChannel

    Methods inherited from interface io.micronaut.runtime.EmbeddedApplication

    getEnvironment, isForceExit

    Methods inherited from interface io.micronaut.runtime.server.EmbeddedServer

    isServer

    Methods inherited from interface io.micronaut.context.LifeCycle

    close, refresh

    Methods inherited from interface io.micronaut.runtime.context.scope.refresh.RefreshEventListener

    getOrder, supports
  • Field Details

  • Constructor Details

    • NettyHttpServer

      public NettyHttpServer(NettyHttpServerConfiguration serverConfiguration, NettyEmbeddedServices nettyEmbeddedServices, boolean isDefault)
      Parameters:
      serverConfiguration - The Netty HTTP server configuration
      nettyEmbeddedServices - The embedded server context
      isDefault - Is this the default server
  • Method Details

    • isKeepAlive

      public boolean isKeepAlive()
      Specified by:
      isKeepAlive in interface io.micronaut.runtime.server.EmbeddedServer
    • getServerConfiguration

      public NettyHttpServerConfiguration getServerConfiguration()
      Returns:
      The configuration for the server
    • isRunning

      public boolean isRunning()
      Specified by:
      isRunning in interface io.micronaut.context.LifeCycle
    • start

      @NonNull public @NonNull NettyEmbeddedServer start()
      Specified by:
      start in interface io.micronaut.context.ApplicationContextLifeCycle<io.micronaut.runtime.server.EmbeddedServer>
      Specified by:
      start in interface io.micronaut.context.LifeCycle
      Specified by:
      start in interface NettyEmbeddedServer
    • stop

      @NonNull public @NonNull NettyEmbeddedServer stop()
      Specified by:
      stop in interface io.micronaut.context.ApplicationContextLifeCycle<io.micronaut.runtime.server.EmbeddedServer>
      Specified by:
      stop in interface io.micronaut.context.LifeCycle
      Specified by:
      stop in interface NettyEmbeddedServer
    • stopServerOnly

      @NonNull public @NonNull NettyEmbeddedServer stopServerOnly()
      Description copied from interface: NettyEmbeddedServer
      Stops the Netty instance, but keeps the ApplicationContext running. This for CRaC checkpointing purposes. This method will only return after waiting for netty to stop.
      Specified by:
      stopServerOnly in interface NettyEmbeddedServer
      Returns:
      The stopped NettyEmbeddedServer
    • register

      public void register(@NonNull @NonNull NettyServerCustomizer customizer)
      Description copied from interface: NettyServerCustomizer.Registry
      Register 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:
      register in interface NettyEmbeddedServer
      Specified by:
      register in interface NettyServerCustomizer.Registry
      Parameters:
      customizer - The customizer to register.
    • getPort

      public int getPort()
      Specified by:
      getPort in interface io.micronaut.runtime.server.EmbeddedServer
    • getHost

      public String getHost()
      Specified by:
      getHost in interface io.micronaut.runtime.server.EmbeddedServer
    • getScheme

      public String getScheme()
      Specified by:
      getScheme in interface io.micronaut.runtime.server.EmbeddedServer
    • getURL

      public URL getURL()
      Specified by:
      getURL in interface io.micronaut.runtime.server.EmbeddedServer
    • getURI

      public URI getURI()
      Specified by:
      getURI in interface io.micronaut.runtime.server.EmbeddedServer
    • getContextURI

      public URI getContextURI()
      Specified by:
      getContextURI in interface io.micronaut.runtime.server.EmbeddedServer
    • getApplicationContext

      public io.micronaut.context.ApplicationContext getApplicationContext()
      Specified by:
      getApplicationContext in interface io.micronaut.context.ApplicationContextProvider
      Specified by:
      getApplicationContext in interface io.micronaut.runtime.EmbeddedApplication<io.micronaut.runtime.server.EmbeddedServer>
    • getApplicationConfiguration

      public io.micronaut.runtime.ApplicationConfiguration getApplicationConfiguration()
      Specified by:
      getApplicationConfiguration in interface io.micronaut.runtime.EmbeddedApplication<io.micronaut.runtime.server.EmbeddedServer>
    • getBoundPorts

      public final Set<Integer> getBoundPorts()
      Description copied from interface: NettyEmbeddedServer
      Gets the set of all ports this Netty server is bound to.
      Specified by:
      getBoundPorts in interface NettyEmbeddedServer
      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 @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:
      addChannel in interface io.micronaut.http.netty.websocket.WebSocketSessionRepository
    • removeChannel

      public void removeChannel(io.netty.channel.Channel channel)
      Specified by:
      removeChannel in interface io.micronaut.http.netty.websocket.WebSocketSessionRepository
    • getChannelGroup

      public io.netty.channel.group.ChannelGroup getChannelGroup()
      Specified by:
      getChannelGroup in interface io.micronaut.http.netty.websocket.WebSocketSessionRepository
    • getWebSocketSessionRepository

      public io.micronaut.http.netty.websocket.WebSocketSessionRepository getWebSocketSessionRepository()
      Returns:
      NettyHttpServer which implements WebSocketSessionRepository
    • isClientChannel

      public boolean isClientChannel()
      Specified by:
      isClientChannel in interface io.micronaut.http.netty.channel.ChannelPipelineCustomizer
    • doOnConnect

      public void doOnConnect(@NonNull @NonNull io.micronaut.http.netty.channel.ChannelPipelineListener listener)
      Specified by:
      doOnConnect in interface io.micronaut.http.netty.channel.ChannelPipelineCustomizer
    • getObservedConfigurationPrefixes

      public Set<String> getObservedConfigurationPrefixes()
      Specified by:
      getObservedConfigurationPrefixes in interface io.micronaut.runtime.context.scope.refresh.RefreshEventListener
    • onApplicationEvent

      public void onApplicationEvent(io.micronaut.runtime.context.scope.refresh.RefreshEvent event)
      Specified by:
      onApplicationEvent in interface io.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 to
      ssl - whether to enable SSL