hg: nio/nio/jdk: First installation of potential updates for M4
Alan Bateman
Alan.Bateman at Sun.COM
Thu May 14 06:39:07 PDT 2009
libman at terabit.com.au wrote:
> Alan,
> couple questions about latest changes in API:
> 1) what distribution should I use it ?
> currently, I am working with b99
>
b99 was the last snapshot release before pushing to jdk7. Since then all
the fixes have been pushed to jdk7 so the latest binaries are jdk7 b58.
As we have API changes in progress then I will make a snapshot release
available very soon (hopefully within a few days).
> 2) CompletionHandler
> does not support cancelled() callback.
>
> Can I assume for my the filter futures that the following
> behavior would be enough :
>
> Future.cancel(boolean mayInterruptIfRunning)
> {
> if (mayInterruptIfRunning) {
> associatedChannel.close();
> }
> else {
> // ignore cancel
> }
> }
>
> This will simplify a lot as no longer need to provide in filters
> methods like onCancelFuture().
>
>
> 3) AsynchronousByteChannel signature of methods have been changed:
> <A> void read(ByteBuffer dst,
> A attachment,
> CompletionHandler<Integer,? super A> handler);
>
> Future<Integer> read(ByteBuffer dst);
>
> It is good - no longer needed to create future (even on demand) for the
> first form. And for the first form no way to cancel operation. So
> I assume that cancel() makes sense only with parameter mayInterrupt = true.
> In other words we can always interpret Future.cancel() as indirect form of
> AsynchronousChannel.close()
>
Future#cancel is hard to get right, as I learned the hard way :-)
The main thing to know is that cancel needs to return true irrespective
of the value of the mayInterruptIfRunning parameter (assuming the I/O
operation hasn't completed or hasn't been cancelled of course, in which
case it will return false). You also need to make sure that subsequent
calls to isDone return true and any calls to get throw CancelledException.
-Alan.
More information about the nio-dev
mailing list