T
- The result object type returned by this futurepublic class ScheduledFutureDelegate<T> extends java.lang.Object implements ListenableScheduledFuture<T>
ListenableScheduledFuture
interface. This design delegates
between a Delayed
instance and ListenableFuture
instance.ListenableFuture.ListenerOptimizationStrategy
Constructor and Description |
---|
ScheduledFutureDelegate(ListenableFuture<? extends T> futureImp,
java.util.concurrent.Delayed delayed)
Constructs a new
ScheduledFutureDelegate with the provided instances to call to for
each interface. |
Modifier and Type | Method and Description |
---|---|
void |
addCallback(FutureCallback<? super T> callback,
java.util.concurrent.Executor executor,
ListenableFuture.ListenerOptimizationStrategy optimizeExecution)
Add a
FutureCallback to be called once the future has completed. |
void |
addListener(java.lang.Runnable listener,
java.util.concurrent.Executor executor,
ListenableFuture.ListenerOptimizationStrategy optimizeExecution)
Add a listener to be called once the future has completed.
|
boolean |
cancel(boolean mayInterruptIfRunning) |
int |
compareTo(java.util.concurrent.Delayed o) |
T |
get() |
T |
get(long timeout,
java.util.concurrent.TimeUnit unit) |
long |
getDelay(java.util.concurrent.TimeUnit unit) |
boolean |
isCancelled() |
boolean |
isDone() |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
addCallback, addCallback, addListener, addListener, flatMap, flatMap, flatMap, map, map, map
public ScheduledFutureDelegate(ListenableFuture<? extends T> futureImp, java.util.concurrent.Delayed delayed)
ScheduledFutureDelegate
with the provided instances to call to for
each interface.futureImp
- implementation to call to for all Future callsdelayed
- implementation to call to for getDelay and compareTopublic long getDelay(java.util.concurrent.TimeUnit unit)
getDelay
in interface java.util.concurrent.Delayed
public int compareTo(java.util.concurrent.Delayed o)
compareTo
in interface java.lang.Comparable<java.util.concurrent.Delayed>
public boolean cancel(boolean mayInterruptIfRunning)
cancel
in interface java.util.concurrent.Future<T>
public boolean isCancelled()
isCancelled
in interface java.util.concurrent.Future<T>
public boolean isDone()
isDone
in interface java.util.concurrent.Future<T>
public T get() throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
get
in interface java.util.concurrent.Future<T>
java.lang.InterruptedException
java.util.concurrent.ExecutionException
public T get(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException, java.util.concurrent.TimeoutException
get
in interface java.util.concurrent.Future<T>
java.lang.InterruptedException
java.util.concurrent.ExecutionException
java.util.concurrent.TimeoutException
public void addListener(java.lang.Runnable listener, java.util.concurrent.Executor executor, ListenableFuture.ListenerOptimizationStrategy optimizeExecution)
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
optimizeExecution
- true
to avoid listener queuing for execution if already on the desired poolpublic void addCallback(FutureCallback<? super T> callback, java.util.concurrent.Executor executor, ListenableFuture.ListenerOptimizationStrategy optimizeExecution)
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.
addCallback
in interface ListenableFuture<T>
callback
- to be invoked when the computation is completeexecutor
- Executor
the callback should be ran on, or null
optimizeExecution
- true
to avoid listener queuing for execution if already on the desired pool