public interface AsyncFuture<T> extends java.util.concurrent.Future<T>, AsyncCancellable
Future while also adding several additional convenience methods and the ability to add asynchronous
callbacks.| Modifier and Type | Interface and Description |
|---|---|
static class |
AsyncFuture.AbstractListener<T,A>
An abstract base class for an implementation of the
Listener interface. |
static interface |
AsyncFuture.Listener<T,A>
A listener for an asynchronous future computation result.
|
static class |
AsyncFuture.Status
The possible statuses of an
AsyncFuture. |
| Modifier and Type | Method and Description |
|---|---|
<A> void |
addListener(AsyncFuture.Listener<? super T,A> listener,
A attachment)
Add an asynchronous listener to be called when this operation completes.
|
void |
asyncCancel(boolean interruptionDesired)
Handle an asynchronous cancellation.
|
AsyncFuture.Status |
await()
Wait if necessary for this operation to complete, returning the outcome.
|
AsyncFuture.Status |
await(long timeout,
java.util.concurrent.TimeUnit unit)
Wait if necessary for this operation to complete, returning the outcome, which may include
AsyncFuture.Status.WAITING if
the timeout expires before the operation completes. |
AsyncFuture.Status |
awaitUninterruptibly()
Wait (uninterruptibly) if necessary for this operation to complete, returning the outcome.
|
AsyncFuture.Status |
awaitUninterruptibly(long timeout,
java.util.concurrent.TimeUnit unit)
Wait if necessary for this operation to complete, returning the outcome, which may include
AsyncFuture.Status.WAITING if
the timeout expires before the operation completes. |
boolean |
cancel(boolean interruptionDesired)
Synchronously cancel a task, blocking uninterruptibly until it is known whether such cancellation was
successful.
|
AsyncFuture.Status |
getStatus()
Get (poll) the current status of the asynchronous operation.
|
T |
getUninterruptibly()
Waits (uninterruptibly) if necessary for the computation to complete, and then retrieves the result.
|
T |
getUninterruptibly(long timeout,
java.util.concurrent.TimeUnit unit)
Waits (uninterruptibly) if necessary for at most the given time for the computation to complete, and then
retrieves the result, if available.
|
AsyncFuture.Status await() throws java.lang.InterruptedException
AsyncFuture.Status.COMPLETE, AsyncFuture.Status.CANCELLED, or AsyncFuture.Status.FAILED.java.lang.InterruptedException - if execution was interrupted while waitingAsyncFuture.Status await(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
AsyncFuture.Status.WAITING if
the timeout expires before the operation completes.timeout - the maximum time to waitunit - the time unit of the timeout argumentjava.lang.InterruptedException - if execution was interrupted while waitingT getUninterruptibly() throws java.util.concurrent.CancellationException, java.util.concurrent.ExecutionException
java.util.concurrent.CancellationException - if the computation was cancelledjava.util.concurrent.ExecutionException - if the computation threw an exceptionT getUninterruptibly(long timeout, java.util.concurrent.TimeUnit unit) throws java.util.concurrent.CancellationException, java.util.concurrent.ExecutionException, java.util.concurrent.TimeoutException
timeout - the maximum time to waitunit - the time unit of the timeout argumentjava.util.concurrent.CancellationException - if the computation was cancelledjava.util.concurrent.ExecutionException - if the computation threw an exceptionjava.util.concurrent.TimeoutException - if the wait timed outAsyncFuture.Status awaitUninterruptibly()
AsyncFuture.Status.COMPLETE, AsyncFuture.Status.CANCELLED, or AsyncFuture.Status.FAILED.AsyncFuture.Status awaitUninterruptibly(long timeout, java.util.concurrent.TimeUnit unit)
AsyncFuture.Status.WAITING if
the timeout expires before the operation completes.timeout - the maximum time to waitunit - the time unit of the timeout argumentAsyncFuture.Status getStatus()
<A> void addListener(AsyncFuture.Listener<? super T,A> listener, A attachment)
A - the attachment typelistener - the listener to addattachment - the attachment to pass inboolean cancel(boolean interruptionDesired)
Future.cancel(boolean) is somewhat unclear about blocking semantics.
It is recommended to use asyncCancel(boolean) instead.cancel in interface java.util.concurrent.Future<T>interruptionDesired - if interruption is desired (if available)true if cancel succeeded, false otherwisevoid asyncCancel(boolean interruptionDesired)
interruptionDesired flag
even if it has already been called without that flag set before. Otherwise, this method is
idempotent, and thus may be called more than once without additional effect.asyncCancel in interface AsyncCancellableinterruptionDesired - true if interruption of threads is desired