- NEVER DO THIS public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) { if (e.getMessage() instanceof ShutdownMessage) { ChannelGroup allChannels = MyServer.getAllChannels(); ChannelGroupFuture future = allChannels.close(); future.awaitUninterruptibly(); // Perform post-shutdown operation // ... } } // GOOD public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) { if (e.getMessage() instanceof ShutdownMessage) { ChannelGroup allChannels = MyServer.getAllChannels(); ChannelGroupFuture future = allChannels.close(); future.addListener(new ChannelGroupFutureListener() { public void operationComplete(ChannelGroupFuture future) { // Perform post-closure operation // ... } }); } }
In spite of the disadvantages mentioned above, there are certainly the cases where it is more convenient to call {@link #await()}. In such a case, please make sure you do not call {@link #await()} in an I/O thread. Otherwise,{@link IllegalStateException} will be raised to prevent a dead lock.
@author The Netty Project (netty-dev@lists.jboss.org)
@author Trustin Lee (tlee@redhat.com)
@version $Rev: 1262 $, $Date: 2009-04-28 22:35:55 +0900 (Tue, 28 Apr 2009) $
@apiviz.owns org.jboss.netty.channel.group.ChannelGroupFutureListener - - notifies