public class DefaultPromise<V> extends AbstractFuture<V> implements Promise<V>
Modifier | Constructor and Description |
---|---|
protected |
DefaultPromise() |
|
DefaultPromise(EventExecutor executor)
Creates a new instance.
|
Modifier and Type | Method and Description |
---|---|
Promise<V> |
addListener(GenericFutureListener<? extends Future<? super V>> listener)
Adds the specified listener to this future.
|
Promise<V> |
addListeners(GenericFutureListener<? extends Future<? super V>>... listeners)
Adds the specified listeners to this future.
|
Promise<V> |
await()
Waits for this future to be completed.
|
boolean |
await(long timeoutMillis)
Waits for this future to be completed within the
specified time limit.
|
boolean |
await(long timeout,
TimeUnit unit)
Waits for this future to be completed within the
specified time limit.
|
Promise<V> |
awaitUninterruptibly()
Waits for this future to be completed without
interruption.
|
boolean |
awaitUninterruptibly(long timeoutMillis)
Waits for this future to be completed within the
specified time limit without interruption.
|
boolean |
awaitUninterruptibly(long timeout,
TimeUnit unit)
Waits for this future to be completed within the
specified time limit without interruption.
|
boolean |
cancel(boolean mayInterruptIfRunning)
If the cancellation was successful it will fail the future with an
CancellationException . |
Throwable |
cause()
Returns the cause of the failed I/O operation if the I/O operation has
failed.
|
protected void |
checkDeadLock()
Do deadlock checks
|
protected EventExecutor |
executor() |
V |
getNow()
Return the result without blocking.
|
boolean |
isCancellable()
returns
true if and only if the operation can be cancelled via Future.cancel(boolean) . |
boolean |
isCancelled() |
boolean |
isDone() |
boolean |
isSuccess()
Returns
true if and only if the I/O operation was completed
successfully. |
protected static void |
notifyListener(EventExecutor eventExecutor,
Future<?> future,
GenericFutureListener<?> l) |
Promise<V> |
removeListener(GenericFutureListener<? extends Future<? super V>> listener)
Removes the specified listener from this future.
|
Promise<V> |
removeListeners(GenericFutureListener<? extends Future<? super V>>... listeners)
Removes the specified listeners from this future.
|
Promise<V> |
setFailure(Throwable cause)
Marks this future as a failure and notifies all
listeners.
|
Promise<V> |
setSuccess(V result)
Marks this future as a success and notifies all
listeners.
|
boolean |
setUncancellable()
Make this future impossible to cancel.
|
Promise<V> |
sync()
Waits for this future until it is done, and rethrows the cause of the failure if this future
failed.
|
Promise<V> |
syncUninterruptibly()
Waits for this future until it is done, and rethrows the cause of the failure if this future
failed.
|
String |
toString() |
protected StringBuilder |
toStringBuilder() |
boolean |
tryFailure(Throwable cause)
Marks this future as a failure and notifies all
listeners.
|
boolean |
trySuccess(V result)
Marks this future as a success and notifies all
listeners.
|
get, get
public DefaultPromise(EventExecutor executor)
EventExecutor.newPromise()
to create a new promiseexecutor
- the EventExecutor
which is used to notify the promise once it is completeprotected DefaultPromise()
protected EventExecutor executor()
public boolean isCancelled()
isCancelled
in interface Future<V>
public boolean isCancellable()
Future
true
if and only if the operation can be cancelled via Future.cancel(boolean)
.public boolean isSuccess()
Future
true
if and only if the I/O operation was completed
successfully.public Throwable cause()
Future
null
if succeeded or this future is not
completed yet.public Promise<V> addListener(GenericFutureListener<? extends Future<? super V>> listener)
Future
addListener
in interface Promise<V>
public Promise<V> addListeners(GenericFutureListener<? extends Future<? super V>>... listeners)
Future
addListeners
in interface Promise<V>
public Promise<V> removeListener(GenericFutureListener<? extends Future<? super V>> listener)
Future
removeListener
in interface Promise<V>
public Promise<V> removeListeners(GenericFutureListener<? extends Future<? super V>>... listeners)
Future
removeListeners
in interface Promise<V>
public Promise<V> sync() throws InterruptedException
Future
sync
in interface Promise<V>
InterruptedException
public Promise<V> syncUninterruptibly()
Future
syncUninterruptibly
in interface Promise<V>
public Promise<V> await() throws InterruptedException
Future
await
in interface Promise<V>
InterruptedException
- if the current thread was interruptedpublic boolean await(long timeout, TimeUnit unit) throws InterruptedException
Future
true
if and only if the future was completed within
the specified time limitInterruptedException
- if the current thread was interruptedpublic boolean await(long timeoutMillis) throws InterruptedException
Future
true
if and only if the future was completed within
the specified time limitInterruptedException
- if the current thread was interruptedpublic Promise<V> awaitUninterruptibly()
Future
InterruptedException
and
discards it silently.awaitUninterruptibly
in interface Promise<V>
public boolean awaitUninterruptibly(long timeout, TimeUnit unit)
Future
InterruptedException
and discards it silently.true
if and only if the future was completed within
the specified time limitpublic boolean awaitUninterruptibly(long timeoutMillis)
Future
InterruptedException
and discards it silently.true
if and only if the future was completed within
the specified time limitprotected void checkDeadLock()
public Promise<V> setSuccess(V result)
Promise
IllegalStateException
.setSuccess
in interface Promise<V>
public boolean trySuccess(V result)
Promise
trySuccess
in interface Promise<V>
true
if and only if successfully marked this future as
a success. Otherwise false
because this future is
already marked as either a success or a failure.public Promise<V> setFailure(Throwable cause)
Promise
IllegalStateException
.setFailure
in interface Promise<V>
public boolean tryFailure(Throwable cause)
Promise
tryFailure
in interface Promise<V>
true
if and only if successfully marked this future as
a failure. Otherwise false
because this future is
already marked as either a success or a failure.public boolean cancel(boolean mayInterruptIfRunning)
Future
CancellationException
.public boolean setUncancellable()
Promise
setUncancellable
in interface Promise<V>
true
if and only if successfully marked this future as uncancellable or it is already done
without being cancelled. false
if this future has been cancelled already.public V getNow()
Future
null
.
As it is possible that a null
value is used to mark the future as successful you also need to check
if the future is really done with Future.isDone()
and not relay on the returned null
value.protected static void notifyListener(EventExecutor eventExecutor, Future<?> future, GenericFutureListener<?> l)
protected StringBuilder toStringBuilder()
Copyright © 2008–2015 The Netty Project. All rights reserved.