Skip to content

Commit fefb1f2

Browse files
committed
GH-1194: Address new Sonar issues
1 parent 4a3c427 commit fefb1f2

File tree

1 file changed

+30
-28
lines changed

1 file changed

+30
-28
lines changed

spring-rabbit/src/main/java/org/springframework/amqp/rabbit/connection/CachingConnectionFactory.java

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,16 +1086,14 @@ else if (methodName.equals("toString")) {
10861086
}
10871087
else if (methodName.equals("close")) {
10881088
// 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;
10941096
}
1095-
1096-
// If we get here, we're supposed to shut down.
1097-
physicalClose(proxy);
1098-
return null;
10991097
}
11001098
else if (methodName.equals("getTargetChannel")) {
11011099
// Handle getTargetChannel method: return underlying Channel.
@@ -1237,25 +1235,7 @@ private void doReturnToCache(Channel proxy) {
12371235
synchronized (this.channelList) {
12381236
// Allow for multiple close calls...
12391237
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);
12591239
}
12601240
else {
12611241
if (proxy.isOpen()) {
@@ -1270,6 +1250,28 @@ else if (!alreadyCached) {
12701250
}
12711251
}
12721252

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+
12731275
private void setHighWaterMark() {
12741276
AtomicInteger hwm = CachingConnectionFactory.this.channelHighWaterMarks.get(this.channelListIdentity);
12751277
if (hwm != null) {

0 commit comments

Comments
 (0)