Skip to content

Commit 41d7862

Browse files
committed
Stop using Netty's internal ConcurrentHashMapV8
1 parent 09ec427 commit 41d7862

File tree

1 file changed

+4
-20
lines changed

1 file changed

+4
-20
lines changed

client/src/main/java/org/asynchttpclient/netty/channel/ChannelManager.java

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@
3535
import io.netty.util.Timer;
3636
import io.netty.util.concurrent.DefaultThreadFactory;
3737
import io.netty.util.concurrent.GenericFutureListener;
38-
import io.netty.util.internal.chmv8.ConcurrentHashMapV8;
3938

4039
import java.io.IOException;
4140
import java.util.Map.Entry;
41+
import java.util.concurrent.ConcurrentHashMap;
4242
import java.util.concurrent.Semaphore;
4343
import java.util.concurrent.ThreadFactory;
4444
import java.util.concurrent.TimeUnit;
@@ -100,9 +100,8 @@ public class ChannelManager {
100100
private final Semaphore freeChannels;
101101
private final ChannelGroup openChannels;
102102
private final boolean maxConnectionsPerHostEnabled;
103-
private final ConcurrentHashMapV8<Object, Semaphore> freeChannelsPerHost;
104-
private final ConcurrentHashMapV8<Channel, Object> channelId2PartitionKey;
105-
private final ConcurrentHashMapV8.Fun<Object, Semaphore> semaphoreComputer;
103+
private final ConcurrentHashMap<Object, Semaphore> freeChannelsPerHost = new ConcurrentHashMap<>();
104+
private final ConcurrentHashMap<Channel, Object> channelId2PartitionKey = new ConcurrentHashMap<>();
106105

107106
private AsyncHttpClientHandler wsHandler;
108107

@@ -156,21 +155,6 @@ public boolean remove(Object o) {
156155
freeChannels = null;
157156
}
158157

159-
if (maxConnectionsPerHostEnabled) {
160-
freeChannelsPerHost = new ConcurrentHashMapV8<>();
161-
channelId2PartitionKey = new ConcurrentHashMapV8<>();
162-
semaphoreComputer = new ConcurrentHashMapV8.Fun<Object, Semaphore>() {
163-
@Override
164-
public Semaphore apply(Object partitionKey) {
165-
return new Semaphore(config.getMaxConnectionsPerHost());
166-
}
167-
};
168-
} else {
169-
freeChannelsPerHost = null;
170-
channelId2PartitionKey = null;
171-
semaphoreComputer = null;
172-
}
173-
174158
handshakeTimeout = config.getHandshakeTimeout();
175159

176160
// check if external EventLoopGroup is defined
@@ -317,7 +301,7 @@ private boolean tryAcquireGlobal() {
317301
}
318302

319303
private Semaphore getFreeConnectionsForHost(Object partitionKey) {
320-
return freeChannelsPerHost.computeIfAbsent(partitionKey, semaphoreComputer);
304+
return freeChannelsPerHost.computeIfAbsent(partitionKey, pk -> new Semaphore(config.getMaxConnectionsPerHost()));
321305
}
322306

323307
private boolean tryAcquirePerHost(Object partitionKey) {

0 commit comments

Comments
 (0)