3939import org .springframework .integration .ip .tcp .connection .AbstractConnectionFactory ;
4040import org .springframework .integration .ip .tcp .connection .TcpConnection ;
4141import org .springframework .integration .ip .tcp .connection .TcpConnectionFailedCorrelationEvent ;
42- import org .springframework .integration .ip .tcp .connection .TcpConnectionSupport ;
4342import org .springframework .integration .ip .tcp .connection .TcpListener ;
4443import org .springframework .integration .ip .tcp .connection .TcpNioConnectionSupport ;
4544import 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