diff --git a/spring-messaging/src/main/java/org/springframework/messaging/tcp/reactor/AbstractPromiseToListenableFutureAdapter.java b/spring-messaging/src/main/java/org/springframework/messaging/tcp/reactor/AbstractPromiseToListenableFutureAdapter.java
index 935128ae76..e635e310ab 100644
--- a/spring-messaging/src/main/java/org/springframework/messaging/tcp/reactor/AbstractPromiseToListenableFutureAdapter.java
+++ b/spring-messaging/src/main/java/org/springframework/messaging/tcp/reactor/AbstractPromiseToListenableFutureAdapter.java
@@ -80,7 +80,7 @@ abstract class AbstractPromiseToListenableFutureAdapter implements Listena
@Override
public T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
S result = this.promise.await(timeout, unit);
- if (result == null) {
+ if (!this.promise.isComplete()) {
throw new TimeoutException();
}
return adapt(result);
diff --git a/spring-messaging/src/main/java/org/springframework/messaging/tcp/reactor/Reactor2TcpClient.java b/spring-messaging/src/main/java/org/springframework/messaging/tcp/reactor/Reactor2TcpClient.java
index f454243ba2..c9601e4479 100644
--- a/spring-messaging/src/main/java/org/springframework/messaging/tcp/reactor/Reactor2TcpClient.java
+++ b/spring-messaging/src/main/java/org/springframework/messaging/tcp/reactor/Reactor2TcpClient.java
@@ -21,8 +21,11 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Properties;
+import java.util.concurrent.atomic.AtomicBoolean;
import io.netty.channel.nio.NioEventLoopGroup;
+import io.netty.util.concurrent.Future;
+import io.netty.util.concurrent.FutureListener;
import org.reactivestreams.Publisher;
import reactor.Environment;
import reactor.core.config.ConfigurationReader;
@@ -79,6 +82,10 @@ public class Reactor2TcpClient
implements TcpOperations
{
private final List >> tcpClients =
new ArrayList >>();
+ private final NioEventLoopGroup eventLoopGroup;
+
+ private boolean stopping;
+
/**
* A constructor that creates a {@link TcpClientSpec TcpClientSpec} factory
@@ -95,7 +102,7 @@ public class Reactor2TcpClient implements TcpOperations {
*/
public Reactor2TcpClient(final String host, final int port, final Codec > codec) {
- final NioEventLoopGroup eventLoopGroup = initEventLoopGroup();
+ this.eventLoopGroup = initEventLoopGroup();
this.tcpClientSpecFactory = new TcpClientFactory >() {
@@ -110,7 +117,7 @@ public class Reactor2TcpClient implements TcpOperations {
};
}
- private NioEventLoopGroup initEventLoopGroup() {
+ private static NioEventLoopGroup initEventLoopGroup() {
int ioThreadCount;
try {
ioThreadCount = Integer.parseInt(System.getProperty("reactor.tcp.ioThreadCount"));
@@ -139,13 +146,27 @@ public class Reactor2TcpClient implements TcpOperations {
public Reactor2TcpClient(TcpClientFactory > tcpClientSpecFactory) {
Assert.notNull(tcpClientSpecFactory, "'tcpClientClientFactory' must not be null");
this.tcpClientSpecFactory = tcpClientSpecFactory;
+ this.eventLoopGroup = null;
}
@Override
public ListenableFuture connectionHandler) {
Assert.notNull(connectionHandler, "'connectionHandler' must not be null");
- Promise (connectionHandler));
+
+ TcpClient > tcpClient;
+ synchronized (this.tcpClients) {
+ if (this.stopping) {
+ IllegalStateException ex = new IllegalStateException("Shutting down.");
+ connectionHandler.afterConnectFailure(ex);
+ return new PassThroughPromiseToListenableFutureAdapter (connectionHandler));
+
return new PassThroughPromiseToListenableFutureAdapter implements TcpOperations {
Assert.notNull(connectionHandler, "'connectionHandler' must not be null");
Assert.notNull(strategy, "'reconnectStrategy' must not be null");
- Stream > tcpClient;
+ synchronized (this.tcpClients) {
+ if (this.stopping) {
+ IllegalStateException ex = new IllegalStateException("Shutting down.");
+ connectionHandler.afterConnectFailure(ex);
+ return new PassThroughPromiseToListenableFutureAdapter (connectionHandler),
new ReactorReconnectAdapter(strategy));
return new PassThroughPromiseToListenableFutureAdapter > createTcpClient() {
- Class > tcpClient = NetStreams.tcpClient(type, this.tcpClientSpecFactory);
- synchronized (this.tcpClients) {
- this.tcpClients.add(tcpClient);
- }
- return tcpClient;
- }
-
@Override
public ListenableFuture >> readOnlyClients;
synchronized (this.tcpClients) {
- readOnlyClients = new ArrayList >>(this.tcpClients);
+ this.stopping = true;
}
- Promise >, Promise > client) {
return client.shutdown().onComplete(new Consumer