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:
java.lang.Runnable,java.util.concurrent.Future<D>,java.util.concurrent.RunnableFuture<D>
public class DeferredFutureTask<D,P> extends java.util.concurrent.FutureTask<D>FutureTask can wrap aroundCallableandRunnable. In these two cases, a newDeferredobject will be created. This class will overrideFutureTask.done()to trigger the appropriateDeferredactions.Note, type used for
Deferred.reject(Object)is alwaysThrowable.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 ofCancellationExceptionIf any Exception occurred,Deferred.reject(Object)will be called with the Exception instance.
-
-
Field Summary
Fields Modifier and Type Field Description private CancellationHandlercancellationHandlerprotected Deferred<D,java.lang.Throwable,P>deferredprivate static org.slf4j.LoggerLOGprotected DeferredManager.StartPolicystartPolicyprivate java.lang.ObjecttaskDelegate
-
Constructor Summary
Constructors Constructor Description DeferredFutureTask(java.lang.Runnable task)Creates a newDeferredFutureTaskwith the given task.DeferredFutureTask(java.lang.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(java.util.concurrent.Callable<D> task)Creates a newDeferredFutureTaskwith the given task.DeferredFutureTask(java.util.concurrent.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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.lang.ThrowablecauseOf(java.lang.Exception e)protected voidcleanup()Performs resource cleanup upon interruption or cancellation of the underlying task.protected voiddone()DeferredManager.StartPolicygetStartPolicy()Promise<D,java.lang.Throwable,P>promise()
-
-
-
Field Detail
-
LOG
private static final org.slf4j.Logger LOG
-
startPolicy
protected final DeferredManager.StartPolicy startPolicy
-
taskDelegate
private java.lang.Object taskDelegate
-
cancellationHandler
private CancellationHandler cancellationHandler
-
-
Constructor Detail
-
DeferredFutureTask
public DeferredFutureTask(java.util.concurrent.Callable<D> task)
Creates a newDeferredFutureTaskwith the given task. The given task may implement theCancellationHandlerinterface.- Parameters:
task- the task to be executed. Must not be null.
-
DeferredFutureTask
public DeferredFutureTask(java.lang.Runnable task)
Creates a newDeferredFutureTaskwith the given task. The given task may implement theCancellationHandlerinterface.- Parameters:
task- the task to be executed. Must not be null.
-
DeferredFutureTask
public DeferredFutureTask(DeferredCallable<D,P> task)
Creates a newDeferredFutureTaskwith the given task. The given task may implement theCancellationHandlerinterface.- Parameters:
task- the task to be executed. Must not be null.
-
DeferredFutureTask
public DeferredFutureTask(DeferredRunnable<P> task)
Creates a newDeferredFutureTaskwith the given task. The given task may implement theCancellationHandlerinterface.- Parameters:
task- the task to be executed. Must not be null.
-
DeferredFutureTask
public DeferredFutureTask(java.util.concurrent.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.- Parameters:
task- the task to be executed. Must not be null.cancellationHandler- theCancellationHandlerto invoke during onCancel. May be null.- Since:
- 2.0
-
DeferredFutureTask
public DeferredFutureTask(java.lang.Runnable task, CancellationHandler cancellationHandler)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
public 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.- Parameters:
task- the task to be executed. Must not be null.cancellationHandler- theCancellationHandlerto invoke during onCancel. May be null.- Since:
- 2.0
-
DeferredFutureTask
public 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.- Parameters:
task- the task to be executed. Must not be null.cancellationHandler- theCancellationHandlerto invoke during onCancel. May be null.- Since:
- 2.0
-
-
Method Detail
-
done
protected void done()
- Overrides:
donein classjava.util.concurrent.FutureTask<D>
-
causeOf
protected java.lang.Throwable causeOf(java.lang.Exception e)
-
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
public DeferredManager.StartPolicy getStartPolicy()
-
-