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 19:57:16 -0500

Salut,

Amy Kang wrote:
> Hi Jeanfrancois,
>
> In the ConnectionCloseHandler methods locallyClosed() and remotelyClosed(),
> will SelectionKey.attachment() guarantee to return the existing attachment
> that was set to through the AttributeHolder,
>
> ctx.getAttributeHolderByScope(Context.AttributeScope.CONNECTION);
>
> the attached object is what I need to do clean up on the server side for
> the connection.

Hum nice catch..it will works when the remotlyClosed is invoked, but
right now it will not work when the locallyClosed is invoked. The reason
is I wanted to make sure the SelectionKey and its associated Channel are
closed before invoking the handler.

Let me rework the implementation to make sure I support your use case.

Thanks for the feedback.

-- Jeanfrancois




>
> Thanks,
> amy
>
> On 11/24/08 19:00, Jeanfrancois Arcand wrote:
>> 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(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
>> For additional commands, e-mail: users-help_at_grizzly.dev.java.net
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_grizzly.dev.java.net
> For additional commands, e-mail: users-help_at_grizzly.dev.java.net
>