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
- Author:
- graemerocher
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedDefaultNettyEmbeddedServerFactory(ApplicationContext applicationContext, RouteExecutor routeExecutor, MediaTypeCodecRegistry mediaTypeCodecRegistry, MessageBodyHandlerRegistry messageBodyHandlerRegistry, StaticResourceResolver staticResourceResolver, ThreadFactory nettyThreadFactory, HttpCompressionStrategy httpCompressionStrategy, EventLoopGroupFactory eventLoopGroupFactory, EventLoopGroupRegistry eventLoopGroupRegistry, @Nullable WebSocketUpgradeHandlerFactory webSocketUpgradeHandlerFactory) Default constructor. -
Method Summary
Modifier and TypeMethodDescriptionbuild(@NonNull NettyHttpServerConfiguration configuration) Builds aNettyEmbeddedServerfor the given configuration.build(@NonNull NettyHttpServerConfiguration configuration, @Nullable 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(EventLoopGroupConfiguration configuration) Creates the event loop group configuration.io.netty.channel.ChannelgetChannelInstance(NettyChannelType type, EventLoopGroupConfiguration workerConfig) Gets the domain server socket channel instance.io.netty.channel.ChannelgetChannelInstance(NettyChannelType type, EventLoopGroupConfiguration workerConfig, io.netty.channel.Channel parent, int fd) Gets the domain server socket channel instance.<E> ApplicationEventPublisher<E>getEventPublisher(Class<E> eventClass) Get an event publisher for the server for the given type.List<io.netty.channel.ChannelOutboundHandler>protected voidsetChannelOptionFactory(@Nullable 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(ApplicationContext applicationContext, RouteExecutor routeExecutor, MediaTypeCodecRegistry mediaTypeCodecRegistry, MessageBodyHandlerRegistry messageBodyHandlerRegistry, StaticResourceResolver staticResourceResolver, @Named("netty") ThreadFactory nettyThreadFactory, HttpCompressionStrategy httpCompressionStrategy, EventLoopGroupFactory eventLoopGroupFactory, 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 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
- Specified by:
getMessageBodyHandlerRegistryin interfaceNettyEmbeddedServices- Returns:
- The message body handler registry.
-
getOutboundHandlers
- Specified by:
getOutboundHandlersin interfaceNettyEmbeddedServices- Returns:
- The channel outbound handlers
-
getApplicationContext
- Specified by:
getApplicationContextin interfaceNettyEmbeddedServices- Returns:
- The application context
-
getRequestArgumentSatisfier
- Specified by:
getRequestArgumentSatisfierin interfaceNettyEmbeddedServices- Returns:
- The request argument satisfier
- See Also:
-
getRouteExecutor
- Specified by:
getRouteExecutorin interfaceNettyEmbeddedServices- Returns:
- The route executor
- See Also:
-
getMediaTypeCodecRegistry
- Specified by:
getMediaTypeCodecRegistryin interfaceNettyEmbeddedServices- Returns:
- The media type code registry
- See Also:
-
getStaticResourceResolver
- Specified by:
getStaticResourceResolverin interfaceNettyEmbeddedServices- Returns:
- The static resource resolver
- See Also:
-
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
- 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
- Specified by:
getEventLoopGroupRegistryin interfaceNettyEmbeddedServices- Returns:
- The event loop group registry.
-
createEventLoopGroup
public io.netty.channel.EventLoopGroup createEventLoopGroup(EventLoopGroupConfiguration configuration) Description copied from interface:NettyEmbeddedServicesCreates the event loop group configuration.- Specified by:
createEventLoopGroupin interfaceNettyEmbeddedServices- Parameters:
configuration- The config- Returns:
- The event loop group config
-
getChannelInstance
public io.netty.channel.Channel getChannelInstance(NettyChannelType type, 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(NettyChannelType type, 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
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 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
-