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 aroundCallable
andRunnable
. In these two cases, a newDeferred
object will be created. This class will overrideFutureTask.done()
to trigger the appropriateDeferred
actions.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 ofCancellationException
If any Exception occurred,Deferred.reject(Object)
will be called with the Exception instance.
-
-
Field Summary
Fields Modifier and Type Field Description private CancellationHandler
cancellationHandler
protected Deferred<D,java.lang.Throwable,P>
deferred
private static org.slf4j.Logger
LOG
protected DeferredManager.StartPolicy
startPolicy
private java.lang.Object
taskDelegate
-
Constructor Summary
Constructors Constructor Description DeferredFutureTask(java.lang.Runnable task)
Creates a newDeferredFutureTask
with the given task.DeferredFutureTask(java.lang.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(java.util.concurrent.Callable<D> task)
Creates a newDeferredFutureTask
with the given task.DeferredFutureTask(java.util.concurrent.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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.lang.Throwable
causeOf(java.lang.Exception e)
protected void
cleanup()
Performs resource cleanup upon interruption or cancellation of the underlying task.protected void
done()
DeferredManager.StartPolicy
getStartPolicy()
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 newDeferredFutureTask
with the given task. The given task may implement theCancellationHandler
interface.- Parameters:
task
- the task to be executed. Must not be null.
-
DeferredFutureTask
public DeferredFutureTask(java.lang.Runnable task)
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
public DeferredFutureTask(DeferredCallable<D,P> task)
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
public DeferredFutureTask(DeferredRunnable<P> task)
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
public DeferredFutureTask(java.util.concurrent.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.- Parameters:
task
- the task to be executed. Must not be null.cancellationHandler
- theCancellationHandler
to invoke during onCancel. May be null.- Since:
- 2.0
-
DeferredFutureTask
public DeferredFutureTask(java.lang.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.- Parameters:
task
- the task to be executed. Must not be null.cancellationHandler
- theCancellationHandler
to invoke during onCancel. May be null.- Since:
- 2.0
-
DeferredFutureTask
public 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.- Parameters:
task
- the task to be executed. Must not be null.cancellationHandler
- theCancellationHandler
to invoke during onCancel. May be null.- Since:
- 2.0
-
DeferredFutureTask
public 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.- Parameters:
task
- the task to be executed. Must not be null.cancellationHandler
- theCancellationHandler
to invoke during onCancel. May be null.- Since:
- 2.0
-
-
Method Detail
-
done
protected void done()
- Overrides:
done
in 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 tocancellationHandler
it not null, otherwise it invokes the underlying task'sonCancel()
if it implements theCancellationHandler
interface.- Since:
- 2.0
-
getStartPolicy
public DeferredManager.StartPolicy getStartPolicy()
-
-