Client disconnect

matthias.s. matthias.scudlik at pangora.com
Wed May 6 04:13:33 EDT 2009


Thanks Fredeeric, that's gonna help me.

I tried using OrderedMemoryAwareThreadPoolExecutor in combination with your
counter proposal. I added the Counter like this:


   @Override
   public void writeRequested( ChannelHandlerContext ctx, MessageEvent e )
throws Exception {
      super.writeRequested(ctx, e);
      _writeRequests.incrementAndGet();
   }

   @Override
   public void writeComplete( ChannelHandlerContext ctx,
WriteCompletionEvent e ) throws Exception {
      super.writeComplete(ctx, e);
      _writeRequests.decrementAndGet();
   }


and in my new disconnect method i start a new Thread waiting for the counter
to get back to zero.

   public void disconnect() {
      _logger.info("disconnecting...");
      new Thread() {

         @Override
         public void run() {
            while ( true ) {
               if ( _writeRequests.get() == 0 ) {
                 
getChannelFuture().addListener(ChannelFutureListener.CLOSE);
                  _logger.info("disconnected");
                  return;
               } else {
                  try {
                     sleep(1000);
                  }
                  catch ( InterruptedException e ) {}
               }
            }
         }

      }.start();
   }


Unfortunately the value never does and gets stuck by 99334.
Threading issues should not occur, i used an AtomicLong to count the
requests

   private volatile AtomicLong _writeRequests = new AtomicLong(0);

It's kind of weird...

The client just prints out

2009.05.06 10:02:15 INFO : disconnecting... 

and the debugger told me the value is 99334
-- 
View this message in context: http://n2.nabble.com/Client-disconnect-tp2798147p2809143.html
Sent from the Netty User Group mailing list archive at Nabble.com.




More information about the netty-users mailing list