Client disconnect

matthias.s. matthias.scudlik at pangora.com
Thu May 7 04:43:10 EDT 2009


Hi Christian,

you really helped me and it works now - thanks a lot :)

You helped me to understand how netty works, the only thing i'm not sure
about
is how to get a ChannelHandlerContext outside the predefined methods - do i
have to set a field on connection? but it should not be the same context
everytime.

I figured out that understanding netty is not that simple but at least it
works for now.
I'm still experimenting and probably have some more questions in the future.

In the meantime i want to thankl the great community and trustin for his
good work :)


------------------------------

This is how i solved my problem

my send method looks like this:

   public <T> void send( T object ) {
      ChannelFuture lastFuture = getChannelFuture();
      Channel channel = lastFuture.getChannel();
      ChannelFuture currentFuture = null;
      if ( lastFuture.isSuccess() ) {
         currentFuture = channel.write(object);
      }
      if ( currentFuture != null ) {
         currentFuture.awaitUninterruptibly();
         setChannelFuture(currentFuture);
      }
   }

and disconnecting is simple:

   public void disconnect() {
      _logger.info("disconnecting from " + _remoteAddress + " ...");
      ChannelFuture channelFuture = getChannelFuture();
      Channel channel = channelFuture.getChannel();
      channelFuture.addListener(ChannelFutureListener.CLOSE);
      if ( channelFuture.isSuccess() ) {
         channelFuture = Channels.disconnect(channel);
      }
      if ( channelFuture.isSuccess() ) {
         Channels.unbind(channel);
      }
      try {
         _clientThreadPool.shutdown();
         _clientThreadPool.awaitTermination(10, TimeUnit.SECONDS);
         _workerThreadPool.shutdown();
         _workerThreadPool.awaitTermination(10, TimeUnit.SECONDS);
      }
      catch ( InterruptedException e ) {
         //ignore
      }
      _logger.info(_remoteAddress + " disconnected");
   }
-- 
View this message in context: http://n2.nabble.com/Client-disconnect-tp2798147p2826769.html
Sent from the Netty User Group mailing list archive at Nabble.com.




More information about the netty-users mailing list