GH-1194: Address new Sonar issues

This commit is contained in:
Gary Russell
2020-05-09 15:42:22 -04:00
parent 33f166f47b
commit 42f8bd55a6

View File

@@ -1136,16 +1136,14 @@ public class CachingConnectionFactory extends AbstractConnectionFactory
}
else if (methodName.equals("close")) {
// Handle close method: don't pass the call on.
if (CachingConnectionFactory.this.active) {
if (!RabbitUtils.isPhysicalCloseRequired()) {
logicalClose((ChannelProxy) proxy);
return null;
}
if (CachingConnectionFactory.this.active && !RabbitUtils.isPhysicalCloseRequired()) {
logicalClose((ChannelProxy) proxy);
return null;
}
else {
physicalClose(proxy);
return null;
}
// If we get here, we're supposed to shut down.
physicalClose(proxy);
return null;
}
else if (methodName.equals("getTargetChannel")) {
// Handle getTargetChannel method: return underlying Channel.
@@ -1287,25 +1285,7 @@ public class CachingConnectionFactory extends AbstractConnectionFactory
synchronized (this.channelList) {
// Allow for multiple close calls...
if (CachingConnectionFactory.this.active) {
boolean alreadyCached = this.channelList.contains(proxy);
if (this.channelList.size() >= getChannelCacheSize() && !alreadyCached) {
if (logger.isTraceEnabled()) {
logger.trace("Cache limit reached: " + this.target);
}
try {
physicalClose(proxy);
}
catch (@SuppressWarnings(UNUSED) Exception e) {
}
}
else if (!alreadyCached) {
if (logger.isTraceEnabled()) {
logger.trace("Returning cached Channel: " + this.target);
}
releasePermitIfNecessary(proxy);
this.channelList.addLast((ChannelProxy) proxy);
setHighWaterMark();
}
cacheOrClose(proxy);
}
else {
if (proxy.isOpen()) {
@@ -1320,6 +1300,28 @@ public class CachingConnectionFactory extends AbstractConnectionFactory
}
}
private void cacheOrClose(Channel proxy) {
boolean alreadyCached = this.channelList.contains(proxy);
if (this.channelList.size() >= getChannelCacheSize() && !alreadyCached) {
if (logger.isTraceEnabled()) {
logger.trace("Cache limit reached: " + this.target);
}
try {
physicalClose(proxy);
}
catch (@SuppressWarnings(UNUSED) Exception e) {
}
}
else if (!alreadyCached) {
if (logger.isTraceEnabled()) {
logger.trace("Returning cached Channel: " + this.target);
}
releasePermitIfNecessary(proxy);
this.channelList.addLast((ChannelProxy) proxy);
setHighWaterMark();
}
}
private void setHighWaterMark() {
AtomicInteger hwm = CachingConnectionFactory.this.channelHighWaterMarks.get(this.channelListIdentity);
if (hwm != null) {