In spite of the disadvantages mentioned above, there are certainly the cases where it is more convenient to call {@link #await()}. In such a case, please make sure you do not call {@link #await()} in an I/O thread. Otherwise,{@link IllegalStateException} will be raised to prevent a dead lock.
// BAD - NEVER DO THIS {@link ClientBootstrap} b = ...;{@link ChannelFuture} f = b.connect(...);f.awaitUninterruptibly(10, TimeUnit.SECONDS); if (f.isCancelled()) { // Connection attempt cancelled by user } else if (!f.isSuccess()) { // You might get a NullPointerException here because the future // might not be completed yet. f.getCause().printStackTrace(); } else { // Connection established successfully } // GOOD {@link ClientBootstrap} b = ...;// Configure the connect timeout option. b.setOption("connectTimeoutMillis", 10000); {@link ChannelFuture} f = b.connect(...);f.awaitUninterruptibly(); // Now we are sure the future is completed. assert f.isDone(); if (f.isCancelled()) { // Connection attempt cancelled by user } else if (!f.isSuccess()) { f.getCause().printStackTrace(); } else { // Connection established successfully }@apiviz.landmark @apiviz.owns com.facebook.presto.jdbc.internal.netty.channel.ChannelFutureListener - - notifies
In spite of the disadvantages mentioned above, there are certainly the cases where it is more convenient to call {@link #await()}. In such a case, please make sure you do not call {@link #await()} in an I/O thread. Otherwise,{@link BlockingOperationException} will be raised to prevent a dead lock.
// BAD - NEVER DO THIS {@link Bootstrap} b = ...;{@link ChannelFuture} f = b.connect(...);f.awaitUninterruptibly(10, TimeUnit.SECONDS); if (f.isCancelled()) { // Connection attempt cancelled by user } else if (!f.isSuccess()) { // You might get a NullPointerException here because the future // might not be completed yet. f.getCause().printStackTrace(); } else { // Connection established successfully } // GOOD {@link Bootstrap} b = ...;// Configure the connect timeout option. b.setOption( {@link ChannelOption}.CONNECT_TIMEOUT_MILLIS, 10000); {@link ChannelFuture} f = b.connect(...);f.awaitUninterruptibly(); // Now we are sure the future is completed. assert f.isDone(); if (f.isCancelled()) { // Connection attempt cancelled by user } else if (!f.isSuccess()) { f.getCause().printStackTrace(); } else { // Connection established successfully }
All I/O operations in Netty are asynchronous. It means any I/O calls will return immediately with no guarantee that the requested I/O operation has been completed at the end of the call. Instead, you will be returned with a {@link ChannelFuture} instance which tells you when the requested I/Ooperation has succeeded, failed, or cancelled.
Various methods are provided to let you check if the I/O operation has been completed, wait for the completion, and retrieve the result of the I/O operation. It also allows you to add more than one {@link ChannelFutureListener}so you can get notified when the I/O operation has been completed. @author The Netty Project (netty-dev@lists.jboss.org) @author Trustin Lee (tlee@redhat.com) @version $Rev: 987 $, $Date: 2009-03-04 23:27:20 +0900 (Wed, 04 Mar 2009) $ @apiviz.landmark @apiviz.owns org.jboss.netty.channel.ChannelFutureListener - - notifies
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|