Client disconnect

Frederic Bregier fredbregier at free.fr
Tue May 5 15:23:56 EDT 2009


Hi Matthias,

I think what you see is normal. Asynchronous operation (like write or close)
can take effect immediately or later on. And there is an order for write
operation (all write will be in order, not necesseraly receive) but other
operations like close (I don't know if another one can exist) has most
likely the chance to occur before the end of the last write.

There is a way to do as you want however:

1) For your last write operation, you might use a await() on the future. But
take care of the following: it is only valid to use await() if it is not an
IO thread, that is to say you have a OrderedMemoryAwareThreadPoolExecutor in
your pipeline.

2) If this is an IO thread (no ThreadPoolExecutor in your pipeline) then you
have to implement your own ChannelFutureListener (or the predefined CLOSE
one) that could do your close operation.

So for instance, what you could do can look like this:

client.connect();

// 100 000 times
for( int i = 0; i < 100000; i++) {
// I would suggest you to get the channel from the standard way of netty 
// from the handler arguments like ChannelHandlerContext ctxt.getChannel()
   channel.write(foo);
}

//Then your last write will close the channel on completion.
channel.write("done").addListener(ChannelFutureListener.CLOSE);

In fact, you place the wait or FutureListener on the bad operation. It is
not on the close but on the last write that you have to wait before closing.
You were almost there... ;-)

There could be other ways, more on business approach (using a counter for
instance that increases on write request and decreases on writeComplete),
then it is up to you...

HTH,
Frederic


-----
Hardware/Software Architect
-- 
View this message in context: http://n2.nabble.com/Client-disconnect-tp2798147p2803754.html
Sent from the Netty User Group mailing list archive at Nabble.com.




More information about the netty-users mailing list