Skip to content

Commit 68f811c

Browse files
committed
Use the Channel random hashcode as id...
1 parent ebf2ef4 commit 68f811c

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/channel/pool/DefaultChannelPool.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public final class DefaultChannelPool implements ChannelPool {
4444
private static final Logger LOGGER = LoggerFactory.getLogger(DefaultChannelPool.class);
4545

4646
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<>();
4848
private final AtomicBoolean isClosed = new AtomicBoolean(false);
4949
private final Timer nettyTimer;
5050
private final boolean sslConnectionPoolEnabled;
@@ -61,6 +61,10 @@ public DefaultChannelPool(AsyncHttpClientConfig config, Timer hashedWheelTimer)
6161
hashedWheelTimer);
6262
}
6363

64+
private int channelId(Channel channel) {
65+
return channel.hashCode();
66+
}
67+
6468
public DefaultChannelPool(
6569
long maxIdleTime,//
6670
int maxConnectionTTL,//
@@ -121,7 +125,7 @@ private boolean isTTLExpired(Channel channel, long now) {
121125
if (maxConnectionTTLDisabled)
122126
return false;
123127

124-
ChannelCreation creation = channel2Creation.get(channel);
128+
ChannelCreation creation = channelId2Creation.get(channelId(channel));
125129
return creation != null && now - creation.creationTime >= maxConnectionTTL;
126130
}
127131

@@ -213,7 +217,7 @@ public void run(Timeout timeout) throws Exception {
213217

214218
if (!closedChannels.isEmpty()) {
215219
for (IdleChannel closedChannel : closedChannels)
216-
channel2Creation.remove(closedChannel.channel);
220+
channelId2Creation.remove(channelId(closedChannel.channel));
217221

218222
partition.removeAll(closedChannels);
219223
closedCount += closedChannels.size();
@@ -258,7 +262,7 @@ public boolean offer(Channel channel, String partitionId) {
258262

259263
boolean added = getPartition(partitionId).add(new IdleChannel(channel, now));
260264
if (added)
261-
channel2Creation.putIfAbsent(channel, new ChannelCreation(now, partitionId));
265+
channelId2Creation.putIfAbsent(channelId(channel), new ChannelCreation(now, partitionId));
262266

263267
return added;
264268
}
@@ -292,7 +296,7 @@ else if (isRemotelyClosed(idleChannel.channel)) {
292296
* {@inheritDoc}
293297
*/
294298
public boolean removeAll(Channel channel) {
295-
ChannelCreation creation = channel2Creation.remove(channel);
299+
ChannelCreation creation = channelId2Creation.remove(channelId(channel));
296300
return !isClosed.get() && creation != null && partitions.get(creation.partition).remove(channel);
297301
}
298302

@@ -316,13 +320,13 @@ public void destroy() {
316320
}
317321

318322
partitions.clear();
319-
channel2Creation.clear();
323+
channelId2Creation.clear();
320324
}
321325

322326
private void close(Channel channel) {
323327
// FIXME pity to have to do this here
324328
Channels.setDiscard(channel);
325-
channel2Creation.remove(channel);
329+
channelId2Creation.remove(channelId(channel));
326330
Channels.silentlyCloseChannel(channel);
327331
}
328332

0 commit comments

Comments
 (0)