Right way to shutdown in case of error
float_dublin
Kostya.Hvan at gmail.com
Mon Sep 14 07:12:55 EDT 2009
OK, I am using ChannelGroups this time still with no success. No channel gets
into Channelgroup in case of "Connection refused". Examining ClientBootstrap
gives no clue :( Application still hangs. So is a new thread for shuting
down the only solution?
Code:
public class ClientTest {
@ChannelPipelineCoverage("all")
private class Client extends SimpleChannelHandler {
@Override
public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent
e) throws Exception {
group.add(e.getChannel());
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, final
ExceptionEvent e) throws Exception {
e.getCause().printStackTrace();
System.out.println("Channels in group: " + group.size());
group.close().addListener(new ChannelGroupFutureListener() {
public void operationComplete(ChannelGroupFuture future)
throws Exception {
bootstrap.releaseExternalResources();
}
});
}
}
final ClientBootstrap bootstrap = new ClientBootstrap(new
NioClientSocketChannelFactory(
Executors.newCachedThreadPool(),
Executors.newCachedThreadPool()));
final ChannelGroup group = new DefaultChannelGroup();
private void initClient() {
bootstrap.setOption("tcpNoDelay", true);
bootstrap.setOption("keepAlive", true);
final ChannelPipeline pipeline = bootstrap.getPipeline();
pipeline.addLast("handler", new Client());
group.add(bootstrap.connect(new InetSocketAddress("localhost",
20001)).getChannel());
}
public static void main(String[] args) {
new ClientTest().initClient();
}
}
--
View this message in context: http://n2.nabble.com/Right-way-to-shutdown-in-case-of-error-tp3637599p3641407.html
Sent from the Netty User Group mailing list archive at Nabble.com.
More information about the netty-users
mailing list