Skip to content

Commit 6e78569

Browse files
garyrussellartembilan
authored andcommitted
GH-2736: TCP Async GW - Fix async check
Checking for NIO cannot be done in `onInit()` because the factory is not yet started. **cherry-pick to 5.3.x**
1 parent ef939a0 commit 6e78569

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/TcpOutboundGateway.java

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import org.springframework.integration.ip.tcp.connection.AbstractConnectionFactory;
4040
import org.springframework.integration.ip.tcp.connection.TcpConnection;
4141
import org.springframework.integration.ip.tcp.connection.TcpConnectionFailedCorrelationEvent;
42-
import org.springframework.integration.ip.tcp.connection.TcpConnectionSupport;
4342
import org.springframework.integration.ip.tcp.connection.TcpListener;
4443
import org.springframework.integration.ip.tcp.connection.TcpNioConnectionSupport;
4544
import org.springframework.integration.ip.tcp.connection.TcpSender;
@@ -127,21 +126,6 @@ protected void doInit() {
127126
}
128127
Assert.state(!this.closeStreamAfterSend || this.isSingleUse,
129128
"Single use connection needed with closeStreamAfterSend");
130-
if (isAsync()) {
131-
try {
132-
TcpConnectionSupport connection = this.connectionFactory.getConnection();
133-
if (connection instanceof TcpNioConnectionSupport) {
134-
setAsync(false);
135-
this.logger.warn("Async replies are not supported with NIO; see the reference manual");
136-
}
137-
if (this.isSingleUse) {
138-
connection.close();
139-
}
140-
}
141-
catch (Exception e) {
142-
this.logger.error("Could not check if async is supported", e);
143-
}
144-
}
145129
}
146130

147131
/**
@@ -167,6 +151,7 @@ protected Object handleRequestMessage(Message<?> requestMessage) {
167151
try {
168152
haveSemaphore = acquireSemaphoreIfNeeded(requestMessage);
169153
connection = this.connectionFactory.getConnection();
154+
checkAsync(connection, async);
170155
Long remoteTimeout = getRemoteTimeout(requestMessage);
171156
AsyncReply reply = new AsyncReply(remoteTimeout, connection, haveSemaphore, requestMessage, async);
172157
connectionId = connection.getConnectionId();
@@ -203,6 +188,13 @@ protected Object handleRequestMessage(Message<?> requestMessage) {
203188
}
204189
}
205190

191+
private void checkAsync(TcpConnection connection, boolean async) {
192+
if (async && connection instanceof TcpNioConnectionSupport) {
193+
setAsync(false);
194+
this.logger.warn("Async replies are not supported with NIO; see the reference manual");
195+
}
196+
}
197+
206198
private boolean acquireSemaphoreIfNeeded(Message<?> requestMessage) throws InterruptedException {
207199
if (!this.isSingleUse) {
208200
logger.debug("trying semaphore");

0 commit comments

Comments
 (0)