T
- The result object type returned by this futurepublic class ImmediateResultListenableFuture<T>
extends java.lang.Object
ListenableFuture
that will immediately return a result.
Meaning listeners added will immediately be ran/executed, FutureCallback
's will
immediately get called with the result provided, and get()
calls will never block.Modifier and Type | Field and Description |
---|---|
static ImmediateResultListenableFuture<java.lang.Boolean> |
BOOLEAN_FALSE_RESULT
Static instance of
ImmediateResultListenableFuture which provides a Boolean
in the false state as the result. |
static ImmediateResultListenableFuture<java.lang.Boolean> |
BOOLEAN_TRUE_RESULT
Static instance of
ImmediateResultListenableFuture which provides a Boolean
in the true state as the result. |
static ImmediateResultListenableFuture<?> |
NULL_RESULT
Static instance of
ImmediateResultListenableFuture which provides a null
result. |
Constructor and Description |
---|
ImmediateResultListenableFuture(T result)
Constructs a completed future that will return the provided result.
|
Modifier and Type | Method and Description |
---|---|
void |
addCallback(FutureCallback<? super T> callback)
Add a
FutureCallback to be called once the future has completed. |
void |
addCallback(FutureCallback<? super T> callback,
java.util.concurrent.Executor executor)
Add a
FutureCallback to be called once the future has completed. |
void |
addListener(java.lang.Runnable listener)
Add a listener to be called once the future has completed.
|
void |
addListener(java.lang.Runnable listener,
java.util.concurrent.Executor executor)
Add a listener to be called once the future has completed.
|
boolean |
cancel(boolean mayInterruptIfRunning)
This has no effect in this implementation, as this future can not be canceled.
|
T |
get() |
T |
get(long timeout,
java.util.concurrent.TimeUnit unit) |
boolean |
isCancelled() |
boolean |
isDone() |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
flatMap, flatMap, map, map
public static final ImmediateResultListenableFuture<?> NULL_RESULT
ImmediateResultListenableFuture
which provides a null
result. Since this is a common case this can avoid GC overhead. If you want to get this in
any generic type use FutureUtils.immediateResultFuture(Object)
, which when provided a
null
will always return this static instance.public static final ImmediateResultListenableFuture<java.lang.Boolean> BOOLEAN_TRUE_RESULT
ImmediateResultListenableFuture
which provides a Boolean
in the true
state as the result.public static final ImmediateResultListenableFuture<java.lang.Boolean> BOOLEAN_FALSE_RESULT
ImmediateResultListenableFuture
which provides a Boolean
in the false
state as the result.public ImmediateResultListenableFuture(T result)
result
- Result that is returned by futurepublic void addCallback(FutureCallback<? super T> callback)
ListenableFuture
FutureCallback
to be called once the future has completed. If the future has
already finished, this will be called immediately.
The callback from this call will execute on the same thread the result was produced on, or on the adding thread if the future is already complete. If the callback has high complexity, consider passing an executor in for it to be called on.
callback
- to be invoked when the computation is completepublic void addCallback(FutureCallback<? super T> callback, java.util.concurrent.Executor executor)
ListenableFuture
FutureCallback
to be called once the future has completed. If the future has
already finished, this will be called immediately.
If the provided Executor
is null, the callback will execute on the thread which
computed the original future (once it is done). If the future has already completed, the
callback will execute immediately on the thread which is adding the callback.
callback
- to be invoked when the computation is completeexecutor
- Executor
the callback should be ran on, or null
public T get()
public T get(long timeout, java.util.concurrent.TimeUnit unit)
public boolean isDone()
isDone
in interface java.util.concurrent.Future<T>
public void addListener(java.lang.Runnable listener)
ListenableFuture
The listener from this call will execute on the same thread the result was produced on, or on
the adding thread if the future is already complete. If the runnable has high complexity,
consider using ListenableFuture.addListener(Runnable, Executor)
.
addListener
in interface ListenableFuture<T>
listener
- the listener to run when the computation is completepublic void addListener(java.lang.Runnable listener, java.util.concurrent.Executor executor)
ListenableFuture
If the provided Executor
is null, the listener will execute on the thread which
computed the original future (once it is done). If the future has already completed, the
listener will execute immediately on the thread which is adding the listener.
addListener
in interface ListenableFuture<T>
listener
- the listener to run when the computation is completeexecutor
- Executor
the listener should be ran on, or null
public boolean cancel(boolean mayInterruptIfRunning)
cancel
in interface java.util.concurrent.Future<T>
mayInterruptIfRunning
- will be ignoredfalse
, as this future can't be canceledpublic boolean isCancelled()
isCancelled
in interface java.util.concurrent.Future<T>