Package io.hekate.network.netty
Class NettyServerFactory
- java.lang.Object
-
- io.hekate.network.NetworkServerFactoryBase
-
- io.hekate.network.netty.NettyServerFactory
-
public class NettyServerFactory extends NetworkServerFactoryBase
Configurable factory for Netty-basedNetworkServer
s.
-
-
Field Summary
-
Fields inherited from class io.hekate.network.NetworkServerFactoryBase
DEFAULT_AUTO_ACCEPT, DEFAULT_HB_INTERVAL, DEFAULT_HB_LOSS_THRESHOLD, DEFAULT_TCP_NO_DELAY
-
-
Constructor Summary
Constructors Constructor Description NettyServerFactory()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description NetworkServer
createServer()
Creates a new network server based on the configuration options of this factory.io.netty.channel.EventLoopGroup
getAcceptorEventLoop()
Returns the event loop group that is responsible for accepting new connections (seesetAcceptorEventLoop(EventLoopGroup)
).List<NettyServerHandlerConfig<?>>
getHandlers()
Returns the list of server connection handlers (seesetHandlers(List)
).NettyMetricsFactory
getMetrics()
Returns the metrics factory (seesetMetrics(NettyMetricsFactory)
).io.netty.handler.ssl.SslContext
getSsl()
Returns the SSL context (seesetSsl(SslContext)
).io.netty.channel.EventLoopGroup
getWorkerEventLoop()
Returns the event loop group that is responsible for handling messaging operations (seesetWorkerEventLoop(EventLoopGroup)
).boolean
isDisableHeartbeats()
Returnstrue
if heartbeats are disabled (seesetDisableHeartbeats(boolean)
).void
setAcceptorEventLoop(io.netty.channel.EventLoopGroup acceptorEventLoop)
Sets the event loop group that will be responsible for accepting new connections.void
setDisableHeartbeats(boolean disableHeartbeats)
Enabled/disabled heartbeats support.void
setHandlers(List<NettyServerHandlerConfig<?>> handlers)
Sets the list of server connection handlers.void
setMetrics(NettyMetricsFactory metrics)
Sets the metrics factory.void
setSsl(io.netty.handler.ssl.SslContext ssl)
Sets the SSL context that should be used to secure all network communications.void
setWorkerEventLoop(io.netty.channel.EventLoopGroup workerEventLoop)
Sets the event loop group that will be responsible for handling messaging operations.NettyServerFactory
withAcceptorEventLoop(io.netty.channel.EventLoopGroup acceptorEventLoop)
Fluent-style version ofsetAcceptorEventLoop(EventLoopGroup)
.NettyServerFactory
withDisableHeartbeats(boolean disableHeartbeats)
Fluent-style version ofsetDisableHeartbeats(boolean)
.NettyServerFactory
withHandler(NettyServerHandlerConfig<?> handler)
Fluent-style version ofsetHandlers(List)
.NettyServerFactory
withMetrics(NettyMetricsFactory metrics)
Fluent-style version ofsetMetrics(NettyMetricsFactory)
.NettyServerFactory
withSsl(io.netty.handler.ssl.SslContext ssl)
Fluent-style version ofsetSsl(SslContext)
.NettyServerFactory
withWorkerEventLoop(io.netty.channel.EventLoopGroup workerEventLoop)
Fluent-style version ofsetWorkerEventLoop(EventLoopGroup)
.-
Methods inherited from class io.hekate.network.NetworkServerFactoryBase
getHeartbeatInterval, getHeartbeatLossThreshold, getSoBacklog, getSoReceiveBufferSize, getSoReuseAddress, getSoSendBufferSize, isAutoAccept, isTcpNoDelay, setAutoAccept, setHeartbeatInterval, setHeartbeatLossThreshold, setSoBacklog, setSoReceiveBufferSize, setSoReuseAddress, setSoSendBufferSize, setTcpNoDelay, toString, withAutoAccept, withHeartbeatInterval, withHeartbeatLossThreshold, withSoBacklog, withSoReceiveBufferSize, withSoReuseAddress, withSoSendBufferSize, withTcpNoDelay
-
-
-
-
Method Detail
-
isDisableHeartbeats
public boolean isDisableHeartbeats()
Returnstrue
if heartbeats are disabled (seesetDisableHeartbeats(boolean)
).- Returns:
true
if heartbeats are disabled.
-
setDisableHeartbeats
public void setDisableHeartbeats(boolean disableHeartbeats)
Enabled/disabled heartbeats support.If heartbeats are disabled then
NetworkServer
will not use heartbeats to keep connections alive. In such case it is up to the application to manage heartbeats and perform detection of broken connections.Default value of this parameter is
false
(i.e. heartbeats are enabled).- Parameters:
disableHeartbeats
-true
if heartbeats must be disabled.
-
withDisableHeartbeats
public NettyServerFactory withDisableHeartbeats(boolean disableHeartbeats)
Fluent-style version ofsetDisableHeartbeats(boolean)
.- Parameters:
disableHeartbeats
-true
if heartbeats must be disabled.- Returns:
- This instance.
-
getHandlers
public List<NettyServerHandlerConfig<?>> getHandlers()
Returns the list of server connection handlers (seesetHandlers(List)
).- Returns:
- Server handlers.
-
setHandlers
public void setHandlers(List<NettyServerHandlerConfig<?>> handlers)
Sets the list of server connection handlers.- Parameters:
handlers
- Server handlers.
-
withHandler
public NettyServerFactory withHandler(NettyServerHandlerConfig<?> handler)
Fluent-style version ofsetHandlers(List)
.- Parameters:
handler
- Server handler.- Returns:
- This instance.
-
getAcceptorEventLoop
public io.netty.channel.EventLoopGroup getAcceptorEventLoop()
Returns the event loop group that is responsible for accepting new connections (seesetAcceptorEventLoop(EventLoopGroup)
).- Returns:
- Event loop group for accepting new connections.
-
setAcceptorEventLoop
public void setAcceptorEventLoop(io.netty.channel.EventLoopGroup acceptorEventLoop)
Sets the event loop group that will be responsible for accepting new connections.- Parameters:
acceptorEventLoop
- Event loop group for accepting new connections.
-
withAcceptorEventLoop
public NettyServerFactory withAcceptorEventLoop(io.netty.channel.EventLoopGroup acceptorEventLoop)
Fluent-style version ofsetAcceptorEventLoop(EventLoopGroup)
.- Parameters:
acceptorEventLoop
- Event loop group for accepting new connections.- Returns:
- This instance.
-
getWorkerEventLoop
public io.netty.channel.EventLoopGroup getWorkerEventLoop()
Returns the event loop group that is responsible for handling messaging operations (seesetWorkerEventLoop(EventLoopGroup)
).- Returns:
- Event loop group for messaging operations handling.
-
setWorkerEventLoop
public void setWorkerEventLoop(io.netty.channel.EventLoopGroup workerEventLoop)
Sets the event loop group that will be responsible for handling messaging operations.- Parameters:
workerEventLoop
- Event loop group for messaging operations handling.
-
withWorkerEventLoop
public NettyServerFactory withWorkerEventLoop(io.netty.channel.EventLoopGroup workerEventLoop)
Fluent-style version ofsetWorkerEventLoop(EventLoopGroup)
.- Parameters:
workerEventLoop
- Event loop group for messaging operations handling.- Returns:
- This instance.
-
getSsl
public io.netty.handler.ssl.SslContext getSsl()
Returns the SSL context (seesetSsl(SslContext)
).- Returns:
- SSL context.
-
setSsl
public void setSsl(io.netty.handler.ssl.SslContext ssl)
Sets the SSL context that should be used to secure all network communications.This parameter is optional and if not specified then no encryption will be applied.
Note: If SSL is configured for the server then it should be configured on the client side too (see
NettyClientFactory.setSsl(SslContext)
).- Parameters:
ssl
- SSL context.
-
withSsl
public NettyServerFactory withSsl(io.netty.handler.ssl.SslContext ssl)
Fluent-style version ofsetSsl(SslContext)
.- Parameters:
ssl
- SSL context.- Returns:
- SSL context.
-
getMetrics
public NettyMetricsFactory getMetrics()
Returns the metrics factory (seesetMetrics(NettyMetricsFactory)
).- Returns:
- Metrics factory.
-
setMetrics
public void setMetrics(NettyMetricsFactory metrics)
Sets the metrics factory.This parameter is optional and if not specified then no metrics will be collected by the
NetworkServer
.- Parameters:
metrics
- Metrics factory.
-
withMetrics
public NettyServerFactory withMetrics(NettyMetricsFactory metrics)
Fluent-style version ofsetMetrics(NettyMetricsFactory)
.- Parameters:
metrics
- Metrics factory.- Returns:
- This instance.
-
createServer
public NetworkServer createServer()
Description copied from class:NetworkServerFactoryBase
Creates a new network server based on the configuration options of this factory.- Specified by:
createServer
in classNetworkServerFactoryBase
- Returns:
- New network server.
-
-