users@grizzly.java.net

Re: [ANN] Getting notified when client or server close the connection.

From: Jeanfrancois Arcand <Jeanfrancois.Arcand_at_Sun.COM>
Date: Tue, 25 Nov 2008 10:25:09 -0500

Salut,

Survivant 00 wrote:
> I reopen the bug, but not sure if I did it correctly.
>
> here what I have.
>
>
> tcpSelectorHandler.setSelectionKeyHandler(new BaseSelectionKeyHandler(){
>
> public void locallyClosed(SelectionKey key) {
> s_logger.debug(key + " is being locally cancelled");
> }
>
> public void remotlyClosed(SelectionKey key) {
> s_logger.debug(key + " is being remotly cancelled
> (connection closed)");
> }
> });
>
> f_controller.addSelectorHandler(tcpSelectorHandler);
>
> if I open a telnet connection and close it, I won't be notify.
>
> but I didn't use ConnectionCloseHandler.
>
> Can I mix the 2 handlers ?

You need to create an instance of ConnectionCloseHandler and pass it to

(1) Create the SelectionKeyHandler

> SelectionKeyHandler skh = new DefaultSelectionKeyHandler();

(2) Create an instance of ConnectionCloseHeader:

> shk.setConnectionCloseHandler(new ConnectionCloseHandler() {
>
> public void locallyClosed(SelectionKey key) {
> logger.info <http://logger.info>(key + " is being locally
> cancelled");
> }
>
> public void remotlyClosed(SelectionKey key) {
> logger.fine(key + " is being remotly cancelled (connection
> closed)");
> }
> });
>

(3) Set it on the Controller or SelectorHandler

> controller.setSelectionKeyHandler(skh);


In your code snippet, you don't create the ConnectionCloseHandler...

A+

-- Jeanfrancois


>
>
>
>
> 2008/11/24 Jeanfrancois Arcand <Jeanfrancois.Arcand_at_sun.com
> <mailto:Jeanfrancois.Arcand_at_sun.com>>
>
> Salut,
>
> I've added a new Handler for managing local and remote connection
> close. The new ConnectionCloseHandler[1] can be configured on any
> class that extends our BaseSelectionKeyHandler (like
> DefaultSelectionKeyHandler):
>
> SelectionKeyHandler skh = new DefaultSelectionKeyHandler();
> shk.setConnectionCloseHandler(new ConnectionCloseHandler() {
>
> public void locallyClosed(SelectionKey key) {
> logger.info <http://logger.info>(key + " is being locally
> cancelled");
> }
>
> public void remotlyClosed(SelectionKey key) {
> logger.fine(key + " is being remotly cancelled (connection
> closed)");
> }
> });
>
> controller.setSelectionKeyHandler(skh);
>
> Those two methods gets invoked when any of the following condition
> happens:
>
> 1. Any IOException occurs on I/O operations (read/write)
> 2. When the read() or write() operation return -1
>
> Please try it :-)
>
> A+
>
> -- Jeanfrancois
>
> [1]
> https://grizzly.dev.java.net/nonav/apidocs/com/sun/grizzly/util/ConnectionCloseHandler.html
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_grizzly.dev.java.net
> <mailto:users-unsubscribe_at_grizzly.dev.java.net>
> For additional commands, e-mail: users-help_at_grizzly.dev.java.net
> <mailto:users-help_at_grizzly.dev.java.net>
>
>