CompletionHandler should take the channel too

Rémi Forax forax at univ-mlv.fr
Wed Apr 22 15:18:16 PDT 2009


Alan Bateman a écrit :
> Rémi Forax wrote:
>> Hi Alan, hi all,
>> Writing a stateless completion handler as suggested in the doc is not
>> that easy because the completion handler doesn't provide a way to get
>> the async channel on which the async operation was called.
> When consuming the result you will typically need the channel, 
> buffer(s), SSLSession and maybe other context. This is the reason for 
> the attachment object so that you can attach arbitrary context 
> (including the channel) to the I/O operation and have it available 
> when consuming the result. So while I agree it is important to have a 
> reference to the channel, it isn't sufficient. If there are cases 
> where the channel is the only context required then you can make the 
> channel available as the attachment object.
>
> -Alan.

I don't see why I have to create an ephemeral object to store a channel 
and a buffer
if the implementation already have this information but don't export it.

Else, there is no way to find the group from an async socket channel,
something like:
asyncSocketChannel().group().shutdown();
should be useful.

Rémi




More information about the nio-dev mailing list