Class ForwardingListenableFuture<V extends @Nullable Object>
- All Implemented Interfaces:
ListenableFuture<V>,Future<V>
- Direct Known Subclasses:
ForwardingListenableFuture.SimpleForwardingListenableFuture
ListenableFuture which forwards all its method calls to another future. Subclasses
should override one or more methods to modify the behavior of the backing future as desired per
the decorator pattern.
Most subclasses can just use SimpleForwardingListenableFuture.
- Since:
- 4.0
- Author:
- Shardul Deo
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classForwardingListenableFuture.SimpleForwardingListenableFuture<V extends @Nullable Object>A simplified version ofForwardingListenableFuturewhere subclasses can pass in an already constructedListenableFutureas the delegate.Nested classes/interfaces inherited from class dev.mccue.guava.concurrent.ForwardingFuture
ForwardingFuture.SimpleForwardingFuture<V extends @Nullable Object> -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedConstructor for use by subclasses. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddListener(Runnable listener, Executor exec) Registers a listener to beExecutor#execute(Runnable) runon the given executor.protected abstract ListenableFuture<? extends V>delegate()Methods inherited from class dev.mccue.guava.concurrent.ForwardingFuture
cancel, get, get, isCancelled, isDoneMethods inherited from class dev.mccue.guava.collect.ForwardingObject
toString
-
Constructor Details
-
ForwardingListenableFuture
protected ForwardingListenableFuture()Constructor for use by subclasses.
-
-
Method Details
-
delegate
- Specified by:
delegatein classForwardingFuture<V extends @Nullable Object>
-
addListener
Description copied from interface:ListenableFutureRegisters a listener to beExecutor#execute(Runnable) runon the given executor. The listener will run when theFuture's computation isFuture#isDone() completeor, if the computation is already complete, immediately.There is no guaranteed ordering of execution of listeners, but any listener added through this method is guaranteed to be called once the computation is complete.
Exceptions thrown by a listener will be propagated up to the executor. Any exception thrown during
Executor.execute(e.g., aRejectedExecutionExceptionor an exception thrown byMoreExecutors#directExecutor direct execution) will be caught and logged.Note: If your listener is lightweight -- and will not cause stack overflow by completing more futures or adding more
directExecutor()listeners inline -- considerMoreExecutors#directExecutor. Otherwise, avoid it: See the warnings on the docs fordirectExecutor.This is the most general listener interface. For common operations performed using listeners, see
Futures. For a simplified but general listener interface, seeFutures#addCallback addCallback().Memory consistency effects: Actions in a thread prior to adding a listener happen-before its execution begins, perhaps in another thread.
Guava implementations of
ListenableFuturepromptly release references to listeners after executing them.- Specified by:
addListenerin interfaceListenableFuture<V extends @Nullable Object>- Parameters:
listener- the listener to run when the computation is completeexec- the executor to run the listener in
-