About SimpleChannelHandler.channelDisconnected

tsuna tsunanet at gmail.com
Wed Nov 3 14:54:21 EDT 2010


On Wed, Nov 3, 2010 at 11:27 AM, Clement Mathieu
<clement.mathieu at activeeon.com> wrote:
> How can I distinguish theses two events in a SimpleChannelHandler:
>  - The remote peer closed the connection (or connection broken or whatever)
>  - My code invoked Channel.close()
>
> Basically I want to perform an action if and only if the connection is
> lost. I don't want to do it if I'm closing the connection from my
> side. I thought that channelDisconnected will do the job, but the
> method is also called when Channel.close() is invoked.

When the channel gets disconnected, you will get an upstream event (a
ChannelStateEvent) informing you about the disconnection.

When you disconnect the channel yourself (by calling
Channels.close()), you will generate a downstream event, which will
disconnect the socket.  Once the socket gets disconnected, you'll get
an upstream event (the same as you'd get in the previous case).

That's how you can distinguish between the two.

-- 
Benoit "tsuna" Sigoure
Software Engineer @ www.StumbleUpon.com



More information about the netty-users mailing list