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

public abstract Class ForwardingFuture<V extends @Nullable Object>

extends ForwardingObject
implements Future<V extends @Nullable Object>
Class Inheritance
All Implemented Interfaces
java.util.concurrent.Future
Known Direct Subclasses
com.google.common.util.concurrent.ForwardingFuture.SimpleForwardingFuture, com.google.common.util.concurrent.ForwardingListenableFuture, com.google.common.util.concurrent.JdkFutureAdapters.ListenableFutureAdapter
Annotations
@GwtCompatible
@ElementTypesAreNonnullByDefault
Imports
com.google.common.annotations.GwtCompatible, com.google.common.base.Preconditions, com.google.common.collect.ForwardingObject, com.google.errorprone.annotations.CanIgnoreReturnValue, java.util.concurrent.ExecutionException, .Future, .TimeUnit, .TimeoutException, org.checkerframework.checker.nullness.qual.Nullable

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

Author
Sven Mawson
Since
1.0

Nested and Inner Type Summary

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

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

Constructor Summary

AccessConstructor and Description
protected
ForwardingFuture()

Constructor for use by subclasses.

Method Summary

Modifier and TypeMethod and Description
public boolean
cancel(boolean
true if the thread executing this task should be interrupted (if the thread is known to the implementation); otherwise, in-progress tasks are allowed to complete
mayInterruptIfRunning
)

Implements java.util.concurrent.Future.cancel.

Attempts to cancel execution of this task.
protected abstract Future<? extends V>
delegate()

Implements abstract com.google.common.collect.ForwardingObject.delegate.

Returns the backing delegate instance that methods are forwarded to.
public V
get()

Implements java.util.concurrent.Future.get.

Waits if necessary for the computation to complete, and then retrieves its result.
public V
get(long
the maximum time to wait
timeout
,
TimeUnit
the time unit of the timeout argument
unit
)

Implements java.util.concurrent.Future.get.

Waits if necessary for at most the given time for the computation to complete, and then retrieves its result, if available.
public boolean
isCancelled()

Implements java.util.concurrent.Future.isCancelled.

Returns true if this task was cancelled before it completed normally.
public boolean
isDone()

Implements java.util.concurrent.Future.isDone.

Returns true if this task completed.
Inherited from com.google.common.collect.ForwardingObject:
toString

Constructor Detail

ForwardingFutureback to summary
protected ForwardingFuture()

Constructor for use by subclasses.

Method Detail

cancelback to summary
public boolean cancel(boolean mayInterruptIfRunning)

Implements java.util.concurrent.Future.cancel.

Doc from java.util.concurrent.Future.cancel.

Attempts to cancel execution of this task. This method has no effect if the task is already completed or cancelled, or could not be cancelled for some other reason. Otherwise, if this task has not started when cancel is called, this task should never run. If the task has already started, then the mayInterruptIfRunning parameter determines whether the thread executing this task (when known by the implementation) is interrupted in an attempt to stop the task.

The return value from this method does not necessarily indicate whether the task is now cancelled; use isCancelled.

Parameters
mayInterruptIfRunning:boolean

true if the thread executing this task should be interrupted (if the thread is known to the implementation); otherwise, in-progress tasks are allowed to complete

Returns:boolean

false if the task could not be cancelled, typically because it has already completed; true otherwise. If two or more threads cause a task to be cancelled, then at least one of them returns true. Implementations may provide stronger guarantees.

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

Implements abstract com.google.common.collect.ForwardingObject.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
getback to summary
public V get() throws InterruptedException, ExecutionException

Implements java.util.concurrent.Future.get.

Doc from java.util.concurrent.Future.get.

Waits if necessary for the computation to complete, and then retrieves its result.

Returns:V

the computed result

Annotations
@Override
@CanIgnoreReturnValue
@ParametricNullness
Exceptions
InterruptedException:
if the current thread was interrupted while waiting
ExecutionException:
if the computation threw an exception
getback to summary
public V get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException

Implements java.util.concurrent.Future.get.

Doc from java.util.concurrent.Future.get.

Waits if necessary for at most the given time for the computation to complete, and then retrieves its result, if available.

Parameters
timeout:long

the maximum time to wait

unit:TimeUnit

the time unit of the timeout argument

Returns:V

the computed result

Annotations
@Override
@CanIgnoreReturnValue
@ParametricNullness
Exceptions
InterruptedException:
if the current thread was interrupted while waiting
ExecutionException:
if the computation threw an exception
TimeoutException:
if the wait timed out
isCancelledback to summary
public boolean isCancelled()

Implements java.util.concurrent.Future.isCancelled.

Doc from java.util.concurrent.Future.isCancelled.

Returns true if this task was cancelled before it completed normally.

Returns:boolean

true if this task was cancelled before it completed

Annotations
@Override
isDoneback to summary
public boolean isDone()

Implements java.util.concurrent.Future.isDone.

Doc from java.util.concurrent.Future.isDone.

Returns true if this task completed. Completion may be due to normal termination, an exception, or cancellation -- in all of these cases, this method will return true.

Returns:boolean

true if this task completed

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

public abstract Class ForwardingFuture.SimpleForwardingFuture<V extends @Nullable Object>

extends ForwardingFuture<V extends @Nullable Object>
Class Inheritance

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

Field Summary

Modifier and TypeField and Description
private final Future<V>

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
protected final Future<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

Field Detail

delegateback to summary
private final Future<V> delegate

Constructor Detail

SimpleForwardingFutureback to summary
protected SimpleForwardingFuture(Future<V> delegate)

Method Detail

delegateback to summary
protected final Future<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