GH-9430: Fix CachingClientCF for collaborating channel adapters (#9431)
Fixes: #9430 When `CachingClientConnectionFactory` is used in combination of `Tcp.outboundAdapter()` & `Tcp.inboundAdapter()`, the connection is not released back to the cache because `CachingClientConnectionFactory` does not store created connections into its `connections` property. So, when `TcpReceivingChannelAdapter` calls `this.clientConnectionFactory.closeConnection(connectionId);` it returned immediately because there is nothing to remove from the `this.connections` * Add `protected removeConnection()` in the `AbstractConnectionFactory` and override it in the `CachingClientConnectionFactory` with delegation to the `this.targetConnectionFactory` * Demonstrate the problem in the new `IpIntegrationTests.allRepliesAreReceivedViaLimitedCachingConnectionFactory()` test and ensure that all 27 letters from English alphabet are sent to the server and received in uppercase while size of the `CachingClientConnectionFactory` is only `10` **Auto-cherry-pick to `6.3.x` & `6.2.x`**
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -977,7 +977,7 @@ public abstract class AbstractConnectionFactory extends IntegrationObjectSupport
|
||||
this.connectionsMonitor.lock();
|
||||
try {
|
||||
boolean closed = false;
|
||||
TcpConnectionSupport connection = this.connections.remove(connectionId);
|
||||
TcpConnectionSupport connection = removeConnection(connectionId);
|
||||
if (connection != null) {
|
||||
try {
|
||||
connection.close();
|
||||
@@ -996,6 +996,11 @@ public abstract class AbstractConnectionFactory extends IntegrationObjectSupport
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected TcpConnectionSupport removeConnection(String connectionId) {
|
||||
return this.connections.remove(connectionId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return super.toString()
|
||||
|
||||
@@ -358,6 +358,11 @@ public class CachingClientConnectionFactory extends AbstractClientConnectionFact
|
||||
this.targetConnectionFactory.enableManualListenerRegistration();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TcpConnectionSupport removeConnection(String connectionId) {
|
||||
return this.targetConnectionFactory.removeConnection(connectionId.replaceFirst("Cached:", ""));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
setActive(true);
|
||||
|
||||
Reference in New Issue
Block a user