Class AsyncFutureTask<T>
java.lang.Object
org.jboss.threads.AsyncFutureTask<T>
- All Implemented Interfaces:
Future<T>,AsyncCancellable,AsyncFuture<T>
Deprecated.
This class is not friendly towards virtual threads.
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.- Author:
- David M. Lloyd
-
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
ConstructorsModifierConstructorDescriptionprotectedAsyncFutureTask(Executor executor) Deprecated.Construct a new instance. -
Method Summary
Modifier and TypeMethodDescriptionfinal <A> voidaddListener(AsyncFuture.Listener<? super T, A> listener, A attachment) Deprecated.Add an asynchronous listener to be called when this operation completes.voidasyncCancel(boolean interruptionDesired) Deprecated.Cancel this task.final AsyncFuture.Statusawait()Deprecated.Wait if necessary for this operation to complete, returning the outcome.final AsyncFuture.StatusDeprecated.Wait if necessary for this operation to complete, returning the outcome, which may includeAsyncFuture.Status.WAITINGif the timeout expires before the operation completes.final AsyncFuture.StatusDeprecated.Wait (uninterruptibly) if necessary for this operation to complete, returning the outcome.final AsyncFuture.StatusawaitUninterruptibly(long timeout, TimeUnit unit) Deprecated.Wait if necessary for this operation to complete, returning the outcome, which may includeAsyncFuture.Status.WAITINGif the timeout expires before the operation completes.final booleancancel(boolean interruptionDesired) Deprecated.Synchronously cancel a task, blocking uninterruptibly until it is known whether such cancellation was successful.final Tget()Deprecated.final TDeprecated.final AsyncFuture.StatusDeprecated.Get (poll) the current status of the asynchronous operation.final TDeprecated.Waits (uninterruptibly) if necessary for the computation to complete, and then retrieves the result.final TgetUninterruptibly(long timeout, TimeUnit unit) Deprecated.Waits (uninterruptibly) if necessary for at most the given time for the computation to complete, and then retrieves the result, if available.final booleanDeprecated.final booleanisDone()Deprecated.protected final booleanDeprecated.Set the cancelled result of this operation.protected final booleanDeprecated.Set the failure result of this operation.protected final booleanDeprecated.Set the successful result of this operation.
-
Constructor Details
-
AsyncFutureTask
Deprecated.Construct a new instance.- Parameters:
executor- the executor to use for asynchronous notifications
-
-
Method Details
-
setResult
Deprecated.Set the successful result of this operation. Once a result is set, calls to this or the otherset*()methods are ignored.- Parameters:
result- the result- Returns:
trueif the result was successfully set, orfalseif a result was already set
-
setCancelled
protected final boolean setCancelled()Deprecated.Set the cancelled result of this operation. Once a result is set, calls to this or the otherset*()methods are ignored.- Returns:
trueif the result was successfully set, orfalseif a result was already set
-
setFailed
Deprecated.Set the failure result of this operation. Once a result is set, calls to this or the otherset*()methods are ignored.- Parameters:
cause- the cause of failure- Returns:
trueif the result was successfully set, orfalseif a result was already set
-
asyncCancel
public void asyncCancel(boolean interruptionDesired) Deprecated.Cancel this task. The default implementation of this method does nothing; if the task support asynchronous cancel, this method may be overridden to implement it. The implementation may choose to support or disregard theinterruptionDesiredflag. Implementations are allowed to interrupt threads associated with tasks even if the flag isfalse; likewise, implementations may choose not to interrupt threads even if the flag istrue.- Specified by:
asyncCancelin interfaceAsyncCancellable- Specified by:
asyncCancelin interfaceAsyncFuture<T>- Parameters:
interruptionDesired-trueif interruption of threads is desired
-
await
Deprecated.Wait if necessary for this operation to complete, returning the outcome. The outcome will be one ofAsyncFuture.Status.COMPLETE,AsyncFuture.Status.CANCELLED, orAsyncFuture.Status.FAILED.- Specified by:
awaitin interfaceAsyncFuture<T>- Returns:
- the outcome
- Throws:
InterruptedException- if execution was interrupted while waiting
-
await
Deprecated.Wait if necessary for this operation to complete, returning the outcome, which may includeAsyncFuture.Status.WAITINGif the timeout expires before the operation completes.- Specified by:
awaitin interfaceAsyncFuture<T>- Parameters:
timeout- the maximum time to waitunit- the time unit of the timeout argument- Returns:
- the outcome
- Throws:
InterruptedException- if execution was interrupted while waiting
-
awaitUninterruptibly
Deprecated.Wait (uninterruptibly) if necessary for this operation to complete, returning the outcome. The outcome will be one ofAsyncFuture.Status.COMPLETE,AsyncFuture.Status.CANCELLED, orAsyncFuture.Status.FAILED.- Specified by:
awaitUninterruptiblyin interfaceAsyncFuture<T>- Returns:
- the outcome
-
awaitUninterruptibly
Deprecated.Wait if necessary for this operation to complete, returning the outcome, which may includeAsyncFuture.Status.WAITINGif the timeout expires before the operation completes.- Specified by:
awaitUninterruptiblyin interfaceAsyncFuture<T>- Parameters:
timeout- the maximum time to waitunit- the time unit of the timeout argument- Returns:
- the outcome
-
get
Deprecated.- Specified by:
getin interfaceFuture<T>- Throws:
InterruptedExceptionExecutionException
-
get
public final T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException Deprecated.- Specified by:
getin interfaceFuture<T>- Throws:
InterruptedExceptionExecutionExceptionTimeoutException
-
getUninterruptibly
Deprecated.Waits (uninterruptibly) if necessary for the computation to complete, and then retrieves the result.- Specified by:
getUninterruptiblyin interfaceAsyncFuture<T>- Returns:
- the computed result
- Throws:
CancellationException- if the computation was cancelledExecutionException- if the computation threw an exception
-
getUninterruptibly
public final T getUninterruptibly(long timeout, TimeUnit unit) throws CancellationException, ExecutionException, TimeoutException Deprecated.Waits (uninterruptibly) if necessary for at most the given time for the computation to complete, and then retrieves the result, if available.- Specified by:
getUninterruptiblyin interfaceAsyncFuture<T>- Parameters:
timeout- the maximum time to waitunit- the time unit of the timeout argument- Returns:
- the computed result
- Throws:
CancellationException- if the computation was cancelledExecutionException- if the computation threw an exceptionTimeoutException- if the wait timed out
-
getStatus
Deprecated.Get (poll) the current status of the asynchronous operation.- Specified by:
getStatusin interfaceAsyncFuture<T>- Returns:
- the current status
-
addListener
Deprecated.Add an asynchronous listener to be called when this operation completes.- Specified by:
addListenerin interfaceAsyncFuture<T>- Type Parameters:
A- the attachment type- Parameters:
listener- the listener to addattachment- the attachment to pass in
-
cancel
public final boolean cancel(boolean interruptionDesired) Deprecated.Synchronously cancel a task, blocking uninterruptibly until it is known whether such cancellation was successful. Note that theFuture.cancel(boolean)is somewhat unclear about blocking semantics. It is recommended to useAsyncFuture.asyncCancel(boolean)instead. -
isCancelled
-
isDone
-