Skip to content

Commit 7a80b2a

Browse files
committed
minor clean up: rename channelPreempted into acquireChannelLock
1 parent 46f5553 commit 7a80b2a

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,12 @@ public class ChannelManager {
9898
private final IOException tooManyConnectionsPerHost;
9999

100100
private final ChannelPool channelPool;
101+
private final ChannelGroup openChannels;
102+
private final ConcurrentHashMap<Channel, Object> channelId2PartitionKey = new ConcurrentHashMap<>();
101103
private final boolean maxTotalConnectionsEnabled;
102104
private final Semaphore freeChannels;
103-
private final ChannelGroup openChannels;
104105
private final boolean maxConnectionsPerHostEnabled;
105106
private final ConcurrentHashMap<Object, Semaphore> freeChannelsPerHost = new ConcurrentHashMap<>();
106-
private final ConcurrentHashMap<Channel, Object> channelId2PartitionKey = new ConcurrentHashMap<>();
107107

108108
private AsyncHttpClientHandler wsHandler;
109109

@@ -340,7 +340,7 @@ private boolean tryAcquirePerHost(Object partitionKey) {
340340
return !maxConnectionsPerHostEnabled || getFreeConnectionsForHost(partitionKey).tryAcquire();
341341
}
342342

343-
public void preemptChannel(Object partitionKey) throws IOException {
343+
public void acquireChannelLock(Object partitionKey) throws IOException {
344344
if (!channelPool.isOpen())
345345
throw PoolAlreadyClosedException.INSTANCE;
346346
if (!tryAcquireGlobal())
@@ -373,7 +373,7 @@ public void closeChannel(Channel channel) {
373373
Channels.silentlyCloseChannel(channel);
374374
}
375375

376-
public void abortChannelPreemption(Object partitionKey) {
376+
public void releaseChannelLock(Object partitionKey) {
377377
if (maxTotalConnectionsEnabled)
378378
freeChannels.release();
379379
if (maxConnectionsPerHostEnabled)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public NettyConnectListener(NettyResponseFuture<T> future,//
6060

6161
public void abortChannelPreemption(Channel channel) {
6262
if (channelPreempted) {
63-
channelManager.abortChannelPreemption(partitionKey);
63+
channelManager.releaseChannelLock(partitionKey);
6464
}
6565

6666
Channels.silentlyCloseChannel(channel);

client/src/main/java/org/asynchttpclient/netty/request/NettyRequestSender.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -263,14 +263,14 @@ private <T> ListenableFuture<T> sendRequestWithNewChannel(//
263263
Object partitionKey = future.getPartitionKey();
264264

265265
// we disable channelPreemption when performing next requests
266-
final boolean channelPreempted = !performingNextRequest;
266+
final boolean acquireChannelLock = !performingNextRequest;
267267

268268
try {
269269
// Do not throw an exception when we need an extra connection for a
270270
// redirect.
271-
if (channelPreempted) {
271+
if (acquireChannelLock) {
272272
// if there's an exception here, channel wasn't preempted and resolve won't happen
273-
channelManager.preemptChannel(partitionKey);
273+
channelManager.acquireChannelLock(partitionKey);
274274
}
275275
} catch (Throwable t) {
276276
abort(null, future, getCause(t));
@@ -285,19 +285,19 @@ private <T> ListenableFuture<T> sendRequestWithNewChannel(//
285285

286286
@Override
287287
protected void onSuccess(List<InetSocketAddress> addresses) {
288-
NettyConnectListener<T> connectListener = new NettyConnectListener<>(future, NettyRequestSender.this, channelManager, channelPreempted, partitionKey);
288+
NettyConnectListener<T> connectListener = new NettyConnectListener<>(future, NettyRequestSender.this, channelManager, acquireChannelLock, partitionKey);
289289
NettyChannelConnector connector = new NettyChannelConnector(request.getLocalAddress(), addresses, asyncHandler, clientState, config);
290290
if (!future.isDone()) {
291291
connector.connect(bootstrap, connectListener);
292-
} else if (channelPreempted) {
293-
channelManager.abortChannelPreemption(partitionKey);
292+
} else if (acquireChannelLock) {
293+
channelManager.releaseChannelLock(partitionKey);
294294
}
295295
}
296296

297297
@Override
298298
protected void onFailure(Throwable cause) {
299-
if (channelPreempted) {
300-
channelManager.abortChannelPreemption(partitionKey);
299+
if (acquireChannelLock) {
300+
channelManager.releaseChannelLock(partitionKey);
301301
}
302302
abort(null, future, getCause(cause));
303303
}

0 commit comments

Comments
 (0)