public class ListenableFutureTask<T> extends java.util.concurrent.FutureTask<T> implements ListenableFuture<T>
FutureTask
that implements ListenableFuture
.Modifier and Type | Field and Description |
---|---|
private ListenableFutureCallbackRegistry<T> |
callbacks |
Constructor and Description |
---|
ListenableFutureTask(java.util.concurrent.Callable<T> callable)
Create a new
ListenableFutureTask that will, upon running,
execute the given Callable . |
ListenableFutureTask(java.lang.Runnable runnable,
T result)
Create a
ListenableFutureTask that will, upon running,
execute the given Runnable , and arrange that FutureTask.get()
will return the given result on successful completion. |
Modifier and Type | Method and Description |
---|---|
void |
addCallback(ListenableFutureCallback<? super T> callback)
Register the given
ListenableFutureCallback . |
void |
addCallback(SuccessCallback<? super T> successCallback,
FailureCallback failureCallback)
Java 8 lambda-friendly alternative with success and failure callbacks.
|
protected void |
done() |
cancel, get, get, isCancelled, isDone, run, runAndReset, set, setException
private final ListenableFutureCallbackRegistry<T> callbacks
public ListenableFutureTask(java.util.concurrent.Callable<T> callable)
ListenableFutureTask
that will, upon running,
execute the given Callable
.callable
- the callable taskpublic ListenableFutureTask(java.lang.Runnable runnable, T result)
ListenableFutureTask
that will, upon running,
execute the given Runnable
, and arrange that FutureTask.get()
will return the given result on successful completion.runnable
- the runnable taskresult
- the result to return on successful completionpublic void addCallback(ListenableFutureCallback<? super T> callback)
ListenableFuture
ListenableFutureCallback
.addCallback
in interface ListenableFuture<T>
callback
- the callback to registerpublic void addCallback(SuccessCallback<? super T> successCallback, FailureCallback failureCallback)
ListenableFuture
addCallback
in interface ListenableFuture<T>
successCallback
- the success callbackfailureCallback
- the failure callbackprotected void done()
done
in class java.util.concurrent.FutureTask<T>