@CanIgnoreReturnValue @GwtCompatible public abstract class ForwardingFuture<V> extends ForwardingObject implements Future<V>
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 ForwardingFuture.SimpleForwardingFuture
.
Modifier and Type | Class and Description |
---|---|
static class |
ForwardingFuture.SimpleForwardingFuture<V>
A simplified version of
ForwardingFuture where subclasses can pass in an already
constructed Future as the delegate. |
Modifier | Constructor and Description |
---|---|
protected |
ForwardingFuture()
Constructor for use by subclasses.
|
Modifier and Type | Method and Description |
---|---|
boolean |
cancel(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.
|
V |
get()
Waits if necessary for the computation to complete, and then
retrieves its result.
|
V |
get(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.
|
boolean |
isCancelled()
Returns
true if this task was cancelled before it completed
normally. |
boolean |
isDone()
Returns
true if this task completed. |
toString
protected ForwardingFuture()
protected abstract Future<? extends V> delegate()
ForwardingObject
ForwardingSet.delegate()
. Concrete subclasses override this method to supply the
instance being decorated.delegate
in class ForwardingObject
public boolean cancel(boolean mayInterruptIfRunning)
java.util.concurrent.Future
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 should be interrupted in
an attempt to stop the task.
After this method returns, subsequent calls to Future.isDone()
will
always return true
. Subsequent calls to Future.isCancelled()
will always return true
if this method returned true
.
cancel
in interface Future<V>
mayInterruptIfRunning
- true
if the thread executing this
task should be interrupted; otherwise, in-progress tasks are allowed
to completefalse
if the task could not be cancelled,
typically because it has already completed normally;
true
otherwisepublic boolean isCancelled()
java.util.concurrent.Future
true
if this task was cancelled before it completed
normally.isCancelled
in interface Future<V>
true
if this task was cancelled before it completedpublic boolean isDone()
java.util.concurrent.Future
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
.public V get() throws InterruptedException, ExecutionException
java.util.concurrent.Future
get
in interface Future<V>
InterruptedException
- if the current thread was interrupted
while waitingExecutionException
- if the computation threw an
exceptionpublic V get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException
java.util.concurrent.Future
get
in interface Future<V>
timeout
- the maximum time to waitunit
- the time unit of the timeout argumentInterruptedException
- if the current thread was interrupted
while waitingExecutionException
- if the computation threw an
exceptionTimeoutException
- if the wait timed outCopyright © 2010–2019. All rights reserved.