T
- The result object type returned by this futurepublic class ImmediateFailureListenableFuture<T>
extends java.lang.Object
ListenableFuture
that will immediately provide a failure
condition. Meaning listeners added will immediately be ran/executed, FutureCallback
's
will immediately get called with the throwable provided, and get()
will immediately
throw an ExecutionException
.ListenableFuture.ListenerOptimizationStrategy
Constructor and Description |
---|
ImmediateFailureListenableFuture(java.lang.Throwable failure)
Constructs a completed future with the provided failure.
|
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,
ListenableFuture.ListenerOptimizationStrategy optimize)
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,
ListenableFuture.ListenerOptimizationStrategy optimize)
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
addCallback, addListener, flatMap, flatMap, flatMap, map, map, map
public ImmediateFailureListenableFuture(java.lang.Throwable failure)
null
, a
new Exception
will be created to represent it.failure
- to be the cause of the ExecutionException from get()
callspublic 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.ListenerOptimizationStrategy optimize)
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.
Caution should be used when choosing to optimize the listener execution. If the listener is
complex, or wanting to be run concurrent, this optimization could prevent that. In addition
it will prevent other listeners from potentially being invoked until it completes. However
if the listener is small / fast, this can provide significant performance gains. It should
also be known that not all ListenableFuture
implementations may be able to do such an
optimization. Please see ListenableFuture.ListenerOptimizationStrategy
javadocs for more specific
details of what optimizations are available.
callback
- to be invoked when the computation is completeexecutor
- Executor
the callback should be ran on, or null
optimize
- true
to avoid listener queuing for execution if already on the desired poolpublic T get() throws java.util.concurrent.ExecutionException
java.util.concurrent.ExecutionException
public T get(long timeout, java.util.concurrent.TimeUnit unit) throws java.util.concurrent.ExecutionException
java.util.concurrent.ExecutionException
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.ListenerOptimizationStrategy optimize)
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.
Caution should be used when choosing to optimize the listener execution. If the listener is
complex, or wanting to be run concurrent, this optimization could prevent that. In addition
it will prevent other listeners from potentially being invoked until it completes. However
if the listener is small / fast, this can provide significant performance gains. It should
also be known that not all ListenableFuture
implementations may be able to do such an
optimization. Please see ListenableFuture.ListenerOptimizationStrategy
javadocs for more specific
details of what optimizations are available.
addListener
in interface ListenableFuture<T>
listener
- the listener to run when the computation is completeexecutor
- Executor
the listener should be ran on, or null
optimize
- true
to avoid listener queuing for execution if already on the desired poolpublic 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>