Skip to content

Commit 03ac5e1

Browse files
committed
Drop CleanupChannelGroup, close AsyncHttpClient#1176
1 parent c16f5cf commit 03ac5e1

File tree

2 files changed

+6
-119
lines changed

2 files changed

+6
-119
lines changed

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

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import io.netty.channel.ChannelPipeline;
2424
import io.netty.channel.EventLoopGroup;
2525
import io.netty.channel.group.ChannelGroup;
26+
import io.netty.channel.group.DefaultChannelGroup;
2627
import io.netty.channel.nio.NioEventLoopGroup;
2728
import io.netty.channel.oio.OioEventLoopGroup;
2829
import io.netty.channel.socket.nio.NioSocketChannel;
@@ -39,6 +40,7 @@
3940
import io.netty.util.concurrent.DefaultThreadFactory;
4041
import io.netty.util.concurrent.Future;
4142
import io.netty.util.concurrent.FutureListener;
43+
import io.netty.util.concurrent.GlobalEventExecutor;
4244

4345
import java.io.IOException;
4446
import java.util.Map.Entry;
@@ -133,7 +135,7 @@ public ChannelManager(final AsyncHttpClientConfig config, Timer nettyTimer) {
133135
maxConnectionsPerHostEnabled = config.getMaxConnectionsPerHost() > 0;
134136

135137
if (maxTotalConnectionsEnabled || maxConnectionsPerHostEnabled) {
136-
openChannels = new CleanupChannelGroup("asyncHttpClient") {
138+
openChannels = new DefaultChannelGroup("asyncHttpClient", GlobalEventExecutor.INSTANCE) {
137139
@Override
138140
public boolean remove(Object o) {
139141
boolean removed = super.remove(o);
@@ -154,7 +156,7 @@ public boolean remove(Object o) {
154156
};
155157
freeChannels = new Semaphore(config.getMaxConnections());
156158
} else {
157-
openChannels = new CleanupChannelGroup("asyncHttpClient");
159+
openChannels = new DefaultChannelGroup("asyncHttpClient", GlobalEventExecutor.INSTANCE);
158160
freeChannels = null;
159161
}
160162

@@ -354,31 +356,18 @@ public void preemptChannel(Object partitionKey) throws IOException {
354356
}
355357
}
356358

357-
private void doClose() {
358-
channelPool.destroy();
359-
openChannels.close();
360-
361-
for (Channel channel : openChannels) {
362-
Object attribute = Channels.getAttribute(channel);
363-
if (attribute instanceof NettyResponseFuture<?>) {
364-
NettyResponseFuture<?> nettyFuture = (NettyResponseFuture<?>) attribute;
365-
nettyFuture.cancelTimeouts();
366-
}
367-
}
368-
}
369-
370359
@SuppressWarnings({ "unchecked", "rawtypes" })
371360
public void close() {
372361
if (allowReleaseEventLoopGroup) {
373362
eventLoopGroup.shutdownGracefully(config.getShutdownQuietPeriod(), config.getShutdownTimeout(), TimeUnit.MILLISECONDS)//
374363
.addListener(new FutureListener() {
375364
@Override
376365
public void operationComplete(Future future) throws Exception {
377-
doClose();
366+
openChannels.close();
378367
}
379368
});
380369
} else
381-
doClose();
370+
openChannels.close();
382371
}
383372

384373
public void closeChannel(Channel channel) {
@@ -387,7 +376,6 @@ public void closeChannel(Channel channel) {
387376
Channels.setDiscard(channel);
388377
removeAll(channel);
389378
Channels.silentlyCloseChannel(channel);
390-
openChannels.remove(channel);
391379
}
392380

393381
public void abortChannelPreemption(Object partitionKey) {

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

Lines changed: 0 additions & 101 deletions
This file was deleted.

0 commit comments

Comments
 (0)