Top Description Inners Constructors Methods
com.google.common.util.concurrent

public abstract Class ForwardingListenableFuture<V extends @Nullable Object>

extends ForwardingFuture<V extends @Nullable Object>
implements ListenableFuture<V extends @Nullable Object>
Class Inheritance
All Implemented Interfaces
com.google.common.util.concurrent.ListenableFuture, java.util.concurrent.Future
Known Direct Subclasses
com.google.common.util.concurrent.ForwardingListenableFuture.SimpleForwardingListenableFuture
Annotations
@GwtCompatible
@ElementTypesAreNonnullByDefault
Imports
com.google.common.annotations.GwtCompatible, com.google.common.base.Preconditions, java.util.concurrent.Executor, org.checkerframework.checker.nullness.qual.Nullable

A 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.

Author
Shardul Deo
Since
4.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
public abstract static class
ForwardingListenableFuture.SimpleForwardingListenableFuture<V extends @Nullable Object>

A simplified version of ForwardingListenableFuture where subclasses can pass in an already constructed ListenableFuture as the delegate.

Constructor Summary

AccessConstructor and Description
protected
ForwardingListenableFuture()

Constructor for use by subclasses.

Method Summary

Modifier and TypeMethod and Description
public void
addListener(Runnable
the listener to run when the computation is complete
listener
,
Executor
the executor to run the listener in
exec
)

Implements com.google.common.util.concurrent.ListenableFuture.addListener.

Registers a listener to be run on the given executor.
protected abstract ListenableFuture<? extends V>
delegate()

Implements abstract com.google.common.util.concurrent.ForwardingFuture.delegate.

Returns the backing delegate instance that methods are forwarded to.
Inherited from com.google.common.util.concurrent.ForwardingFuture:
cancelgetgetisCancelledisDone

Constructor Detail

ForwardingListenableFutureback to summary
protected ForwardingListenableFuture()

Constructor for use by subclasses.

Method Detail

addListenerback to summary
public void addListener(Runnable listener, Executor exec)

Implements com.google.common.util.concurrent.ListenableFuture.addListener.

Doc from com.google.common.util.concurrent.ListenableFuture.addListener.

Registers a listener to be run on the given executor. The listener will run when the Future's computation is complete or, 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., a RejectedExecutionException or an exception thrown by 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 -- consider MoreExecutors#directExecutor. Otherwise, avoid it: See the warnings on the docs for directExecutor.

This is the most general listener interface. For common operations performed using listeners, see Futures. For a simplified but general listener interface, see 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 ListenableFuture promptly release references to listeners after executing them.

Parameters
listener:Runnable

the listener to run when the computation is complete

exec:Executor

the executor to run the listener in

Annotations
@Override
delegateback to summary
protected abstract ListenableFuture<? extends V> delegate()

Implements abstract com.google.common.util.concurrent.ForwardingFuture.delegate.

Doc from com.google.common.collect.ForwardingObject.delegate.

Returns the backing delegate instance that methods are forwarded to. Abstract subclasses generally override this method with an abstract method that has a more specific return type, such as ForwardingSet#delegate. Concrete subclasses override this method to supply the instance being decorated.

Annotations
@Override
com.google.common.util.concurrent back to summary

public abstract Class ForwardingListenableFuture.SimpleForwardingListenableFuture<V extends @Nullable Object>

extends ForwardingListenableFuture<V extends @Nullable Object>
Class Inheritance
Known Direct Subclasses
com.google.common.util.concurrent.MoreExecutors.ScheduledListeningDecorator.ListenableScheduledTask

A simplified version of ForwardingListenableFuture where subclasses can pass in an already constructed ListenableFuture as the delegate.
Since
9.0

Field Summary

Modifier and TypeField and Description
private final ListenableFuture<V>

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
protected final ListenableFuture<V>
delegate()

Implements abstract com.google.common.util.concurrent.ForwardingListenableFuture.delegate.

Returns the backing delegate instance that methods are forwarded to.
Inherited from com.google.common.util.concurrent.ForwardingListenableFuture:
addListener

Field Detail

delegateback to summary
private final ListenableFuture<V> delegate

Constructor Detail

SimpleForwardingListenableFutureback to summary
protected SimpleForwardingListenableFuture(ListenableFuture<V> delegate)

Method Detail

delegateback to summary
protected final ListenableFuture<V> delegate()

Implements abstract com.google.common.util.concurrent.ForwardingListenableFuture.delegate.

Doc from com.google.common.collect.ForwardingObject.delegate.

Returns the backing delegate instance that methods are forwarded to. Abstract subclasses generally override this method with an abstract method that has a more specific return type, such as ForwardingSet#delegate. Concrete subclasses override this method to supply the instance being decorated.

Annotations
@Override