Class ForwardingFuture<V>
-
- com.google.common.collect.ForwardingObject
-
- com.google.common.util.concurrent.ForwardingFuture<V>
-
- All Implemented Interfaces:
<V>
- Direct Known Subclasses:
ForwardingFuture.SimpleForwardingFuture
,ForwardingListenableFuture
@GwtCompatible public abstract class ForwardingFuture<V> extends ForwardingObject implements <V>
A 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 .Most subclasses can just use
ForwardingFuture.SimpleForwardingFuture
.- Since:
- 1.0
- Author:
- Sven Mawson
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ForwardingFuture.SimpleForwardingFuture<V>
A simplified version ofForwardingFuture
where subclasses can pass in an already constructed as the delegate.
-
Constructor Summary
Constructors Modifier Constructor Description protected
ForwardingFuture()
Constructor for use by subclasses.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description boolean
cancel(boolean mayInterruptIfRunning)
Attempts to cancel execution of this task.protected abstract <? extends V>
delegate()
Returns the backing delegate instance that methods are forwarded to.V
get()
Waits if necessary for the computation to complete, and then retrieves its result.V
get(long timeout, unit)
Waits if necessary for at most the given time for the computation to complete, and then retrieves its result, if available.boolean
isCancelled()
Returnstrue
if this task was cancelled before it completed normally.boolean
isDone()
Returnstrue
if 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 <? extends V> delegate()
Description copied from class:ForwardingObject
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 asForwardingSet.delegate()
. Concrete subclasses override this method to supply the instance being decorated.- Specified by:
delegate
in classForwardingObject
-
cancel
public boolean cancel(boolean mayInterruptIfRunning)
Description copied from interface:Attempts 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 whencancel
is called, this task should never run. If the task has already started, then themayInterruptIfRunning
parameter determines whether the thread executing this task should be interrupted in an attempt to stop the task.After this method returns, subsequent calls to will always return
true
. Subsequent calls to will always returntrue
if this method returnedtrue
.- Specified by:
in interface
<V>
- Parameters:
mayInterruptIfRunning
-true
if the thread executing this task should be interrupted; otherwise, in-progress tasks are allowed to complete- Returns:
false
if the task could not be cancelled, typically because it has already completed normally;true
otherwise
-
isCancelled
public boolean isCancelled()
Description copied from interface:Returnstrue
if this task was cancelled before it completed normally.- Specified by:
in interface
<V>
- Returns:
true
if this task was cancelled before it completed
-
isDone
public boolean isDone()
Description copied from interface:Returnstrue
if this task completed. Completion may be due to normal termination, an exception, or cancellation -- in all of these cases, this method will returntrue
.- Specified by:
in interface
<V>
- Returns:
true
if this task completed
-
get
public V get() throws ,
Description copied from interface:Waits if necessary for the computation to complete, and then retrieves its result.- Specified by:
in interface
<V>
- Returns:
- the computed result
- Throws:
- if the current thread was interrupted while waiting
- if the computation threw an exception
-
get
public V get(long timeout, unit) throws , ,
Description copied from interface:Waits if necessary for at most the given time for the computation to complete, and then retrieves its result, if available.- Specified by:
in interface
<V>
- Parameters:
timeout
- the maximum time to waitunit
- the time unit of the timeout argument- Returns:
- the computed result
- Throws:
- if the current thread was interrupted while waiting
- if the computation threw an exception
- if the wait timed out
-
-