Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit672160b

Browse files
stepanchegslandelle
authored andcommitted
Store partition key in Channel attribute instead of global hash map (AsyncHttpClient#1373)
1 parent82154f1 commit672160b

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
importio.netty.handler.logging.LoggingHandler;
3636
importio.netty.handler.ssl.SslHandler;
3737
importio.netty.handler.stream.ChunkedWriteHandler;
38+
importio.netty.util.AttributeKey;
3839
importio.netty.util.Timer;
3940
importio.netty.util.concurrent.DefaultThreadFactory;
4041
importio.netty.util.concurrent.GlobalEventExecutor;
@@ -87,6 +88,8 @@ public class ChannelManager {
8788
publicstaticfinalStringAHC_WS_HANDLER ="ahc-ws";
8889
publicstaticfinalStringLOGGING_HANDLER ="logging";
8990

91+
privatestaticfinalAttributeKey<Object>partitionKeyAttr =AttributeKey.valueOf("partitionKey");
92+
9093
privatefinalAsyncHttpClientConfigconfig;
9194
privatefinalSslEngineFactorysslEngineFactory;
9295
privatefinalEventLoopGroupeventLoopGroup;
@@ -99,7 +102,6 @@ public class ChannelManager {
99102

100103
privatefinalChannelPoolchannelPool;
101104
privatefinalChannelGroupopenChannels;
102-
privatefinalConcurrentHashMap<Channel,Object>channelId2PartitionKey =newConcurrentHashMap<>();
103105
privatefinalbooleanmaxTotalConnectionsEnabled;
104106
privatefinalSemaphorefreeChannels;
105107
privatefinalbooleanmaxConnectionsPerHostEnabled;
@@ -141,7 +143,7 @@ public boolean remove(Object o) {
141143
if (maxTotalConnectionsEnabled)
142144
freeChannels.release();
143145
if (maxConnectionsPerHostEnabled) {
144-
ObjectpartitionKey =channelId2PartitionKey.remove(Channel.class.cast(o));
146+
ObjectpartitionKey =Channel.class.cast(o).attr(partitionKeyAttr).getAndSet(null);
145147
if (partitionKey !=null) {
146148
SemaphorehostFreeChannels =freeChannelsPerHost.get(partitionKey);
147149
if (hostFreeChannels !=null)
@@ -308,7 +310,7 @@ public final void tryToOfferChannelToPool(Channel channel, AsyncHandler<?> async
308310
AsyncHandlerExtensions.class.cast(asyncHandler).onConnectionOffer(channel);
309311
if (channelPool.offer(channel,partitionKey)) {
310312
if (maxConnectionsPerHostEnabled)
311-
channelId2PartitionKey.putIfAbsent(channel,partitionKey);
313+
channel.attr(partitionKeyAttr).setIfAbsent(partitionKey);
312314
}else {
313315
// rejected by pool
314316
closeChannel(channel);
@@ -383,7 +385,7 @@ public void releaseChannelLock(Object partitionKey) {
383385
publicvoidregisterOpenChannel(Channelchannel,ObjectpartitionKey) {
384386
openChannels.add(channel);
385387
if (maxConnectionsPerHostEnabled) {
386-
channelId2PartitionKey.put(channel,partitionKey);
388+
channel.attr(partitionKeyAttr).set(partitionKey);
387389
}
388390
}
389391

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp