public interface AsyncFuture<T> extends 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,
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,
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,
TimeUnit unit)
Waits (uninterruptibly) if necessary for at most the given time for the computation to complete, and then
retrieves the result, if available.
|
get, get, isCancelled, isDone
AsyncFuture.Status await() throws InterruptedException
AsyncFuture.Status.COMPLETE
, AsyncFuture.Status.CANCELLED
, or AsyncFuture.Status.FAILED
.InterruptedException
- if execution was interrupted while waitingAsyncFuture.Status await(long timeout, TimeUnit unit) throws InterruptedException
AsyncFuture.Status.WAITING
if
the timeout expires before the operation completes.timeout
- the maximum time to waitunit
- the time unit of the timeout argumentInterruptedException
- if execution was interrupted while waitingT getUninterruptibly() throws CancellationException, ExecutionException
CancellationException
- if the computation was cancelledExecutionException
- if the computation threw an exceptionT getUninterruptibly(long timeout, TimeUnit unit) throws CancellationException, ExecutionException, TimeoutException
timeout
- the maximum time to waitunit
- the time unit of the timeout argumentCancellationException
- if the computation was cancelledExecutionException
- if the computation threw an exceptionTimeoutException
- if the wait timed outAsyncFuture.Status awaitUninterruptibly()
AsyncFuture.Status.COMPLETE
, AsyncFuture.Status.CANCELLED
, or AsyncFuture.Status.FAILED
.AsyncFuture.Status awaitUninterruptibly(long timeout, 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.void 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 AsyncCancellable
interruptionDesired
- true
if interruption of threads is desiredCopyright © 2012 JBoss by Red Hat. All Rights Reserved.