Class DefaultNettyEmbeddedServerFactory

java.lang.Object
io.micronaut.http.server.netty.DefaultNettyEmbeddedServerFactory
All Implemented Interfaces:
NettyEmbeddedServerFactory, NettyEmbeddedServices

@Factory @Internal @Bean(typed={NettyEmbeddedServerFactory.class,DefaultNettyEmbeddedServerFactory.class}) public class DefaultNettyEmbeddedServerFactory extends Object implements NettyEmbeddedServerFactory, NettyEmbeddedServices
Default implementation of NettyEmbeddedServerFactory.
Since:
3.1.0
  • Constructor Details

    • DefaultNettyEmbeddedServerFactory

      protected DefaultNettyEmbeddedServerFactory(io.micronaut.context.ApplicationContext applicationContext, io.micronaut.http.server.RouteExecutor routeExecutor, io.micronaut.http.codec.MediaTypeCodecRegistry mediaTypeCodecRegistry, io.micronaut.http.body.MessageBodyHandlerRegistry messageBodyHandlerRegistry, io.micronaut.web.router.resource.StaticResourceResolver staticResourceResolver, @Named("netty") ThreadFactory nettyThreadFactory, HttpCompressionStrategy httpCompressionStrategy, io.micronaut.http.netty.channel.EventLoopGroupFactory eventLoopGroupFactory, io.micronaut.http.netty.channel.EventLoopGroupRegistry eventLoopGroupRegistry, @Nullable @Nullable WebSocketUpgradeHandlerFactory webSocketUpgradeHandlerFactory)
      Default constructor.
      Parameters:
      applicationContext - The app ctx
      routeExecutor - The route executor
      mediaTypeCodecRegistry - The media type codec
      messageBodyHandlerRegistry - The message body handler registery
      staticResourceResolver - The static resource resolver
      nettyThreadFactory - The netty thread factory
      httpCompressionStrategy - The http compression strategy
      eventLoopGroupFactory - The event loop group factory
      eventLoopGroupRegistry - The event loop group registry
      webSocketUpgradeHandlerFactory - An optional websocket integration
  • Method Details

    • build

      @NonNull public @NonNull NettyEmbeddedServer build(@NonNull @NonNull NettyHttpServerConfiguration configuration)
      Description copied from interface: NettyEmbeddedServerFactory
      Builds a NettyEmbeddedServer for the given configuration.

      Note that the returned server instance should be closed gracefully by calling the NettyEmbeddedServer.stop() method.

      Specified by:
      build in interface NettyEmbeddedServerFactory
      Parameters:
      configuration - The configuration, never null
      Returns:
      A NettyEmbeddedServer instance
    • build

      @NonNull public @NonNull NettyEmbeddedServer build(@NonNull @NonNull NettyHttpServerConfiguration configuration, @Nullable @Nullable io.micronaut.http.ssl.ServerSslConfiguration sslConfiguration)
      Description copied from interface: NettyEmbeddedServerFactory
      Builds a NettyEmbeddedServer for the given configuration.

      Note that the returned server instance should be closed gracefully by calling the NettyEmbeddedServer.stop() method.

      Specified by:
      build in interface NettyEmbeddedServerFactory
      Parameters:
      configuration - The configuration, never null
      sslConfiguration - The SSL configuration, can be null if SSL is not required
      Returns:
      A NettyEmbeddedServer instance
    • buildDefaultServer

      @Singleton @Primary @NonNull protected @NonNull NettyEmbeddedServer buildDefaultServer(@NonNull @NonNull NettyHttpServerConfiguration configuration)
      Builds the default server configuration.
      Parameters:
      configuration - The server configuration
      Returns:
      The NettyEmbeddedServer instance
    • getMessageBodyHandlerRegistry

      public io.micronaut.http.body.MessageBodyHandlerRegistry getMessageBodyHandlerRegistry()
      Specified by:
      getMessageBodyHandlerRegistry in interface NettyEmbeddedServices
      Returns:
      The message body handler registry.
    • getOutboundHandlers

      public List<io.netty.channel.ChannelOutboundHandler> getOutboundHandlers()
      Specified by:
      getOutboundHandlers in interface NettyEmbeddedServices
      Returns:
      The channel outbound handlers
    • getApplicationContext

      public io.micronaut.context.ApplicationContext getApplicationContext()
      Specified by:
      getApplicationContext in interface NettyEmbeddedServices
      Returns:
      The application context
    • getRequestArgumentSatisfier

      public io.micronaut.http.server.binding.RequestArgumentSatisfier getRequestArgumentSatisfier()
      Specified by:
      getRequestArgumentSatisfier in interface NettyEmbeddedServices
      Returns:
      The request argument satisfier
      See Also:
      • RequestArgumentSatisfier
    • getRouteExecutor

      public io.micronaut.http.server.RouteExecutor getRouteExecutor()
      Specified by:
      getRouteExecutor in interface NettyEmbeddedServices
      Returns:
      The route executor
      See Also:
      • RouteExecutor
    • getMediaTypeCodecRegistry

      public io.micronaut.http.codec.MediaTypeCodecRegistry getMediaTypeCodecRegistry()
      Specified by:
      getMediaTypeCodecRegistry in interface NettyEmbeddedServices
      Returns:
      The media type code registry
      See Also:
      • MediaTypeCodecRegistry
    • getStaticResourceResolver

      public io.micronaut.web.router.resource.StaticResourceResolver getStaticResourceResolver()
      Specified by:
      getStaticResourceResolver in interface NettyEmbeddedServices
      Returns:
      The static resource resolver
      See Also:
      • StaticResourceResolver
    • getExecutorSelector

      public io.micronaut.scheduling.executor.ExecutorSelector getExecutorSelector()
      Specified by:
      getExecutorSelector in interface NettyEmbeddedServices
      Returns:
      The executor resolver
    • getServerSslBuilder

      public ServerSslBuilder getServerSslBuilder()
      Specified by:
      getServerSslBuilder in interface NettyEmbeddedServices
      Returns:
      The server SSL builder or null if none is configured
      See Also:
    • getChannelOptionFactory

      public io.micronaut.http.netty.channel.converters.ChannelOptionFactory getChannelOptionFactory()
      Specified by:
      getChannelOptionFactory in interface NettyEmbeddedServices
      Returns:
      The channel option factory
    • getHttpCompressionStrategy

      public HttpCompressionStrategy getHttpCompressionStrategy()
      Specified by:
      getHttpCompressionStrategy in interface NettyEmbeddedServices
      Returns:
      The http compression strategy
    • getWebSocketUpgradeHandler

      public Optional<NettyServerWebSocketUpgradeHandler> getWebSocketUpgradeHandler(NettyEmbeddedServer server)
      Specified by:
      getWebSocketUpgradeHandler in interface NettyEmbeddedServices
      Parameters:
      server - The server
      Returns:
      The websocket upgrade handler if present
    • getEventLoopGroupRegistry

      public io.micronaut.http.netty.channel.EventLoopGroupRegistry getEventLoopGroupRegistry()
      Specified by:
      getEventLoopGroupRegistry in interface NettyEmbeddedServices
      Returns:
      The event loop group registry.
    • createEventLoopGroup

      public io.netty.channel.EventLoopGroup createEventLoopGroup(io.micronaut.http.netty.channel.EventLoopGroupConfiguration config)
      Description copied from interface: NettyEmbeddedServices
      Creates the event loop group configuration.
      Specified by:
      createEventLoopGroup in interface NettyEmbeddedServices
      Parameters:
      config - The config
      Returns:
      The event loop group config
    • getServerSocketChannelInstance

      public io.netty.channel.socket.ServerSocketChannel getServerSocketChannelInstance(io.micronaut.http.netty.channel.EventLoopGroupConfiguration workerConfig)
      Description copied from interface: NettyEmbeddedServices
      Gets the server socket channel instance.
      Specified by:
      getServerSocketChannelInstance in interface NettyEmbeddedServices
      Parameters:
      workerConfig - The worker config
      Returns:
      The ServerSocketChannel
    • getDomainServerChannelInstance

      public io.netty.channel.ServerChannel getDomainServerChannelInstance(io.micronaut.http.netty.channel.EventLoopGroupConfiguration workerConfig)
      Description copied from interface: NettyEmbeddedServices
      Gets the domain server socket channel instance.
      Specified by:
      getDomainServerChannelInstance in interface NettyEmbeddedServices
      Parameters:
      workerConfig - The worker config
      Returns:
      The DomainSocketChannel
    • getChannelInstance

      public io.netty.channel.Channel getChannelInstance(io.micronaut.http.netty.channel.NettyChannelType type, io.micronaut.http.netty.channel.EventLoopGroupConfiguration workerConfig)
      Description copied from interface: NettyEmbeddedServices
      Gets the domain server socket channel instance.
      Specified by:
      getChannelInstance in interface NettyEmbeddedServices
      Parameters:
      type - The channel type to return
      workerConfig - The worker config
      Returns:
      The channel
    • getEventPublisher

      public <E> io.micronaut.context.event.ApplicationEventPublisher<E> getEventPublisher(Class<E> eventClass)
      Description copied from interface: NettyEmbeddedServices
      Get an event publisher for the server for the given type.
      Specified by:
      getEventPublisher in interface NettyEmbeddedServices
      Type Parameters:
      E - The event generic type
      Parameters:
      eventClass - The event publisher
      Returns:
      The event publisher
    • createEventLoopGroup

      @NonNull public @NonNull io.netty.channel.EventLoopGroup createEventLoopGroup(int numThreads, @NonNull @NonNull ExecutorService executorService, Integer ioRatio)
      Description copied from interface: NettyEmbeddedServices
      Creates the event loop group configuration.
      Specified by:
      createEventLoopGroup in interface NettyEmbeddedServices
      Parameters:
      numThreads - The number of threads
      executorService - The executor service
      ioRatio - The I/O ratio
      Returns:
      The event loop group
    • setChannelOptionFactory

      @Inject protected void setChannelOptionFactory(@Nullable @Nullable io.micronaut.http.netty.channel.converters.ChannelOptionFactory channelOptionFactory)
      Configures the channel option factory.
      Parameters:
      channelOptionFactory - The channel option factory.
    • setServerSslBuilder

      @Inject protected void setServerSslBuilder(@Nullable @Nullable ServerSslBuilder serverSslBuilder)
      Configures the ServerSslBuilder the server ssl builder.
      Parameters:
      serverSslBuilder - The builder
    • setOutboundHandlers

      @Inject protected void setOutboundHandlers(List<io.netty.channel.ChannelOutboundHandler> outboundHandlers)
      Sets the outbound handlers.
      Parameters:
      outboundHandlers - The ChannelOutboundHandler instances