public abstract class AsyncFutureTask<T> extends Object implements AsyncFuture<T>
Future
as well as AsyncFuture
, and
is approximately equivalent to FutureTask
, however it
does not implement Runnable
and is somewhat more flexible.AsyncFuture.AbstractListener<T,A>, AsyncFuture.Listener<T,A>, AsyncFuture.Status
Modifier | Constructor and Description |
---|---|
protected |
AsyncFutureTask(Executor executor)
Construct a new instance.
|
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)
Cancel this task.
|
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.
|
T |
get() |
T |
get(long timeout,
TimeUnit unit) |
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.
|
boolean |
isCancelled() |
boolean |
isDone() |
protected boolean |
setCancelled()
Set the cancelled result of this operation.
|
protected boolean |
setFailed(Throwable cause)
Set the failure result of this operation.
|
protected boolean |
setResult(T result)
Set the successful result of this operation.
|
protected AsyncFutureTask(Executor executor)
executor
- the executor to use for asynchronous notificationsprotected final boolean setResult(T result)
set*()
methods are ignored.result
- the resulttrue
if the result was successfully set, or false
if a result was already setprotected final boolean setCancelled()
set*()
methods are ignored.true
if the result was successfully set, or false
if a result was already setprotected final boolean setFailed(Throwable cause)
set*()
methods are ignored.cause
- the cause of failuretrue
if the result was successfully set, or false
if a result was already setpublic void asyncCancel(boolean interruptionDesired)
interruptionDesired
flag.
Implementations are allowed to interrupt threads associated with tasks even if the flag is
false
; likewise, implementations may choose not to interrupt threads even if the
flag is true
.asyncCancel
in interface AsyncCancellable
asyncCancel
in interface AsyncFuture<T>
interruptionDesired
- true
if interruption of threads is desiredpublic final AsyncFuture.Status await() throws InterruptedException
AsyncFuture.Status.COMPLETE
, AsyncFuture.Status.CANCELLED
, or AsyncFuture.Status.FAILED
.await
in interface AsyncFuture<T>
InterruptedException
- if execution was interrupted while waitingpublic final AsyncFuture.Status await(long timeout, TimeUnit unit) throws InterruptedException
AsyncFuture.Status.WAITING
if
the timeout expires before the operation completes.await
in interface AsyncFuture<T>
timeout
- the maximum time to waitunit
- the time unit of the timeout argumentInterruptedException
- if execution was interrupted while waitingpublic final AsyncFuture.Status awaitUninterruptibly()
AsyncFuture.Status.COMPLETE
, AsyncFuture.Status.CANCELLED
, or AsyncFuture.Status.FAILED
.awaitUninterruptibly
in interface AsyncFuture<T>
public final AsyncFuture.Status awaitUninterruptibly(long timeout, TimeUnit unit)
AsyncFuture.Status.WAITING
if
the timeout expires before the operation completes.awaitUninterruptibly
in interface AsyncFuture<T>
timeout
- the maximum time to waitunit
- the time unit of the timeout argumentpublic final T get() throws InterruptedException, ExecutionException
get
in interface Future<T>
InterruptedException
ExecutionException
public final T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException
get
in interface Future<T>
InterruptedException
ExecutionException
TimeoutException
public final T getUninterruptibly() throws CancellationException, ExecutionException
getUninterruptibly
in interface AsyncFuture<T>
CancellationException
- if the computation was cancelledExecutionException
- if the computation threw an exceptionpublic final T getUninterruptibly(long timeout, TimeUnit unit) throws CancellationException, ExecutionException, TimeoutException
getUninterruptibly
in interface AsyncFuture<T>
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 outpublic final AsyncFuture.Status getStatus()
getStatus
in interface AsyncFuture<T>
public final <A> void addListener(AsyncFuture.Listener<? super T,A> listener, A attachment)
addListener
in interface AsyncFuture<T>
A
- the attachment typelistener
- the listener to addattachment
- the attachment to pass inpublic final boolean cancel(boolean interruptionDesired)
Future.cancel(boolean)
is somewhat unclear about blocking semantics.
It is recommended to use AsyncFuture.asyncCancel(boolean)
instead.public final boolean isCancelled()
isCancelled
in interface Future<T>
Copyright © 2012 JBoss by Red Hat. All Rights Reserved.