Package org.jdeferred2
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 java.util.concurrent.Future
Future.State
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate CancellationHandler
private static final org.slf4j.Logger
protected final DeferredManager.StartPolicy
private Object
-
Constructor Summary
ConstructorsConstructorDescriptionDeferredFutureTask
(Runnable task) Creates a newDeferredFutureTask
with the given task.DeferredFutureTask
(Runnable task, CancellationHandler cancellationHandler) Creates a newDeferredFutureTask
with the given task and a explicitCancellationHandler
The givencancellationHandler
has precedence over the given task if the task implements theCancellationHandler
interface.DeferredFutureTask
(Callable<D> task) Creates a newDeferredFutureTask
with the given task.DeferredFutureTask
(Callable<D> task, CancellationHandler cancellationHandler) Creates a newDeferredFutureTask
with the given task and a explicitCancellationHandler
The givencancellationHandler
has precedence over the given task if the task implements theCancellationHandler
interface.DeferredFutureTask
(DeferredCallable<D, P> task) Creates a newDeferredFutureTask
with the given task.DeferredFutureTask
(DeferredCallable<D, P> task, CancellationHandler cancellationHandler) Creates a newDeferredFutureTask
with the given task and a explicitCancellationHandler
The givencancellationHandler
has precedence over the given task if the task implements theCancellationHandler
interface.DeferredFutureTask
(DeferredRunnable<P> task) Creates a newDeferredFutureTask
with the given task.DeferredFutureTask
(DeferredRunnable<P> task, CancellationHandler cancellationHandler) Creates a newDeferredFutureTask
with the given task and a explicitCancellationHandler
The givencancellationHandler
has precedence over the given task if the task implements theCancellationHandler
interface. -
Method Summary
Methods inherited from class java.util.concurrent.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
Creates a newDeferredFutureTask
with the given task. The given task may implement theCancellationHandler
interface.- Parameters:
task
- the task to be executed. Must not be null.
-
DeferredFutureTask
Creates a newDeferredFutureTask
with the given task. The given task may implement theCancellationHandler
interface.- Parameters:
task
- the task to be executed. Must not be null.
-
DeferredFutureTask
Creates a newDeferredFutureTask
with the given task. The given task may implement theCancellationHandler
interface.- Parameters:
task
- the task to be executed. Must not be null.
-
DeferredFutureTask
Creates a newDeferredFutureTask
with the given task. The given task may implement theCancellationHandler
interface.- Parameters:
task
- the task to be executed. Must not be null.
-
DeferredFutureTask
Creates a newDeferredFutureTask
with the given task and a explicitCancellationHandler
The givencancellationHandler
has precedence over the given task if the task implements theCancellationHandler
interface.- Parameters:
task
- the task to be executed. Must not be null.cancellationHandler
- theCancellationHandler
to invoke during onCancel. May be null.- Since:
- 2.0
-
DeferredFutureTask
Creates a newDeferredFutureTask
with the given task and a explicitCancellationHandler
The givencancellationHandler
has precedence over the given task if the task implements theCancellationHandler
interface.- Parameters:
task
- the task to be executed. Must not be null.cancellationHandler
- theCancellationHandler
to invoke during onCancel. May be null.- Since:
- 2.0
-
DeferredFutureTask
Creates a newDeferredFutureTask
with the given task and a explicitCancellationHandler
The givencancellationHandler
has precedence over the given task if the task implements theCancellationHandler
interface.- Parameters:
task
- the task to be executed. Must not be null.cancellationHandler
- theCancellationHandler
to invoke during onCancel. May be null.- Since:
- 2.0
-
DeferredFutureTask
Creates a newDeferredFutureTask
with the given task and a explicitCancellationHandler
The givencancellationHandler
has precedence over the given task if the task implements theCancellationHandler
interface.- Parameters:
task
- the task to be executed. Must not be null.cancellationHandler
- theCancellationHandler
to invoke during onCancel. May be null.- Since:
- 2.0
-
-
Method Details
-
promise
-
done
protected void done()- Overrides:
done
in classFutureTask<D>
-
causeOf
-
cleanup
protected void cleanup()Performs resource cleanup upon interruption or cancellation of the underlying task. This method gives precedence tocancellationHandler
it not null, otherwise it invokes the underlying task'sonCancel()
if it implements theCancellationHandler
interface.- Since:
- 2.0
-
getStartPolicy
-