@@ -1086,16 +1086,14 @@ else if (methodName.equals("toString")) {
1086
1086
}
1087
1087
else if (methodName .equals ("close" )) {
1088
1088
// Handle close method: don't pass the call on.
1089
- if (CachingConnectionFactory .this .active ) {
1090
- if (!RabbitUtils .isPhysicalCloseRequired ()) {
1091
- logicalClose ((ChannelProxy ) proxy );
1092
- return null ;
1093
- }
1089
+ if (CachingConnectionFactory .this .active && !RabbitUtils .isPhysicalCloseRequired ()) {
1090
+ logicalClose ((ChannelProxy ) proxy );
1091
+ return null ;
1092
+ }
1093
+ else {
1094
+ physicalClose (proxy );
1095
+ return null ;
1094
1096
}
1095
-
1096
- // If we get here, we're supposed to shut down.
1097
- physicalClose (proxy );
1098
- return null ;
1099
1097
}
1100
1098
else if (methodName .equals ("getTargetChannel" )) {
1101
1099
// Handle getTargetChannel method: return underlying Channel.
@@ -1237,25 +1235,7 @@ private void doReturnToCache(Channel proxy) {
1237
1235
synchronized (this .channelList ) {
1238
1236
// Allow for multiple close calls...
1239
1237
if (CachingConnectionFactory .this .active ) {
1240
- boolean alreadyCached = this .channelList .contains (proxy );
1241
- if (this .channelList .size () >= getChannelCacheSize () && !alreadyCached ) {
1242
- if (logger .isTraceEnabled ()) {
1243
- logger .trace ("Cache limit reached: " + this .target );
1244
- }
1245
- try {
1246
- physicalClose (proxy );
1247
- }
1248
- catch (@ SuppressWarnings (UNUSED ) Exception e ) {
1249
- }
1250
- }
1251
- else if (!alreadyCached ) {
1252
- if (logger .isTraceEnabled ()) {
1253
- logger .trace ("Returning cached Channel: " + this .target );
1254
- }
1255
- releasePermitIfNecessary (proxy );
1256
- this .channelList .addLast ((ChannelProxy ) proxy );
1257
- setHighWaterMark ();
1258
- }
1238
+ cacheOrClose (proxy );
1259
1239
}
1260
1240
else {
1261
1241
if (proxy .isOpen ()) {
@@ -1270,6 +1250,28 @@ else if (!alreadyCached) {
1270
1250
}
1271
1251
}
1272
1252
1253
+ private void cacheOrClose (Channel proxy ) {
1254
+ boolean alreadyCached = this .channelList .contains (proxy );
1255
+ if (this .channelList .size () >= getChannelCacheSize () && !alreadyCached ) {
1256
+ if (logger .isTraceEnabled ()) {
1257
+ logger .trace ("Cache limit reached: " + this .target );
1258
+ }
1259
+ try {
1260
+ physicalClose (proxy );
1261
+ }
1262
+ catch (@ SuppressWarnings (UNUSED ) Exception e ) {
1263
+ }
1264
+ }
1265
+ else if (!alreadyCached ) {
1266
+ if (logger .isTraceEnabled ()) {
1267
+ logger .trace ("Returning cached Channel: " + this .target );
1268
+ }
1269
+ releasePermitIfNecessary (proxy );
1270
+ this .channelList .addLast ((ChannelProxy ) proxy );
1271
+ setHighWaterMark ();
1272
+ }
1273
+ }
1274
+
1273
1275
private void setHighWaterMark () {
1274
1276
AtomicInteger hwm = CachingConnectionFactory .this .channelHighWaterMarks .get (this .channelListIdentity );
1275
1277
if (hwm != null ) {
0 commit comments