Package io.micronaut.http.server.netty
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 Summary
ConstructorsModifierConstructorDescriptionprotectedDefaultNettyEmbeddedServerFactory(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, ThreadFactory nettyThreadFactory, HttpCompressionStrategy httpCompressionStrategy, io.micronaut.http.netty.channel.EventLoopGroupFactory eventLoopGroupFactory, io.micronaut.http.netty.channel.EventLoopGroupRegistry eventLoopGroupRegistry, @Nullable WebSocketUpgradeHandlerFactory webSocketUpgradeHandlerFactory) Default constructor. -
Method Summary
Modifier and TypeMethodDescription@NonNull NettyEmbeddedServerbuild(@NonNull NettyHttpServerConfiguration configuration) Builds aNettyEmbeddedServerfor the given configuration.@NonNull NettyEmbeddedServerbuild(@NonNull NettyHttpServerConfiguration configuration, @Nullable io.micronaut.http.ssl.ServerSslConfiguration sslConfiguration) Builds aNettyEmbeddedServerfor the given configuration.protected @NonNull NettyEmbeddedServerbuildDefaultServer(@NonNull NettyHttpServerConfiguration configuration) Builds the default server configuration.@NonNull io.netty.channel.EventLoopGroupcreateEventLoopGroup(int numThreads, @NonNull ExecutorService executorService, Integer ioRatio) Creates the event loop group configuration.io.netty.channel.EventLoopGroupcreateEventLoopGroup(io.micronaut.http.netty.channel.EventLoopGroupConfiguration config) Creates the event loop group configuration.io.micronaut.context.ApplicationContextio.netty.channel.ChannelgetChannelInstance(io.micronaut.http.netty.channel.NettyChannelType type, io.micronaut.http.netty.channel.EventLoopGroupConfiguration workerConfig) Gets the domain server socket channel instance.io.netty.channel.ChannelgetChannelInstance(io.micronaut.http.netty.channel.NettyChannelType type, io.micronaut.http.netty.channel.EventLoopGroupConfiguration workerConfig, io.netty.channel.Channel parent, int fd) Gets the domain server socket channel instance.io.micronaut.http.netty.channel.converters.ChannelOptionFactoryio.micronaut.http.netty.channel.EventLoopGroupRegistry<E> io.micronaut.context.event.ApplicationEventPublisher<E>getEventPublisher(Class<E> eventClass) Get an event publisher for the server for the given type.io.micronaut.scheduling.executor.ExecutorSelectorio.micronaut.http.codec.MediaTypeCodecRegistryio.micronaut.http.body.MessageBodyHandlerRegistryList<io.netty.channel.ChannelOutboundHandler>io.micronaut.http.server.binding.RequestArgumentSatisfierio.micronaut.http.server.RouteExecutorio.micronaut.web.router.resource.StaticResourceResolverprotected voidsetChannelOptionFactory(@Nullable io.micronaut.http.netty.channel.converters.ChannelOptionFactory channelOptionFactory) Configures the channel option factory.protected voidsetOutboundHandlers(List<io.netty.channel.ChannelOutboundHandler> outboundHandlers) Sets the outbound handlers.protected voidsetServerSslBuilder(@Nullable ServerSslBuilder serverSslBuilder) Configures theServerSslBuilderthe server ssl builder.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.micronaut.http.server.netty.NettyEmbeddedServices
getDomainServerChannelInstance, getRouter, getServerSocketChannelInstance
-
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 ctxrouteExecutor- The route executormediaTypeCodecRegistry- The media type codecmessageBodyHandlerRegistry- The message body handler registerystaticResourceResolver- The static resource resolvernettyThreadFactory- The netty thread factoryhttpCompressionStrategy- The http compression strategyeventLoopGroupFactory- The event loop group factoryeventLoopGroupRegistry- The event loop group registrywebSocketUpgradeHandlerFactory- An optional websocket integration
-
-
Method Details
-
build
@NonNull public @NonNull NettyEmbeddedServer build(@NonNull @NonNull NettyHttpServerConfiguration configuration) Description copied from interface:NettyEmbeddedServerFactoryBuilds aNettyEmbeddedServerfor the given configuration.Note that the returned server instance should be closed gracefully by calling the
NettyEmbeddedServer.stop()method.- Specified by:
buildin interfaceNettyEmbeddedServerFactory- Parameters:
configuration- The configuration, nevernull- Returns:
- A
NettyEmbeddedServerinstance
-
build
@NonNull public @NonNull NettyEmbeddedServer build(@NonNull @NonNull NettyHttpServerConfiguration configuration, @Nullable @Nullable io.micronaut.http.ssl.ServerSslConfiguration sslConfiguration) Description copied from interface:NettyEmbeddedServerFactoryBuilds aNettyEmbeddedServerfor the given configuration.Note that the returned server instance should be closed gracefully by calling the
NettyEmbeddedServer.stop()method.- Specified by:
buildin interfaceNettyEmbeddedServerFactory- Parameters:
configuration- The configuration, nevernullsslConfiguration- The SSL configuration, can benullif SSL is not required- Returns:
- A
NettyEmbeddedServerinstance
-
buildDefaultServer
@Singleton @Primary @NonNull protected @NonNull NettyEmbeddedServer buildDefaultServer(@NonNull @NonNull NettyHttpServerConfiguration configuration) Builds the default server configuration.- Parameters:
configuration- The server configuration- Returns:
- The
NettyEmbeddedServerinstance
-
getMessageBodyHandlerRegistry
public io.micronaut.http.body.MessageBodyHandlerRegistry getMessageBodyHandlerRegistry()- Specified by:
getMessageBodyHandlerRegistryin interfaceNettyEmbeddedServices- Returns:
- The message body handler registry.
-
getOutboundHandlers
- Specified by:
getOutboundHandlersin interfaceNettyEmbeddedServices- Returns:
- The channel outbound handlers
-
getApplicationContext
public io.micronaut.context.ApplicationContext getApplicationContext()- Specified by:
getApplicationContextin interfaceNettyEmbeddedServices- Returns:
- The application context
-
getRequestArgumentSatisfier
public io.micronaut.http.server.binding.RequestArgumentSatisfier getRequestArgumentSatisfier()- Specified by:
getRequestArgumentSatisfierin interfaceNettyEmbeddedServices- Returns:
- The request argument satisfier
- See Also:
-
RequestArgumentSatisfier
-
getRouteExecutor
public io.micronaut.http.server.RouteExecutor getRouteExecutor()- Specified by:
getRouteExecutorin interfaceNettyEmbeddedServices- Returns:
- The route executor
- See Also:
-
RouteExecutor
-
getMediaTypeCodecRegistry
public io.micronaut.http.codec.MediaTypeCodecRegistry getMediaTypeCodecRegistry()- Specified by:
getMediaTypeCodecRegistryin interfaceNettyEmbeddedServices- Returns:
- The media type code registry
- See Also:
-
MediaTypeCodecRegistry
-
getStaticResourceResolver
public io.micronaut.web.router.resource.StaticResourceResolver getStaticResourceResolver()- Specified by:
getStaticResourceResolverin interfaceNettyEmbeddedServices- Returns:
- The static resource resolver
- See Also:
-
StaticResourceResolver
-
getExecutorSelector
public io.micronaut.scheduling.executor.ExecutorSelector getExecutorSelector()- Specified by:
getExecutorSelectorin interfaceNettyEmbeddedServices- Returns:
- The executor resolver
-
getServerSslBuilder
- Specified by:
getServerSslBuilderin interfaceNettyEmbeddedServices- Returns:
- The server SSL builder or
nullif none is configured - See Also:
-
getChannelOptionFactory
public io.micronaut.http.netty.channel.converters.ChannelOptionFactory getChannelOptionFactory()- Specified by:
getChannelOptionFactoryin interfaceNettyEmbeddedServices- Returns:
- The channel option factory
-
getHttpCompressionStrategy
- Specified by:
getHttpCompressionStrategyin interfaceNettyEmbeddedServices- Returns:
- The http compression strategy
-
getWebSocketUpgradeHandler
public Optional<NettyServerWebSocketUpgradeHandler> getWebSocketUpgradeHandler(NettyEmbeddedServer server) - Specified by:
getWebSocketUpgradeHandlerin interfaceNettyEmbeddedServices- Parameters:
server- The server- Returns:
- The websocket upgrade handler if present
-
getEventLoopGroupRegistry
public io.micronaut.http.netty.channel.EventLoopGroupRegistry getEventLoopGroupRegistry()- Specified by:
getEventLoopGroupRegistryin interfaceNettyEmbeddedServices- Returns:
- The event loop group registry.
-
createEventLoopGroup
public io.netty.channel.EventLoopGroup createEventLoopGroup(io.micronaut.http.netty.channel.EventLoopGroupConfiguration config) Description copied from interface:NettyEmbeddedServicesCreates the event loop group configuration.- Specified by:
createEventLoopGroupin interfaceNettyEmbeddedServices- Parameters:
config- The config- Returns:
- The event loop group config
-
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:NettyEmbeddedServicesGets the domain server socket channel instance.- Specified by:
getChannelInstancein interfaceNettyEmbeddedServices- Parameters:
type- The channel type to returnworkerConfig- The worker config- Returns:
- The channel
-
getChannelInstance
public io.netty.channel.Channel getChannelInstance(io.micronaut.http.netty.channel.NettyChannelType type, io.micronaut.http.netty.channel.EventLoopGroupConfiguration workerConfig, io.netty.channel.Channel parent, int fd) Description copied from interface:NettyEmbeddedServicesGets the domain server socket channel instance.- Specified by:
getChannelInstancein interfaceNettyEmbeddedServices- Parameters:
type- The channel type to returnworkerConfig- The worker configparent- The parent channel, ornullfor no parent channelfd- The pre-defined file descriptor- Returns:
- The channel
-
getEventPublisher
public <E> io.micronaut.context.event.ApplicationEventPublisher<E> getEventPublisher(Class<E> eventClass) Description copied from interface:NettyEmbeddedServicesGet an event publisher for the server for the given type.- Specified by:
getEventPublisherin interfaceNettyEmbeddedServices- 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:NettyEmbeddedServicesCreates the event loop group configuration.- Specified by:
createEventLoopGroupin interfaceNettyEmbeddedServices- Parameters:
numThreads- The number of threadsexecutorService- The executor serviceioRatio- 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
Configures theServerSslBuilderthe server ssl builder.- Parameters:
serverSslBuilder- The builder
-
setOutboundHandlers
@Inject protected void setOutboundHandlers(List<io.netty.channel.ChannelOutboundHandler> outboundHandlers) Sets the outbound handlers.- Parameters:
outboundHandlers- TheChannelOutboundHandlerinstances
-