Class DeferredFutureTask<D,P>
java.lang.Object
java.util.concurrent.FutureTask<D>
org.jdeferred2.DeferredFutureTask<D,P>
- Type Parameters:
D- Type used forDeferred.resolve(Object)P- Type used forDeferred.notify(Object)
- All Implemented Interfaces:
Runnable, Future<D>, RunnableFuture<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.
-
Nested Class Summary
Nested classes/interfaces inherited from interface Future
Future.State -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate CancellationHandlerprivate static final org.slf4j.Loggerprotected final DeferredManager.StartPolicyprivate Object -
Constructor Summary
ConstructorsConstructorDescriptionDeferredFutureTask(Runnable task) Creates a newDeferredFutureTaskwith the given task.DeferredFutureTask(Runnable task, CancellationHandler cancellationHandler) Creates a newDeferredFutureTaskwith the given task and a explicitCancellationHandlerThe givencancellationHandlerhas precedence over the given task if the task implements theCancellationHandlerinterface.DeferredFutureTask(Callable<D> task) Creates a newDeferredFutureTaskwith the given task.DeferredFutureTask(Callable<D> task, CancellationHandler cancellationHandler) Creates a newDeferredFutureTaskwith the given task and a explicitCancellationHandlerThe givencancellationHandlerhas precedence over the given task if the task implements theCancellationHandlerinterface.DeferredFutureTask(DeferredCallable<D, P> task) Creates a newDeferredFutureTaskwith the given task.DeferredFutureTask(DeferredCallable<D, P> task, CancellationHandler cancellationHandler) Creates a newDeferredFutureTaskwith the given task and a explicitCancellationHandlerThe givencancellationHandlerhas precedence over the given task if the task implements theCancellationHandlerinterface.DeferredFutureTask(DeferredRunnable<P> task) Creates a newDeferredFutureTaskwith the given task.DeferredFutureTask(DeferredRunnable<P> task, CancellationHandler cancellationHandler) Creates a newDeferredFutureTaskwith the given task and a explicitCancellationHandlerThe givencancellationHandlerhas precedence over the given task if the task implements theCancellationHandlerinterface. -
Method Summary
Methods inherited from class FutureTask
cancel, exceptionNow, get, get, isCancelled, isDone, resultNow, run, runAndReset, set, setException, state, toString
-
Field Details
-
LOG
private static final org.slf4j.Logger LOG -
deferred
-
startPolicy
-
taskDelegate
-
cancellationHandler
-
-
Constructor Details
-
DeferredFutureTask
-
DeferredFutureTask
Creates a newDeferredFutureTaskwith the given task. The given task may implement theCancellationHandlerinterface.- Parameters:
task- the task to be executed. Must not be null.
-
DeferredFutureTask
Creates a newDeferredFutureTaskwith the given task. The given task may implement theCancellationHandlerinterface.- Parameters:
task- the task to be executed. Must not be null.
-
DeferredFutureTask
Creates a newDeferredFutureTaskwith the given task. The given task may implement theCancellationHandlerinterface.- Parameters:
task- the task to be executed. Must not be null.
-
DeferredFutureTask
Creates a newDeferredFutureTaskwith the given task and a explicitCancellationHandlerThe givencancellationHandlerhas precedence over the given task if the task implements theCancellationHandlerinterface.- Parameters:
task- the task to be executed. Must not be null.cancellationHandler- theCancellationHandlerto invoke during onCancel. May be null.- Since:
- 2.0
-
DeferredFutureTask
Creates a newDeferredFutureTaskwith the given task and a explicitCancellationHandlerThe givencancellationHandlerhas precedence over the given task if the task implements theCancellationHandlerinterface.- Parameters:
task- the task to be executed. Must not be null.cancellationHandler- theCancellationHandlerto invoke during onCancel. May be null.- Since:
- 2.0
-
DeferredFutureTask
Creates a newDeferredFutureTaskwith the given task and a explicitCancellationHandlerThe givencancellationHandlerhas precedence over the given task if the task implements theCancellationHandlerinterface.- Parameters:
task- the task to be executed. Must not be null.cancellationHandler- theCancellationHandlerto invoke during onCancel. May be null.- Since:
- 2.0
-
DeferredFutureTask
Creates a newDeferredFutureTaskwith the given task and a explicitCancellationHandlerThe givencancellationHandlerhas precedence over the given task if the task implements theCancellationHandlerinterface.- Parameters:
task- the task to be executed. Must not be null.cancellationHandler- theCancellationHandlerto invoke during onCancel. May be null.- Since:
- 2.0
-
-
Method Details
-
promise
-
done
protected void done()- Overrides:
donein classFutureTask<D>
-
causeOf
-
cleanup
protected void cleanup()Performs resource cleanup upon interruption or cancellation of the underlying task. This method gives precedence tocancellationHandlerit not null, otherwise it invokes the underlying task'sonCancel()if it implements theCancellationHandlerinterface.- Since:
- 2.0
-
getStartPolicy
-