CompletionHandler should take the channel too

Alan Bateman Alan.Bateman at Sun.COM
Wed Apr 22 00:23:13 PDT 2009


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.



More information about the nio-dev mailing list