Skip to content

Instantly share code, notes, and snippets.

@kjunine
Created October 22, 2012 09:56
Show Gist options
  • Select an option

  • Save kjunine/3930712 to your computer and use it in GitHub Desktop.

Select an option

Save kjunine/3930712 to your computer and use it in GitHub Desktop.
Using ChannelGroup to close all connected channel
@Override
public void channelConnected(ChannelHandlerContext ctx,
ChannelStateEvent e) throws Exception {
this.channel = e.getChannel();
channels.add(channel);
}
private Channel channel;
private ChannelGroup channels;
public void start() {
this.channel = bootstrap.bind(localAddress);
this.channels = new DefaultChannelGroup();
channels.add(channel);
}
public void stop() {
channels.close().awaitUninterruptibly();
bootstrap.releaseExternalResources();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment