Class ForwardingFuture<V>
- java.lang.Object
-
- com.google.common.collect.ForwardingObject
-
- com.google.common.util.concurrent.ForwardingFuture<V>
-
- All Implemented Interfaces:
Future<V>
- Direct Known Subclasses:
ForwardingFuture.SimpleForwardingFuture,ForwardingListenableFuture
@CanIgnoreReturnValue @GwtCompatible public abstract class ForwardingFuture<V> extends ForwardingObject implements Future<V>
AFuturewhich 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
ForwardingFuture.SimpleForwardingFuture.- Since:
- 1.0
- Author:
- Sven Mawson
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classForwardingFuture.SimpleForwardingFuture<V>A simplified version ofForwardingFuturewhere subclasses can pass in an already constructedFutureas the delegate.
-
Constructor Summary
Constructors Modifier Constructor Description protectedForwardingFuture()Constructor for use by subclasses.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description booleancancel(boolean mayInterruptIfRunning)Attempts to cancel execution of this task.protected abstract Future<? extends V>delegate()Returns the backing delegate instance that methods are forwarded to.Vget()Waits if necessary for the computation to complete, and then retrieves its result.Vget(long timeout, TimeUnit unit)Waits if necessary for at most the given time for the computation to complete, and then retrieves its result, if available.booleanisCancelled()Returnstrueif this task was cancelled before it completed normally.booleanisDone()Returnstrueif this task completed.-
Methods inherited from class com.google.common.collect.ForwardingObject
toString
-
-
-
-
Constructor Detail
-
ForwardingFuture
protected ForwardingFuture()
Constructor for use by subclasses.
-
-
Method Detail
-
delegate
protected abstract Future<? extends V> delegate()
Description copied from class:ForwardingObjectReturns 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 asForwardingSet.delegate(). Concrete subclasses override this method to supply the instance being decorated.- Specified by:
delegatein classForwardingObject
-
cancel
public boolean cancel(boolean mayInterruptIfRunning)
Description copied from interface:java.util.concurrent.FutureAttempts to cancel execution of this task. This attempt will fail if the task has already completed, has already been cancelled, or could not be cancelled for some other reason. If successful, and this task has not started whencancelis called, this task should never run. If the task has already started, then themayInterruptIfRunningparameter determines whether the thread executing this task should be interrupted in an attempt to stop the task.After this method returns, subsequent calls to
Future.isDone()will always returntrue. Subsequent calls toFuture.isCancelled()will always returntrueif this method returnedtrue.- Specified by:
cancelin interfaceFuture<V>- Parameters:
mayInterruptIfRunning-trueif the thread executing this task should be interrupted; otherwise, in-progress tasks are allowed to complete- Returns:
falseif the task could not be cancelled, typically because it has already completed normally;trueotherwise
-
isCancelled
public boolean isCancelled()
Description copied from interface:java.util.concurrent.FutureReturnstrueif this task was cancelled before it completed normally.- Specified by:
isCancelledin interfaceFuture<V>- Returns:
trueif this task was cancelled before it completed
-
isDone
public boolean isDone()
Description copied from interface:java.util.concurrent.FutureReturnstrueif this task completed. Completion may be due to normal termination, an exception, or cancellation -- in all of these cases, this method will returntrue.
-
get
public V get() throws InterruptedException, ExecutionException
Description copied from interface:java.util.concurrent.FutureWaits if necessary for the computation to complete, and then retrieves its result.- Specified by:
getin interfaceFuture<V>- Returns:
- the computed result
- Throws:
InterruptedException- if the current thread was interrupted while waitingExecutionException- if the computation threw an exception
-
get
public V get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException
Description copied from interface:java.util.concurrent.FutureWaits if necessary for at most the given time for the computation to complete, and then retrieves its result, if available.- Specified by:
getin interfaceFuture<V>- Parameters:
timeout- the maximum time to waitunit- the time unit of the timeout argument- Returns:
- the computed result
- Throws:
InterruptedException- if the current thread was interrupted while waitingExecutionException- if the computation threw an exceptionTimeoutException- if the wait timed out
-
-