Class DeferredFutureTask<D,P>

java.lang.Object
java.util.concurrent.FutureTask<D>
org.jdeferred2.DeferredFutureTask<D,P>
Type Parameters:
D - Type used for Deferred.resolve(Object)
P - Type used for Deferred.notify(Object)
All Implemented Interfaces:
Runnable, Future<D>, RunnableFuture<D>

public class DeferredFutureTask<D,P> extends FutureTask<D>
FutureTask can wrap around Callable and Runnable. In these two cases, a new Deferred object will be created. This class will override FutureTask.done() to trigger the appropriate Deferred actions.

Note, type used for Deferred.reject(Object) is always Throwable.

When the task is completed successfully, Deferred.resolve(Object) will be called. When a task is canceled, Deferred.reject(Object) will be called with an instance of CancellationException If any Exception occurred, Deferred.reject(Object) will be called with the Exception instance.

  • Field Details

  • Constructor Details

    • DeferredFutureTask

      public DeferredFutureTask(Callable<D> task)
      Creates a new DeferredFutureTask with the given task. The given task may implement the CancellationHandler interface.
      Parameters:
      task - the task to be executed. Must not be null.
    • DeferredFutureTask

      public DeferredFutureTask(Runnable task)
      Creates a new DeferredFutureTask with the given task. The given task may implement the CancellationHandler interface.
      Parameters:
      task - the task to be executed. Must not be null.
    • DeferredFutureTask

      public DeferredFutureTask(DeferredCallable<D,P> task)
      Creates a new DeferredFutureTask with the given task. The given task may implement the CancellationHandler interface.
      Parameters:
      task - the task to be executed. Must not be null.
    • DeferredFutureTask

      public DeferredFutureTask(DeferredRunnable<P> task)
      Creates a new DeferredFutureTask with the given task. The given task may implement the CancellationHandler interface.
      Parameters:
      task - the task to be executed. Must not be null.
    • DeferredFutureTask

      public DeferredFutureTask(Callable<D> task, CancellationHandler cancellationHandler)
      Creates a new DeferredFutureTask with the given task and a explicit CancellationHandler The given cancellationHandler has precedence over the given task if the task implements the CancellationHandler interface.
      Parameters:
      task - the task to be executed. Must not be null.
      cancellationHandler - the CancellationHandler to invoke during onCancel. May be null.
      Since:
      2.0
    • DeferredFutureTask

      public DeferredFutureTask(Runnable task, CancellationHandler cancellationHandler)
      Creates a new DeferredFutureTask with the given task and a explicit CancellationHandler The given cancellationHandler has precedence over the given task if the task implements the CancellationHandler interface.
      Parameters:
      task - the task to be executed. Must not be null.
      cancellationHandler - the CancellationHandler to invoke during onCancel. May be null.
      Since:
      2.0
    • DeferredFutureTask

      public DeferredFutureTask(DeferredCallable<D,P> task, CancellationHandler cancellationHandler)
      Creates a new DeferredFutureTask with the given task and a explicit CancellationHandler The given cancellationHandler has precedence over the given task if the task implements the CancellationHandler interface.
      Parameters:
      task - the task to be executed. Must not be null.
      cancellationHandler - the CancellationHandler to invoke during onCancel. May be null.
      Since:
      2.0
    • DeferredFutureTask

      public DeferredFutureTask(DeferredRunnable<P> task, CancellationHandler cancellationHandler)
      Creates a new DeferredFutureTask with the given task and a explicit CancellationHandler The given cancellationHandler has precedence over the given task if the task implements the CancellationHandler interface.
      Parameters:
      task - the task to be executed. Must not be null.
      cancellationHandler - the CancellationHandler to invoke during onCancel. May be null.
      Since:
      2.0
  • Method Details

    • promise

      public Promise<D,Throwable,P> promise()
    • done

      protected void done()
      Overrides:
      done in class FutureTask<D>
    • causeOf

      protected Throwable causeOf(Exception e)
    • cleanup

      protected void cleanup()
      Performs resource cleanup upon interruption or cancellation of the underlying task. This method gives precedence to cancellationHandler it not null, otherwise it invokes the underlying task's onCancel() if it implements the CancellationHandler interface.
      Since:
      2.0
    • getStartPolicy

      public DeferredManager.StartPolicy getStartPolicy()