@@ -76,16 +76,16 @@ private void scheduleNewIdleChannelDetector(TimerTask task) {
76
76
}
77
77
78
78
private static final class IdleChannel {
79
- final String uri ;
79
+ final String key ;
80
80
final Channel channel ;
81
81
final long start ;
82
82
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 " );
86
86
if (channel == null )
87
87
throw new NullPointerException ("channel" );
88
- this .uri = uri ;
88
+ this .key = key ;
89
89
this .channel = channel ;
90
90
this .start = millisTime ();
91
91
}
@@ -218,13 +218,13 @@ public Channel poll(String uri) {
218
218
}
219
219
220
220
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 ) {
223
223
boolean poolEmpty = false ;
224
224
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 ();
228
228
if (idleChannel != null ) {
229
229
channel2IdleChannel .remove (idleChannel .channel );
230
230
}
@@ -247,12 +247,11 @@ private boolean remove(IdleChannel pooledChannel) {
247
247
return false ;
248
248
249
249
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 );
253
253
}
254
- isRemoved |= channel2IdleChannel .remove (pooledChannel .channel ) != null ;
255
- return isRemoved ;
254
+ return isRemoved |= channel2IdleChannel .remove (pooledChannel .channel ) != null ;
256
255
}
257
256
258
257
/**
@@ -267,11 +266,7 @@ public boolean removeAll(Channel channel) {
267
266
* {@inheritDoc}
268
267
*/
269
268
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 );
275
270
}
276
271
277
272
/**
0 commit comments