public class TcpServerImpl<R,W> extends TcpServer<R,W>
Modifier and Type | Class and Description |
---|---|
protected static class |
TcpServerImpl.ServerStatus |
Modifier and Type | Field and Description |
---|---|
protected java.util.concurrent.atomic.AtomicReference<TcpServerImpl.ServerStatus> |
serverStateRef |
Constructor and Description |
---|
TcpServerImpl(java.net.SocketAddress socketAddress) |
TcpServerImpl(java.net.SocketAddress socketAddress,
io.netty.channel.EventLoopGroup parent,
io.netty.channel.EventLoopGroup child,
java.lang.Class<? extends io.netty.channel.ServerChannel> channelClass) |
Modifier and Type | Method and Description |
---|---|
<RR,WW> TcpServer<RR,WW> |
addChannelHandlerAfter(io.netty.util.concurrent.EventExecutorGroup group,
java.lang.String baseName,
java.lang.String name,
rx.functions.Func0<io.netty.channel.ChannelHandler> handlerFactory)
Adds a
ChannelHandler to ChannelPipeline for all connections created by this server. |
<RR,WW> TcpServer<RR,WW> |
addChannelHandlerAfter(java.lang.String baseName,
java.lang.String name,
rx.functions.Func0<io.netty.channel.ChannelHandler> handlerFactory)
Adds a
ChannelHandler to ChannelPipeline for all connections created by this server. |
<RR,WW> TcpServer<RR,WW> |
addChannelHandlerBefore(io.netty.util.concurrent.EventExecutorGroup group,
java.lang.String baseName,
java.lang.String name,
rx.functions.Func0<io.netty.channel.ChannelHandler> handlerFactory)
Adds a
ChannelHandler to ChannelPipeline for all connections created by this server. |
<RR,WW> TcpServer<RR,WW> |
addChannelHandlerBefore(java.lang.String baseName,
java.lang.String name,
rx.functions.Func0<io.netty.channel.ChannelHandler> handlerFactory)
Adds a
ChannelHandler to ChannelPipeline for all connections created by this server. |
<RR,WW> TcpServer<RR,WW> |
addChannelHandlerFirst(io.netty.util.concurrent.EventExecutorGroup group,
java.lang.String name,
rx.functions.Func0<io.netty.channel.ChannelHandler> handlerFactory)
Adds a
ChannelHandler to ChannelPipeline for all connections created by this server. |
<RR,WW> TcpServer<RR,WW> |
addChannelHandlerFirst(java.lang.String name,
rx.functions.Func0<io.netty.channel.ChannelHandler> handlerFactory)
Adds a
ChannelHandler to ChannelPipeline for all connections created by this server. |
<RR,WW> TcpServer<RR,WW> |
addChannelHandlerLast(io.netty.util.concurrent.EventExecutorGroup group,
java.lang.String name,
rx.functions.Func0<io.netty.channel.ChannelHandler> handlerFactory)
Adds a
ChannelHandler to ChannelPipeline for all connections created by this server. |
<RR,WW> TcpServer<RR,WW> |
addChannelHandlerLast(java.lang.String name,
rx.functions.Func0<io.netty.channel.ChannelHandler> handlerFactory)
Adds a
ChannelHandler to ChannelPipeline for all connections created by this server. |
void |
awaitShutdown()
Waits for the shutdown of this server.
|
void |
awaitShutdown(long duration,
java.util.concurrent.TimeUnit timeUnit)
Waits for the shutdown of this server, waiting a maximum of the passed duration.
|
<T> TcpServer<R,W> |
channelOption(io.netty.channel.ChannelOption<T> option,
T value)
Creates a new server instance, inheriting all configurations from this server and adding a
ChannelOption for the server socket created by the newly created server instance. |
<T> TcpServer<R,W> |
clientChannelOption(io.netty.channel.ChannelOption<T> option,
T value)
Creates a new server instance, inheriting all configurations from this server and adding a
ChannelOption for the client socket created by the newly created server instance. |
TcpServer<R,W> |
enableWireLogging(io.netty.handler.logging.LogLevel wireLoggingLevel)
Creates a new server instances, inheriting all configurations from this server and enabling wire logging at the
passed level for the newly created server instance.
|
TcpServerEventPublisher |
getEventPublisher()
Returns the event publisher for this server.
|
java.net.SocketAddress |
getServerAddress()
Returns the address at which this server is running.
|
int |
getServerPort()
Returns the port at which this server is running.
|
<RR,WW> TcpServer<RR,WW> |
pipelineConfigurator(rx.functions.Action1<io.netty.channel.ChannelPipeline> pipelineConfigurator)
Creates a new server instances, inheriting all configurations from this server and using the passed
action to configure all the connections created by the newly created server instance.
|
TcpServer<R,W> |
secure(rx.functions.Func1<io.netty.buffer.ByteBufAllocator,javax.net.ssl.SSLEngine> sslEngineFactory)
Creates a new server instances, inheriting all configurations from this server and using the passed
sslEngineFactory for all secured connections accepted by the newly created server instance. |
TcpServer<R,W> |
secure(io.reactivex.netty.ssl.SslCodec sslCodec)
Creates a new server instances, inheriting all configurations from this server and using the passed
sslCodec for all secured connections accepted by the newly created server instance. |
TcpServer<R,W> |
secure(javax.net.ssl.SSLEngine sslEngine)
Creates a new server instances, inheriting all configurations from this server and using the passed
sslEngine for all secured connections accepted by the newly created server instance. |
void |
shutdown()
Shutdown this server and waits till the server socket is closed.
|
TcpServer<R,W> |
start(ConnectionHandler<R,W> connectionHandler)
Starts this server.
|
rx.Subscription |
subscribe(TcpServerEventListener listener) |
TcpServer<R,W> |
unsafeSecure()
Creates a new server instances, inheriting all configurations from this server and using a self-signed
certificate for all secured connections accepted by the newly created server instance.
|
protected final java.util.concurrent.atomic.AtomicReference<TcpServerImpl.ServerStatus> serverStateRef
public TcpServerImpl(java.net.SocketAddress socketAddress)
public TcpServerImpl(java.net.SocketAddress socketAddress, io.netty.channel.EventLoopGroup parent, io.netty.channel.EventLoopGroup child, java.lang.Class<? extends io.netty.channel.ServerChannel> channelClass)
public <T> TcpServer<R,W> channelOption(io.netty.channel.ChannelOption<T> option, T value)
TcpServer
ChannelOption
for the server socket created by the newly created server instance.channelOption
in class TcpServer<R,W>
option
- Option to add.value
- Value for the option.TcpServer
instance.public <T> TcpServer<R,W> clientChannelOption(io.netty.channel.ChannelOption<T> option, T value)
TcpServer
ChannelOption
for the client socket created by the newly created server instance.clientChannelOption
in class TcpServer<R,W>
option
- Option to add.value
- Value for the option.TcpServer
instance.public <RR,WW> TcpServer<RR,WW> addChannelHandlerFirst(java.lang.String name, rx.functions.Func0<io.netty.channel.ChannelHandler> handlerFactory)
TcpServer
ChannelHandler
to ChannelPipeline
for all connections created by this server.
The specified handler is added at the first position of the pipeline as specified by
ChannelPipeline.addFirst(String, ChannelHandler)
For better flexibility of pipeline modification, the method TcpServer.pipelineConfigurator(Action1)
will be more convenient.addChannelHandlerFirst
in class TcpServer<R,W>
name
- Name of the handler.handlerFactory
- Factory to create handler instance to add.TcpServer
instance.public <RR,WW> TcpServer<RR,WW> addChannelHandlerFirst(io.netty.util.concurrent.EventExecutorGroup group, java.lang.String name, rx.functions.Func0<io.netty.channel.ChannelHandler> handlerFactory)
TcpServer
ChannelHandler
to ChannelPipeline
for all connections created by this server. The specified
handler is added at the first position of the pipeline as specified by
ChannelPipeline.addFirst(EventExecutorGroup, String, ChannelHandler)
For better flexibility of pipeline modification, the method TcpServer.pipelineConfigurator(Action1)
will be
more convenient.addChannelHandlerFirst
in class TcpServer<R,W>
group
- The EventExecutorGroup
which will be used to execute the ChannelHandler
methodsname
- The name of the handler to appendhandlerFactory
- Factory to create handler instance to add.TcpServer
instance.public <RR,WW> TcpServer<RR,WW> addChannelHandlerLast(java.lang.String name, rx.functions.Func0<io.netty.channel.ChannelHandler> handlerFactory)
TcpServer
ChannelHandler
to ChannelPipeline
for all connections created by this server. The specified
handler is added at the last position of the pipeline as specified by
ChannelPipeline.addLast(String, ChannelHandler)
For better flexibility of pipeline modification, the method TcpServer.pipelineConfigurator(Action1)
will be
more convenient.addChannelHandlerLast
in class TcpServer<R,W>
name
- Name of the handler.handlerFactory
- Factory to create handler instance to add.TcpServer
instance.public <RR,WW> TcpServer<RR,WW> addChannelHandlerLast(io.netty.util.concurrent.EventExecutorGroup group, java.lang.String name, rx.functions.Func0<io.netty.channel.ChannelHandler> handlerFactory)
TcpServer
ChannelHandler
to ChannelPipeline
for all connections created by this server. The specified
handler is added at the last position of the pipeline as specified by
ChannelPipeline.addLast(EventExecutorGroup, String, ChannelHandler)
For better flexibility of pipeline modification, the method TcpServer.pipelineConfigurator(Action1)
will be more
convenient.addChannelHandlerLast
in class TcpServer<R,W>
group
- the EventExecutorGroup
which will be used to execute the ChannelHandler
methodsname
- the name of the handler to appendhandlerFactory
- Factory to create handler instance to add.TcpServer
instance.public <RR,WW> TcpServer<RR,WW> addChannelHandlerBefore(java.lang.String baseName, java.lang.String name, rx.functions.Func0<io.netty.channel.ChannelHandler> handlerFactory)
TcpServer
ChannelHandler
to ChannelPipeline
for all connections created by this server. The specified
handler is added before an existing handler with the passed baseName
in the pipeline as specified by
ChannelPipeline.addBefore(String, String, ChannelHandler)
For better flexibility of pipeline modification, the method TcpServer.pipelineConfigurator(Action1)
will be more
convenient.addChannelHandlerBefore
in class TcpServer<R,W>
baseName
- the name of the existing handlername
- Name of the handler.handlerFactory
- Factory to create handler instance to add.TcpServer
instance.public <RR,WW> TcpServer<RR,WW> addChannelHandlerBefore(io.netty.util.concurrent.EventExecutorGroup group, java.lang.String baseName, java.lang.String name, rx.functions.Func0<io.netty.channel.ChannelHandler> handlerFactory)
TcpServer
ChannelHandler
to ChannelPipeline
for all connections created by this server. The specified
handler is added before an existing handler with the passed baseName
in the pipeline as specified by
ChannelPipeline.addBefore(EventExecutorGroup, String, String, ChannelHandler)
For better flexibility of pipeline modification, the method TcpServer.pipelineConfigurator(Action1)
will be more
convenient.addChannelHandlerBefore
in class TcpServer<R,W>
group
- the EventExecutorGroup
which will be used to execute the ChannelHandler
methodsbaseName
- the name of the existing handlername
- the name of the handler to appendhandlerFactory
- Factory to create handler instance to add.TcpServer
instance.public <RR,WW> TcpServer<RR,WW> addChannelHandlerAfter(java.lang.String baseName, java.lang.String name, rx.functions.Func0<io.netty.channel.ChannelHandler> handlerFactory)
TcpServer
ChannelHandler
to ChannelPipeline
for all connections created by this server. The specified
handler is added after an existing handler with the passed baseName
in the pipeline as specified by
ChannelPipeline.addAfter(String, String, ChannelHandler)
For better flexibility of pipeline modification, the method TcpServer.pipelineConfigurator(Action1)
will be more
convenient.addChannelHandlerAfter
in class TcpServer<R,W>
baseName
- the name of the existing handlername
- Name of the handler.handlerFactory
- Factory to create handler instance to add.TcpServer
instance.public <RR,WW> TcpServer<RR,WW> addChannelHandlerAfter(io.netty.util.concurrent.EventExecutorGroup group, java.lang.String baseName, java.lang.String name, rx.functions.Func0<io.netty.channel.ChannelHandler> handlerFactory)
TcpServer
ChannelHandler
to ChannelPipeline
for all connections created by this server. The specified
handler is added after an existing handler with the passed baseName
in the pipeline as specified by
ChannelPipeline.addAfter(EventExecutorGroup, String, String, ChannelHandler)
For better flexibility of pipeline modification, the method TcpServer.pipelineConfigurator(Action1)
will be more
convenient.addChannelHandlerAfter
in class TcpServer<R,W>
group
- the EventExecutorGroup
which will be used to execute the ChannelHandler
methodsbaseName
- the name of the existing handlername
- the name of the handler to appendhandlerFactory
- Factory to create handler instance to add.TcpServer
instance.public <RR,WW> TcpServer<RR,WW> pipelineConfigurator(rx.functions.Action1<io.netty.channel.ChannelPipeline> pipelineConfigurator)
TcpServer
pipelineConfigurator
in class TcpServer<R,W>
pipelineConfigurator
- Action to configure ChannelPipeline
.TcpServer
instance.public TcpServer<R,W> secure(rx.functions.Func1<io.netty.buffer.ByteBufAllocator,javax.net.ssl.SSLEngine> sslEngineFactory)
TcpServer
sslEngineFactory
for all secured connections accepted by the newly created server instance.
If the SSLEngine
instance can be statically, created, TcpServer.secure(SSLEngine)
can be used.public TcpServer<R,W> secure(javax.net.ssl.SSLEngine sslEngine)
TcpServer
sslEngine
for all secured connections accepted by the newly created server instance.
If the SSLEngine
instance can not be statically, created, TcpServer.secure(Func1)
)} can be used.public TcpServer<R,W> secure(io.reactivex.netty.ssl.SslCodec sslCodec)
TcpServer
sslCodec
for all secured connections accepted by the newly created server instance.
This is required only when the SslHandler
used by SslCodec
is to be modified before adding to
the ChannelPipeline
. For most of the cases, TcpServer.secure(Func1)
or TcpServer.secure(SSLEngine)
will be
enough.public TcpServer<R,W> unsafeSecure()
TcpServer
unsafeSecure
in class TcpServer<R,W>
TcpServer
instance.public TcpServer<R,W> enableWireLogging(io.netty.handler.logging.LogLevel wireLoggingLevel)
TcpServer
enableWireLogging
in class TcpServer<R,W>
wireLoggingLevel
- Logging level at which the wire logs will be logged. The wire logging will only be done if
logging is enabled at this level for LoggingHandler
TcpServer
instance.public int getServerPort()
TcpServer
getServerPort
in class TcpServer<R,W>
public java.net.SocketAddress getServerAddress()
TcpServer
getServerAddress
in class TcpServer<R,W>
public TcpServer<R,W> start(ConnectionHandler<R,W> connectionHandler)
TcpServer
public void shutdown()
TcpServer
public void awaitShutdown()
TcpServer
awaitShutdown
in class TcpServer<R,W>
public void awaitShutdown(long duration, java.util.concurrent.TimeUnit timeUnit)
TcpServer
awaitShutdown
in class TcpServer<R,W>
duration
- Duration to wait for shutdown.timeUnit
- Timeunit for the duration to wait for shutdown.public TcpServerEventPublisher getEventPublisher()
TcpServer
getEventPublisher
in class TcpServer<R,W>
public rx.Subscription subscribe(TcpServerEventListener listener)