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
ModifierConstructorDescriptionprotected
DefaultNettyEmbeddedServerFactory
(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 aNettyEmbeddedServer
for the given configuration.build
(@NonNull NettyHttpServerConfiguration configuration, @Nullable ServerSslConfiguration sslConfiguration) Builds aNettyEmbeddedServer
for the given configuration.protected @NonNull NettyEmbeddedServer
buildDefaultServer
(@NonNull NettyHttpServerConfiguration configuration) Builds the default server configuration.@NonNull io.netty.channel.EventLoopGroup
createEventLoopGroup
(int numThreads, @NonNull ExecutorService executorService, Integer ioRatio) Creates the event loop group configuration.io.netty.channel.EventLoopGroup
Creates the event loop group configuration.io.netty.channel.Channel
getChannelInstance
(NettyChannelType type, EventLoopGroupConfiguration workerConfig) Gets the domain server socket channel instance.io.netty.channel.Channel
getChannelInstance
(NettyChannelType type, EventLoopGroupConfiguration workerConfig, io.netty.channel.Channel parent, int fd) Gets the domain server socket channel instance.io.netty.channel.ServerChannel
getDomainServerChannelInstance
(EventLoopGroupConfiguration workerConfig) 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>
io.netty.channel.socket.ServerSocketChannel
getServerSocketChannelInstance
(EventLoopGroupConfiguration workerConfig) Gets the server socket channel instance.protected void
setChannelOptionFactory
(@Nullable ChannelOptionFactory channelOptionFactory) Configures the channel option factory.protected void
setOutboundHandlers
(List<io.netty.channel.ChannelOutboundHandler> outboundHandlers) Sets the outbound handlers.protected void
setServerSslBuilder
(@Nullable ServerSslBuilder serverSslBuilder) Configures theServerSslBuilder
the server ssl builder.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.server.netty.NettyEmbeddedServices
getRouter
-
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:NettyEmbeddedServerFactory
Builds aNettyEmbeddedServer
for the given configuration.Note that the returned server instance should be closed gracefully by calling the
NettyEmbeddedServer.stop()
method.- Specified by:
build
in interfaceNettyEmbeddedServerFactory
- Parameters:
configuration
- The configuration, nevernull
- Returns:
- A
NettyEmbeddedServer
instance
-
build
@NonNull public @NonNull NettyEmbeddedServer build(@NonNull @NonNull NettyHttpServerConfiguration configuration, @Nullable @Nullable ServerSslConfiguration sslConfiguration) Description copied from interface:NettyEmbeddedServerFactory
Builds aNettyEmbeddedServer
for the given configuration.Note that the returned server instance should be closed gracefully by calling the
NettyEmbeddedServer.stop()
method.- Specified by:
build
in interfaceNettyEmbeddedServerFactory
- Parameters:
configuration
- The configuration, nevernull
sslConfiguration
- The SSL configuration, can benull
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
- Specified by:
getMessageBodyHandlerRegistry
in interfaceNettyEmbeddedServices
- Returns:
- The message body handler registry.
-
getOutboundHandlers
- Specified by:
getOutboundHandlers
in interfaceNettyEmbeddedServices
- Returns:
- The channel outbound handlers
-
getApplicationContext
- Specified by:
getApplicationContext
in interfaceNettyEmbeddedServices
- Returns:
- The application context
-
getRequestArgumentSatisfier
- Specified by:
getRequestArgumentSatisfier
in interfaceNettyEmbeddedServices
- Returns:
- The request argument satisfier
- See Also:
-
getRouteExecutor
- Specified by:
getRouteExecutor
in interfaceNettyEmbeddedServices
- Returns:
- The route executor
- See Also:
-
getMediaTypeCodecRegistry
- Specified by:
getMediaTypeCodecRegistry
in interfaceNettyEmbeddedServices
- Returns:
- The media type code registry
- See Also:
-
getStaticResourceResolver
- Specified by:
getStaticResourceResolver
in interfaceNettyEmbeddedServices
- Returns:
- The static resource resolver
- See Also:
-
getExecutorSelector
- Specified by:
getExecutorSelector
in interfaceNettyEmbeddedServices
- Returns:
- The executor resolver
-
getServerSslBuilder
- Specified by:
getServerSslBuilder
in interfaceNettyEmbeddedServices
- Returns:
- The server SSL builder or
null
if none is configured - See Also:
-
getChannelOptionFactory
- Specified by:
getChannelOptionFactory
in interfaceNettyEmbeddedServices
- Returns:
- The channel option factory
-
getHttpCompressionStrategy
- Specified by:
getHttpCompressionStrategy
in interfaceNettyEmbeddedServices
- Returns:
- The http compression strategy
-
getWebSocketUpgradeHandler
public Optional<NettyServerWebSocketUpgradeHandler> getWebSocketUpgradeHandler(NettyEmbeddedServer server) - Specified by:
getWebSocketUpgradeHandler
in interfaceNettyEmbeddedServices
- Parameters:
server
- The server- Returns:
- The websocket upgrade handler if present
-
getEventLoopGroupRegistry
- Specified by:
getEventLoopGroupRegistry
in interfaceNettyEmbeddedServices
- Returns:
- The event loop group registry.
-
createEventLoopGroup
Description copied from interface:NettyEmbeddedServices
Creates the event loop group configuration.- Specified by:
createEventLoopGroup
in interfaceNettyEmbeddedServices
- Parameters:
config
- The config- Returns:
- The event loop group config
-
getServerSocketChannelInstance
public io.netty.channel.socket.ServerSocketChannel getServerSocketChannelInstance(EventLoopGroupConfiguration workerConfig) Description copied from interface:NettyEmbeddedServices
Gets the server socket channel instance.- Specified by:
getServerSocketChannelInstance
in interfaceNettyEmbeddedServices
- Parameters:
workerConfig
- The worker config- Returns:
- The
ServerSocketChannel
-
getDomainServerChannelInstance
public io.netty.channel.ServerChannel getDomainServerChannelInstance(EventLoopGroupConfiguration workerConfig) Description copied from interface:NettyEmbeddedServices
Gets the domain server socket channel instance.- Specified by:
getDomainServerChannelInstance
in interfaceNettyEmbeddedServices
- Parameters:
workerConfig
- The worker config- Returns:
- The
DomainSocketChannel
-
getChannelInstance
public io.netty.channel.Channel getChannelInstance(NettyChannelType type, EventLoopGroupConfiguration workerConfig) Description copied from interface:NettyEmbeddedServices
Gets the domain server socket channel instance.- Specified by:
getChannelInstance
in 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:NettyEmbeddedServices
Gets the domain server socket channel instance.- Specified by:
getChannelInstance
in interfaceNettyEmbeddedServices
- Parameters:
type
- The channel type to returnworkerConfig
- The worker configparent
- The parent channel, ornull
for no parent channelfd
- The pre-defined file descriptor- Returns:
- The channel
-
getEventPublisher
Description copied from interface:NettyEmbeddedServices
Get an event publisher for the server for the given type.- Specified by:
getEventPublisher
in 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:NettyEmbeddedServices
Creates the event loop group configuration.- Specified by:
createEventLoopGroup
in 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 theServerSslBuilder
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
- TheChannelOutboundHandler
instances
-