Skip to content

Commit b72bbbf

Browse files
committed
minor clean up
1 parent 4105955 commit b72bbbf

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

src/main/java/com/ning/http/client/providers/netty/channel/ChannelManager.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ public class ChannelManager {
9393
private final boolean maxConnectionsPerHostEnabled;
9494
private final ConcurrentHashMapV8<Object, Semaphore> freeChannelsPerHost;
9595
private final ConcurrentHashMapV8<Integer, Object> channelId2PartitionKey;
96+
private final ConcurrentHashMapV8.Fun<Object, Semaphore> semaphoreComputer;
9697
private final long handshakeTimeout;
9798
private final Timer nettyTimer;
9899
private final IOException tooManyConnections;
@@ -108,7 +109,7 @@ public class ChannelManager {
108109

109110
private Processor wsProcessor;
110111

111-
public ChannelManager(AsyncHttpClientConfig config, NettyAsyncHttpProviderConfig nettyConfig, Timer nettyTimer) {
112+
public ChannelManager(final AsyncHttpClientConfig config, NettyAsyncHttpProviderConfig nettyConfig, Timer nettyTimer) {
112113

113114
this.config = config;
114115
this.nettyConfig = nettyConfig;
@@ -157,9 +158,17 @@ public boolean remove(Object o) {
157158
if (maxConnectionsPerHostEnabled) {
158159
freeChannelsPerHost = new ConcurrentHashMapV8<>();
159160
channelId2PartitionKey = new ConcurrentHashMapV8<>();
161+
semaphoreComputer = new ConcurrentHashMapV8.Fun<Object, Semaphore>() {
162+
@Override
163+
public Semaphore apply(Object partitionKey) {
164+
return new Semaphore(config.getMaxConnectionsPerHost());
165+
}
166+
};
167+
160168
} else {
161169
freeChannelsPerHost = null;
162170
channelId2PartitionKey = null;
171+
semaphoreComputer = null;
163172
}
164173

165174
handshakeTimeout = nettyConfig.getHandshakeTimeout();
@@ -308,13 +317,6 @@ private boolean tryAcquireGlobal() {
308317
return !maxTotalConnectionsEnabled || freeChannels.tryAcquire();
309318
}
310319

311-
private final ConcurrentHashMapV8.Fun<Object, Semaphore> semaphoreComputer = new ConcurrentHashMapV8.Fun<Object, Semaphore>() {
312-
@Override
313-
public Semaphore apply(Object partitionKey) {
314-
return new Semaphore(config.getMaxConnectionsPerHost());
315-
}
316-
};
317-
318320
private Semaphore getFreeConnectionsForHost(Object partitionKey) {
319321
return freeChannelsPerHost.computeIfAbsent(partitionKey, semaphoreComputer);
320322
}

src/main/java/com/ning/http/client/providers/netty/request/NettyConnectListener.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public NettyResponseFuture<T> future() {
5858
return future;
5959
}
6060

61-
private void abortChannelPreemption(Object partitionKey) {
61+
private void abortChannelPreemption() {
6262
if (channelPreempted)
6363
channelManager.abortChannelPreemption(partitionKey);
6464
}
@@ -73,7 +73,7 @@ private void writeRequest(Channel channel) {
7373
Channels.setAttribute(channel, future);
7474

7575
if (future.isDone()) {
76-
abortChannelPreemption(partitionKey);
76+
abortChannelPreemption();
7777
return;
7878
}
7979

@@ -112,7 +112,7 @@ public void operationComplete(ChannelFuture handshakeFuture) throws Exception {
112112
}
113113

114114
private void onFutureFailure(Channel channel, Throwable cause) {
115-
abortChannelPreemption(partitionKey);
115+
abortChannelPreemption();
116116

117117
boolean canRetry = future.canRetry();
118118
LOGGER.debug("Trying to recover from failing to connect channel {} with a retry value of {} ", channel, canRetry);

0 commit comments

Comments
 (0)