|
JBoss Threads 2.0.0.GA | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.jboss.threads.AsyncFutureTask<T>
public abstract class AsyncFutureTask<T>
A base class for implementing asynchronous tasks. This class implements
Future as well as AsyncFuture, and
is approximately equivalent to FutureTask, however it
does not implement Runnable and is somewhat more flexible.
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from interface org.jboss.threads.AsyncFuture |
|---|
AsyncFuture.AbstractListener<T,A>, AsyncFuture.Listener<T,A>, AsyncFuture.Status |
| Constructor Summary | |
|---|---|
protected |
AsyncFutureTask(Executor executor)
Construct a new instance. |
| Method Summary | ||
|---|---|---|
|
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. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
protected AsyncFutureTask(Executor executor)
executor - the executor to use for asynchronous notifications| Method Detail |
|---|
protected final boolean setResult(T result)
set*() methods are ignored.
result - the result
true 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 failure
true 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 AsyncCancellableasyncCancel in interface AsyncFuture<T>interruptionDesired - true if interruption of threads is desired
public 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 waiting
public 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 argument
InterruptedException - 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 argument
public 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 cancelled
ExecutionException - if the computation threw an exception
public 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 argument
CancellationException - if the computation was cancelled
ExecutionException - if the computation threw an exception
TimeoutException - 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.
cancel in interface Future<T>cancel in interface AsyncFuture<T>interruptionDesired - if interruption is desired (if available)
true if cancel succeeded, false otherwisepublic final boolean isCancelled()
isCancelled in interface Future<T>public final boolean isDone()
isDone in interface Future<T>
|
JBoss Threads 2.0.0.GA | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||