Async channels

Rémi Forax forax at univ-mlv.fr
Sun Apr 19 16:50:38 PDT 2009


Hi Alan, hi all,
I have some questions about channels and their implementations.
(I use the jdk7 workspace so sorry if it's already fixed).

1) Why SocketChannel.getRemoteAddress()/Async...Channel.getRemoteAddress()
    and Socket.getSocketRemoteAddress() doesn't have the same semantics ?

   getSocketRemoteAddress() returns the remote address even
   if the connection is closed,
   getRemoteAddress() throws a IOException in that case.

2) In the doc of AsynchronousChannel there is a small typo:
    <li><pre>Future&lt;V&gt; <em>operation</em>(<em>...</em> A attachment,
    {@link CompletionHandler}&lt;V,? super A&gt handler)</pre></li>
    should be
    <li><pre>Future&lt;V&gt; <em>operation</em>(<em>...</em> A attachment,
    {@link CompletionHandler}&lt;V,? super A&gt; handler)</pre></li>
                             a semicolon is missing here   -----^

3) The doc of AsynchronousChannel is not crystal clear for methods
     read() or write() that doesn't take a completion handler
     in case of IOException.

     "In the first form, the methods defined by the {@link Future Future}
      interface may be used to check if the operation has completed, 
wait for its
      completion, and to retrieve the result."

     Is future.get() will throw a ExecutionException that will wrap the 
corresponding
     IOException ?

4) Why CompletionHandler.failed() take a Throwable and not a IOException ?

5) As specified in the doc of AsynchronousChannel about cancelation,
    "further attempts to initiate a {@code read} operation causes an
      unspecified runtime exception to be thrown".
   Why a runtime exception and not a call to the completion handler ?

6) Is it possible to rename all Asynchronous* to Async*.
    I will *really* increase the readability of the types.

7) UnixAsynchronousSocketChannelImpl.onCancel() seems to have a 
copy&paste bug:

public void onCancel(PendingFuture<?,?> task) {
        if (task.getContext() == OpType.CONNECT)
            killConnect();
        if (task.getContext() == OpType.READ)
            killConnect();    // <----------------------- killReading()
        if (task.getContext() == OpType.WRITE)
            killConnect();   // <----------------------- killWriting()
    }


8) Why AsyncFileChannel.open(...) take an ExecutorService and not a 
AsyncChannelGroup ?

regards,
Rémi



More information about the nio-dev mailing list