Right way to shutdown in case of error

Michael McGrady mmcgrady at topiatechnology.com
Mon Sep 14 10:19:37 EDT 2009


Could you give the relevant code?  I suspect that you are not getting  
all channels into the group.

Mike

On Sep 14, 2009, at 4:12 AM, float_dublin wrote:

>
> 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.
> _______________________________________________
> netty-users mailing list
> netty-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/netty-users

Mike McGrady
Principal Investigator AF081-028 AFRL SBIR
Senior Engineer
Topia Technology, Inc
1.253.720.3365
mmcgrady at topiatechnology.com









More information about the netty-users mailing list