public class Reactor2TcpClient<P> extends java.lang.Object implements TcpOperations<P>
TcpOperations
based on the TCP client support of the Reactor project.
This implementation wraps N (Reactor) clients for N connect(org.springframework.messaging.tcp.TcpConnectionHandler<P>)
calls,
i.e. a separate (Reactor) client instance for each connection.
Modifier and Type | Class and Description |
---|---|
private static class |
Reactor2TcpClient.MessageChannelStreamHandler<P> |
private static class |
Reactor2TcpClient.ReactorReconnectAdapter |
private static class |
Reactor2TcpClient.SynchronousDispatcherConfigReader |
Modifier and Type | Field and Description |
---|---|
private NioEventLoopGroup |
eventLoopGroup |
static java.lang.Class<NettyTcpClient> |
REACTOR_TCP_CLIENT_TYPE |
private boolean |
stopping |
private java.util.List<<any>> |
tcpClients |
private <any> |
tcpClientSpecFactory |
Constructor and Description |
---|
Reactor2TcpClient(<any> tcpClientSpecFactory)
A constructor with a pre-configured
TcpClientSpec Function
factory. |
Reactor2TcpClient(java.lang.String host,
int port,
<any> codec)
A constructor that creates a
TcpClientSpec factory
with a default reactor.core.dispatch.SynchronousDispatcher , i.e. |
Modifier and Type | Method and Description |
---|---|
ListenableFuture<java.lang.Void> |
connect(TcpConnectionHandler<P> connectionHandler)
Open a new connection.
|
ListenableFuture<java.lang.Void> |
connect(TcpConnectionHandler<P> connectionHandler,
ReconnectStrategy strategy)
Open a new connection and a strategy for reconnecting if the connection fails.
|
private static NioEventLoopGroup |
initEventLoopGroup() |
ListenableFuture<java.lang.Void> |
shutdown()
Shut down and close any open connections.
|
public static final java.lang.Class<NettyTcpClient> REACTOR_TCP_CLIENT_TYPE
private final <any> tcpClientSpecFactory
private final java.util.List<<any>> tcpClients
private final NioEventLoopGroup eventLoopGroup
private boolean stopping
public Reactor2TcpClient(java.lang.String host, int port, <any> codec)
TcpClientSpec
factory
with a default reactor.core.dispatch.SynchronousDispatcher
, i.e.
relying on Netty threads. The number of Netty threads can be tweaked with
the reactor.tcp.ioThreadCount
System property. The network I/O
threads will be shared amongst the active clients.
Also see the constructor accepting a ready Reactor
TcpClientSpec
Function
factory.
host
- the host to connect toport
- the port to connect tocodec
- the codec to use for encoding and decoding the TCP streampublic Reactor2TcpClient(<any> tcpClientSpecFactory)
TcpClientSpec
Function
factory. This might be used to add SSL or specific network parameters to
the generated client configuration.
NOTE: if the client is configured with a thread-creating
dispatcher, you are responsible for cleaning them, e.g. using
reactor.core.Dispatcher#shutdown
.
tcpClientSpecFactory
- the TcpClientSpec Function
to use for each client creation.private static NioEventLoopGroup initEventLoopGroup()
public ListenableFuture<java.lang.Void> connect(TcpConnectionHandler<P> connectionHandler)
TcpOperations
connect
in interface TcpOperations<P>
connectionHandler
- a handler to manage the connectionpublic ListenableFuture<java.lang.Void> connect(TcpConnectionHandler<P> connectionHandler, ReconnectStrategy strategy)
TcpOperations
connect
in interface TcpOperations<P>
connectionHandler
- a handler to manage the connectionstrategy
- a strategy for reconnectingpublic ListenableFuture<java.lang.Void> shutdown()
TcpOperations
shutdown
in interface TcpOperations<P>