Skip to content

Commit 4d157ac

Browse files
author
Stephane Landelle
committed
minor renaming
1 parent b4f289b commit 4d157ac

File tree

1 file changed

+15
-20
lines changed

1 file changed

+15
-20
lines changed

src/main/java/com/ning/http/client/providers/netty/NettyConnectionsPool.java

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,16 @@ private void scheduleNewIdleChannelDetector(TimerTask task) {
7676
}
7777

7878
private static final class IdleChannel {
79-
final String uri;
79+
final String key;
8080
final Channel channel;
8181
final long start;
8282

83-
IdleChannel(String uri, Channel channel) {
84-
if (uri == null)
85-
throw new NullPointerException("uri");
83+
IdleChannel(String key, Channel channel) {
84+
if (key == null)
85+
throw new NullPointerException("key");
8686
if (channel == null)
8787
throw new NullPointerException("channel");
88-
this.uri = uri;
88+
this.key = key;
8989
this.channel = channel;
9090
this.start = millisTime();
9191
}
@@ -218,13 +218,13 @@ public Channel poll(String uri) {
218218
}
219219

220220
IdleChannel idleChannel = null;
221-
ConcurrentLinkedQueue<IdleChannel> idleConnectionForHost = connectionsPool.get(uri);
222-
if (idleConnectionForHost != null) {
221+
ConcurrentLinkedQueue<IdleChannel> pooledConnectionForKey = connectionsPool.get(uri);
222+
if (pooledConnectionForKey != null) {
223223
boolean poolEmpty = false;
224224
while (!poolEmpty && idleChannel == null) {
225-
if (!idleConnectionForHost.isEmpty()) {
226-
synchronized (idleConnectionForHost) {
227-
idleChannel = idleConnectionForHost.poll();
225+
if (!pooledConnectionForKey.isEmpty()) {
226+
synchronized (pooledConnectionForKey) {
227+
idleChannel = pooledConnectionForKey.poll();
228228
if (idleChannel != null) {
229229
channel2IdleChannel.remove(idleChannel.channel);
230230
}
@@ -247,12 +247,11 @@ private boolean remove(IdleChannel pooledChannel) {
247247
return false;
248248

249249
boolean isRemoved = false;
250-
ConcurrentLinkedQueue<IdleChannel> pooledConnectionForHost = connectionsPool.get(pooledChannel.uri);
251-
if (pooledConnectionForHost != null) {
252-
isRemoved = pooledConnectionForHost.remove(pooledChannel);
250+
ConcurrentLinkedQueue<IdleChannel> pooledConnectionForKey = connectionsPool.get(pooledChannel.key);
251+
if (pooledConnectionForKey != null) {
252+
isRemoved = pooledConnectionForKey.remove(pooledChannel);
253253
}
254-
isRemoved |= channel2IdleChannel.remove(pooledChannel.channel) != null;
255-
return isRemoved;
254+
return isRemoved |= channel2IdleChannel.remove(pooledChannel.channel) != null;
256255
}
257256

258257
/**
@@ -267,11 +266,7 @@ public boolean removeAll(Channel channel) {
267266
* {@inheritDoc}
268267
*/
269268
public boolean canCacheConnection() {
270-
if (!isClosed.get() && maxTotalConnections != -1 && channel2IdleChannel.size() >= maxTotalConnections) {
271-
return false;
272-
} else {
273-
return true;
274-
}
269+
return !isClosed.get() && (maxTotalConnections != -1 || channel2IdleChannel.size() < maxTotalConnections);
275270
}
276271

277272
/**

0 commit comments

Comments
 (0)