@@ -44,7 +44,7 @@ public final class DefaultChannelPool implements ChannelPool {
44
44
private static final Logger LOGGER = LoggerFactory .getLogger (DefaultChannelPool .class );
45
45
46
46
private final ConcurrentHashMap <String , ConcurrentLinkedQueue <IdleChannel >> partitions = new ConcurrentHashMap <>();
47
- private final ConcurrentHashMap <Channel , ChannelCreation > channel2Creation = new ConcurrentHashMap <>();
47
+ private final ConcurrentHashMap <Integer , ChannelCreation > channelId2Creation = new ConcurrentHashMap <>();
48
48
private final AtomicBoolean isClosed = new AtomicBoolean (false );
49
49
private final Timer nettyTimer ;
50
50
private final boolean sslConnectionPoolEnabled ;
@@ -61,6 +61,10 @@ public DefaultChannelPool(AsyncHttpClientConfig config, Timer hashedWheelTimer)
61
61
hashedWheelTimer );
62
62
}
63
63
64
+ private int channelId (Channel channel ) {
65
+ return channel .hashCode ();
66
+ }
67
+
64
68
public DefaultChannelPool (
65
69
long maxIdleTime ,//
66
70
int maxConnectionTTL ,//
@@ -121,7 +125,7 @@ private boolean isTTLExpired(Channel channel, long now) {
121
125
if (maxConnectionTTLDisabled )
122
126
return false ;
123
127
124
- ChannelCreation creation = channel2Creation .get (channel );
128
+ ChannelCreation creation = channelId2Creation .get (channelId ( channel ) );
125
129
return creation != null && now - creation .creationTime >= maxConnectionTTL ;
126
130
}
127
131
@@ -213,7 +217,7 @@ public void run(Timeout timeout) throws Exception {
213
217
214
218
if (!closedChannels .isEmpty ()) {
215
219
for (IdleChannel closedChannel : closedChannels )
216
- channel2Creation .remove (closedChannel .channel );
220
+ channelId2Creation .remove (channelId ( closedChannel .channel ) );
217
221
218
222
partition .removeAll (closedChannels );
219
223
closedCount += closedChannels .size ();
@@ -258,7 +262,7 @@ public boolean offer(Channel channel, String partitionId) {
258
262
259
263
boolean added = getPartition (partitionId ).add (new IdleChannel (channel , now ));
260
264
if (added )
261
- channel2Creation .putIfAbsent (channel , new ChannelCreation (now , partitionId ));
265
+ channelId2Creation .putIfAbsent (channelId ( channel ) , new ChannelCreation (now , partitionId ));
262
266
263
267
return added ;
264
268
}
@@ -292,7 +296,7 @@ else if (isRemotelyClosed(idleChannel.channel)) {
292
296
* {@inheritDoc}
293
297
*/
294
298
public boolean removeAll (Channel channel ) {
295
- ChannelCreation creation = channel2Creation .remove (channel );
299
+ ChannelCreation creation = channelId2Creation .remove (channelId ( channel ) );
296
300
return !isClosed .get () && creation != null && partitions .get (creation .partition ).remove (channel );
297
301
}
298
302
@@ -316,13 +320,13 @@ public void destroy() {
316
320
}
317
321
318
322
partitions .clear ();
319
- channel2Creation .clear ();
323
+ channelId2Creation .clear ();
320
324
}
321
325
322
326
private void close (Channel channel ) {
323
327
// FIXME pity to have to do this here
324
328
Channels .setDiscard (channel );
325
- channel2Creation .remove (channel );
329
+ channelId2Creation .remove (channelId ( channel ) );
326
330
Channels .silentlyCloseChannel (channel );
327
331
}
328
332
0 commit comments