Class AsyncFutureTask<T>

java.lang.Object
org.jboss.threads.AsyncFutureTask<T>
All Implemented Interfaces:
Future<T>, AsyncCancellable, AsyncFuture<T>

@Deprecated public abstract class AsyncFutureTask<T> extends Object implements 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
  • Constructor Details

    • AsyncFutureTask

      protected AsyncFutureTask(Executor executor)
      Deprecated.
      Construct a new instance.
      Parameters:
      executor - the executor to use for asynchronous notifications
  • Method Details

    • setResult

      protected final boolean setResult(T result)
      Deprecated.
      Set the successful result of this operation. Once a result is set, calls to this or the other set*() methods are ignored.
      Parameters:
      result - the result
      Returns:
      true if the result was successfully set, or false if 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 other set*() methods are ignored.
      Returns:
      true if the result was successfully set, or false if a result was already set
    • setFailed

      protected final boolean setFailed(Throwable cause)
      Deprecated.
      Set the failure result of this operation. Once a result is set, calls to this or the other set*() methods are ignored.
      Parameters:
      cause - the cause of failure
      Returns:
      true if the result was successfully set, or false if 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 the 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.
      Specified by:
      asyncCancel in interface AsyncCancellable
      Specified by:
      asyncCancel in interface AsyncFuture<T>
      Parameters:
      interruptionDesired - true if interruption of threads is desired
    • await

      public final AsyncFuture.Status await() throws InterruptedException
      Deprecated.
      Wait if necessary for this operation to complete, returning the outcome. The outcome will be one of AsyncFuture.Status.COMPLETE, AsyncFuture.Status.CANCELLED, or AsyncFuture.Status.FAILED.
      Specified by:
      await in interface AsyncFuture<T>
      Returns:
      the outcome
      Throws:
      InterruptedException - if execution was interrupted while waiting
    • await

      public final AsyncFuture.Status await(long timeout, TimeUnit unit) throws InterruptedException
      Deprecated.
      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.
      Specified by:
      await in interface AsyncFuture<T>
      Parameters:
      timeout - the maximum time to wait
      unit - the time unit of the timeout argument
      Returns:
      the outcome
      Throws:
      InterruptedException - if execution was interrupted while waiting
    • awaitUninterruptibly

      public final AsyncFuture.Status awaitUninterruptibly()
      Deprecated.
      Wait (uninterruptibly) if necessary for this operation to complete, returning the outcome. The outcome will be one of AsyncFuture.Status.COMPLETE, AsyncFuture.Status.CANCELLED, or AsyncFuture.Status.FAILED.
      Specified by:
      awaitUninterruptibly in interface AsyncFuture<T>
      Returns:
      the outcome
    • awaitUninterruptibly

      public final AsyncFuture.Status awaitUninterruptibly(long timeout, TimeUnit unit)
      Deprecated.
      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.
      Specified by:
      awaitUninterruptibly in interface AsyncFuture<T>
      Parameters:
      timeout - the maximum time to wait
      unit - the time unit of the timeout argument
      Returns:
      the outcome
    • get

      public final T get() throws InterruptedException, ExecutionException
      Deprecated.
      Specified by:
      get in interface Future<T>
      Throws:
      InterruptedException
      ExecutionException
    • get

      public final T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException
      Deprecated.
      Specified by:
      get in interface Future<T>
      Throws:
      InterruptedException
      ExecutionException
      TimeoutException
    • getUninterruptibly

      public final T getUninterruptibly() throws CancellationException, ExecutionException
      Deprecated.
      Waits (uninterruptibly) if necessary for the computation to complete, and then retrieves the result.
      Specified by:
      getUninterruptibly in interface AsyncFuture<T>
      Returns:
      the computed result
      Throws:
      CancellationException - if the computation was cancelled
      ExecutionException - 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:
      getUninterruptibly in interface AsyncFuture<T>
      Parameters:
      timeout - the maximum time to wait
      unit - the time unit of the timeout argument
      Returns:
      the computed result
      Throws:
      CancellationException - if the computation was cancelled
      ExecutionException - if the computation threw an exception
      TimeoutException - if the wait timed out
    • getStatus

      public final AsyncFuture.Status getStatus()
      Deprecated.
      Get (poll) the current status of the asynchronous operation.
      Specified by:
      getStatus in interface AsyncFuture<T>
      Returns:
      the current status
    • addListener

      public final <A> void addListener(AsyncFuture.Listener<? super T, A> listener, A attachment)
      Deprecated.
      Add an asynchronous listener to be called when this operation completes.
      Specified by:
      addListener in interface AsyncFuture<T>
      Type Parameters:
      A - the attachment type
      Parameters:
      listener - the listener to add
      attachment - 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 the Future.cancel(boolean) is somewhat unclear about blocking semantics. It is recommended to use AsyncFuture.asyncCancel(boolean) instead.
      Specified by:
      cancel in interface AsyncFuture<T>
      Specified by:
      cancel in interface Future<T>
      Parameters:
      interruptionDesired - if interruption is desired (if available)
      Returns:
      true if cancel succeeded, false otherwise
    • isCancelled

      public final boolean isCancelled()
      Deprecated.
      Specified by:
      isCancelled in interface Future<T>
    • isDone

      public final boolean isDone()
      Deprecated.
      Specified by:
      isDone in interface Future<T>