Created
October 22, 2012 09:56
-
-
Save kjunine/3930712 to your computer and use it in GitHub Desktop.
Using ChannelGroup to close all connected channel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Override | |
| public void channelConnected(ChannelHandlerContext ctx, | |
| ChannelStateEvent e) throws Exception { | |
| this.channel = e.getChannel(); | |
| channels.add(channel); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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