R
- The type of objects read from this server.W
- The type of objects written to this server.public abstract class TcpServer<R,W> extends java.lang.Object implements io.reactivex.netty.events.EventSource<TcpServerEventListener>
Constructor and Description |
---|
TcpServer() |
Modifier and Type | Method and Description |
---|---|
abstract <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. |
abstract <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. |
abstract <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. |
abstract <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. |
abstract <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. |
abstract <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. |
abstract <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. |
abstract <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. |
abstract void |
awaitShutdown()
Waits for the shutdown of this server.
|
abstract void |
awaitShutdown(long duration,
java.util.concurrent.TimeUnit timeUnit)
Waits for the shutdown of this server, waiting a maximum of the passed duration.
|
abstract <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. |
abstract <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. |
abstract 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.
|
abstract TcpServerEventPublisher |
getEventPublisher()
Returns the event publisher for this server.
|
abstract java.net.SocketAddress |
getServerAddress()
Returns the address at which this server is running.
|
abstract int |
getServerPort()
Returns the port at which this server is running.
|
static TcpServer<io.netty.buffer.ByteBuf,io.netty.buffer.ByteBuf> |
newServer()
Creates a new server using an ephemeral port.
|
static TcpServer<io.netty.buffer.ByteBuf,io.netty.buffer.ByteBuf> |
newServer(int port)
Creates a new server using the passed port.
|
static TcpServer<io.netty.buffer.ByteBuf,io.netty.buffer.ByteBuf> |
newServer(int port,
io.netty.channel.EventLoopGroup eventLoopGroup,
java.lang.Class<? extends io.netty.channel.ServerChannel> channelClass)
Creates a new server using the passed port.
|
static TcpServer<io.netty.buffer.ByteBuf,io.netty.buffer.ByteBuf> |
newServer(int port,
io.netty.channel.EventLoopGroup acceptGroup,
io.netty.channel.EventLoopGroup clientGroup,
java.lang.Class<? extends io.netty.channel.ServerChannel> channelClass)
Creates a new server using the passed port.
|
static TcpServer<io.netty.buffer.ByteBuf,io.netty.buffer.ByteBuf> |
newServer(java.net.SocketAddress socketAddress)
Creates a new server using the passed address.
|
static TcpServer<io.netty.buffer.ByteBuf,io.netty.buffer.ByteBuf> |
newServer(java.net.SocketAddress socketAddress,
io.netty.channel.EventLoopGroup eventLoopGroup,
java.lang.Class<? extends io.netty.channel.ServerChannel> channelClass)
Creates a new server using the passed address.
|
static TcpServer<io.netty.buffer.ByteBuf,io.netty.buffer.ByteBuf> |
newServer(java.net.SocketAddress socketAddress,
io.netty.channel.EventLoopGroup acceptGroup,
io.netty.channel.EventLoopGroup clientGroup,
java.lang.Class<? extends io.netty.channel.ServerChannel> channelClass)
Creates a new server using the passed address.
|
abstract <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.
|
abstract 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. |
abstract 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. |
abstract 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. |
abstract void |
shutdown()
Shutdown this server and waits till the server socket is closed.
|
abstract TcpServer<R,W> |
start(ConnectionHandler<R,W> connectionHandler)
Starts this server.
|
abstract 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.
|
public abstract <T> TcpServer<R,W> channelOption(io.netty.channel.ChannelOption<T> option, T value)
ChannelOption
for the server socket created by the newly created server instance.option
- Option to add.value
- Value for the option.TcpServer
instance.public abstract <T> TcpServer<R,W> clientChannelOption(io.netty.channel.ChannelOption<T> option, T value)
ChannelOption
for the client socket created by the newly created server instance.option
- Option to add.value
- Value for the option.TcpServer
instance.public abstract <RR,WW> TcpServer<RR,WW> addChannelHandlerFirst(java.lang.String name, rx.functions.Func0<io.netty.channel.ChannelHandler> handlerFactory)
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 pipelineConfigurator(Action1)
will be more convenient.name
- Name of the handler.handlerFactory
- Factory to create handler instance to add.TcpServer
instance.public abstract <RR,WW> TcpServer<RR,WW> addChannelHandlerFirst(io.netty.util.concurrent.EventExecutorGroup group, java.lang.String name, rx.functions.Func0<io.netty.channel.ChannelHandler> handlerFactory)
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 pipelineConfigurator(Action1)
will be
more convenient.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 abstract <RR,WW> TcpServer<RR,WW> addChannelHandlerLast(java.lang.String name, rx.functions.Func0<io.netty.channel.ChannelHandler> handlerFactory)
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 pipelineConfigurator(Action1)
will be
more convenient.name
- Name of the handler.handlerFactory
- Factory to create handler instance to add.TcpServer
instance.public abstract <RR,WW> TcpServer<RR,WW> addChannelHandlerLast(io.netty.util.concurrent.EventExecutorGroup group, java.lang.String name, rx.functions.Func0<io.netty.channel.ChannelHandler> handlerFactory)
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 pipelineConfigurator(Action1)
will be more
convenient.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 abstract <RR,WW> TcpServer<RR,WW> addChannelHandlerBefore(java.lang.String baseName, java.lang.String name, rx.functions.Func0<io.netty.channel.ChannelHandler> handlerFactory)
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 pipelineConfigurator(Action1)
will be more
convenient.baseName
- the name of the existing handlername
- Name of the handler.handlerFactory
- Factory to create handler instance to add.TcpServer
instance.public abstract <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)
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 pipelineConfigurator(Action1)
will be more
convenient.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 abstract <RR,WW> TcpServer<RR,WW> addChannelHandlerAfter(java.lang.String baseName, java.lang.String name, rx.functions.Func0<io.netty.channel.ChannelHandler> handlerFactory)
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 pipelineConfigurator(Action1)
will be more
convenient.baseName
- the name of the existing handlername
- Name of the handler.handlerFactory
- Factory to create handler instance to add.TcpServer
instance.public abstract <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)
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 pipelineConfigurator(Action1)
will be more
convenient.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 abstract <RR,WW> TcpServer<RR,WW> pipelineConfigurator(rx.functions.Action1<io.netty.channel.ChannelPipeline> pipelineConfigurator)
pipelineConfigurator
- Action to configure ChannelPipeline
.TcpServer
instance.public abstract TcpServer<R,W> secure(rx.functions.Func1<io.netty.buffer.ByteBufAllocator,javax.net.ssl.SSLEngine> sslEngineFactory)
sslEngineFactory
for all secured connections accepted by the newly created server instance.
If the SSLEngine
instance can be statically, created, secure(SSLEngine)
can be used.sslEngineFactory
- Factory for all secured connections created by the newly created server instance.TcpServer
instance.public abstract TcpServer<R,W> secure(javax.net.ssl.SSLEngine sslEngine)
sslEngine
for all secured connections accepted by the newly created server instance.
If the SSLEngine
instance can not be statically, created, secure(Func1)
)} can be used.sslEngine
- SSLEngine
for all secured connections created by the newly created server instance.TcpServer
instance.public abstract TcpServer<R,W> secure(io.reactivex.netty.ssl.SslCodec sslCodec)
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, secure(Func1)
or secure(SSLEngine)
will be
enough.sslCodec
- SslCodec
for all secured connections created by the newly created server instance.TcpServer
instance.public abstract TcpServer<R,W> unsafeSecure()
TcpServer
instance.public abstract TcpServer<R,W> enableWireLogging(io.netty.handler.logging.LogLevel wireLoggingLevel)
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 abstract int getServerPort()
public abstract java.net.SocketAddress getServerAddress()
public abstract TcpServer<R,W> start(ConnectionHandler<R,W> connectionHandler)
connectionHandler
- Connection handler that will handle any new server connections to this server.public abstract void shutdown()
public abstract void awaitShutdown()
public abstract void awaitShutdown(long duration, java.util.concurrent.TimeUnit timeUnit)
duration
- Duration to wait for shutdown.timeUnit
- Timeunit for the duration to wait for shutdown.public abstract TcpServerEventPublisher getEventPublisher()
public static TcpServer<io.netty.buffer.ByteBuf,io.netty.buffer.ByteBuf> newServer()
getServerPort()
TcpServer
public static TcpServer<io.netty.buffer.ByteBuf,io.netty.buffer.ByteBuf> newServer(int port)
port
- Port for the server. 0
to use ephemeral port.TcpServer
public static TcpServer<io.netty.buffer.ByteBuf,io.netty.buffer.ByteBuf> newServer(int port, io.netty.channel.EventLoopGroup eventLoopGroup, java.lang.Class<? extends io.netty.channel.ServerChannel> channelClass)
port
- Port for the server. 0
to use ephemeral port.eventLoopGroup
- Eventloop group to be used for server as well as client sockets.channelClass
- The class to be used for server channel.TcpServer
public static TcpServer<io.netty.buffer.ByteBuf,io.netty.buffer.ByteBuf> newServer(int port, io.netty.channel.EventLoopGroup acceptGroup, io.netty.channel.EventLoopGroup clientGroup, java.lang.Class<? extends io.netty.channel.ServerChannel> channelClass)
port
- Port for the server. 0
to use ephemeral port.acceptGroup
- Eventloop group to be used for server sockets.clientGroup
- Eventloop group to be used for client sockets.channelClass
- The class to be used for server channel.TcpServer
public static TcpServer<io.netty.buffer.ByteBuf,io.netty.buffer.ByteBuf> newServer(java.net.SocketAddress socketAddress)
socketAddress
- Socket address for the server.TcpServer
public static TcpServer<io.netty.buffer.ByteBuf,io.netty.buffer.ByteBuf> newServer(java.net.SocketAddress socketAddress, io.netty.channel.EventLoopGroup eventLoopGroup, java.lang.Class<? extends io.netty.channel.ServerChannel> channelClass)
socketAddress
- Socket address for the server.eventLoopGroup
- Eventloop group to be used for server as well as client sockets.channelClass
- The class to be used for server channel.TcpServer
public static TcpServer<io.netty.buffer.ByteBuf,io.netty.buffer.ByteBuf> newServer(java.net.SocketAddress socketAddress, io.netty.channel.EventLoopGroup acceptGroup, io.netty.channel.EventLoopGroup clientGroup, java.lang.Class<? extends io.netty.channel.ServerChannel> channelClass)
socketAddress
- Socket address for the server.acceptGroup
- Eventloop group to be used for server sockets.clientGroup
- Eventloop group to be used for client sockets.channelClass
- The class to be used for server channel.TcpServer