ListenableFuture, intended for advanced users only. More
common ways to create a ListenableFuture include instantiating a SettableFuture,
submitting a task to a ListeningExecutorService, and deriving a Future from an
existing one, typically using methods like Futures.transform and Futures.catching .
This class implements all methods in ListenableFuture. Subclasses should provide a way
to set the result of the computation through the protected methods set(Object), setFuture(ListenableFuture) and setException(Throwable). Subclasses may also override
afterDone(), which will be invoked automatically when the future completes. Subclasses
should rarely override other methods.
| Modifier and Type | Class and Description |
|---|---|
| private abstract static class | |
| private static class | AbstractFuture.Cancellation
A special value to represent cancellation and the 'wasInterrupted' bit. |
| private static class | AbstractFuture.Failure
A special value to represent failure, when |
| private static class | AbstractFuture.Listener
Listeners also form a stack through the |
| private static class | |
| private static class | AbstractFuture.SetFuture<V extends @Nullable Object>
A special value that encodes the 'setFuture' state. |
| private static class | AbstractFuture.SynchronizedHelper
|
| pack-priv static interface | |
| pack-priv abstract static class | |
| private static class | |
| private static class | AbstractFuture.Waiter
Waiter links form a Treiber stack, in the |
| Modifier and Type | Field and Description |
|---|---|
| private static final AbstractFuture. | |
| pack-priv static final boolean | |
| private volatile AbstractFuture. | listeners
All listeners. |
| private static final Logger | |
| private static final Object | NULL
A special value to represent |
| private static final long | |
| private volatile Object | value
This field encodes the current state of the future. |
| private volatile AbstractFuture. | waiters
All waiting threads. |
| Access | Constructor and Description |
|---|---|
| protected |
| Modifier and Type | Method and Description |
|---|---|
| private void | |
| public void | addListener(Runnable
the listener to run when the computation is complete listener, Executor the executor to run the listener in executor)Implements com. |
| private void | |
| protected void | |
| private void | appendResultObject(StringBuilder builder, Object o)
Any object can be the result of a Future, and not every object has a reasonable toString() implementation. |
| private void | appendUserObject(StringBuilder builder, Object o)
Helper for printing user supplied objects into our toString method. |
| 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 completeImplements java. |
| private static CancellationException | |
| private AbstractFuture. | clearListeners(AbstractFuture.
Clears the |
| private static void | complete(AbstractFuture<?> param, boolean callInterruptTask)
Unblocks all threads and runs all listeners. |
| private static void | executeListener(Runnable runnable, Executor executor)
Submits the given runnable to the given |
| public V | get(long
the maximum time to wait timeout, TimeUnit the time unit of the timeout argument unit)Implements java. |
| public V | get()
Implements java. |
| private V | |
| private static Object | getFutureValue(ListenableFuture<?> future)
Returns a value that satisfies the contract of the |
| private static <V extends @Nullable Object> V | getUninterruptibly(Future<V> future)
An inlined private copy of |
| protected void | interruptTask()
Subclasses can override this method to implement interruption of the future's computation. |
| public boolean | isCancelled()
Implements java. true if this task was cancelled before it completed
normally.
|
| public boolean | |
| pack-priv final void | maybePropagateCancellationTo(Future<?> related)
If this future has been cancelled (and possibly interrupted), cancels (and possibly interrupts) the given future (if available). |
| protected String | Returns: null if an explanation cannot be provided (e.g. because the future is done).Provide a human-readable explanation of why this future has not yet completed. |
| private void | |
| private void | removeWaiter(AbstractFuture.
Marks the given node as 'deleted' (null waiter) and then scans the list to unlink all deleted nodes. |
| protected boolean | Returns: true if the attempt was accepted, completing theFuturethe value to be used as the result value)Sets the result of this |
| protected boolean | Returns: true if the attempt was accepted, completing theFuturethe exception to be used as the failed result throwable)Sets the failed result of this |
| protected boolean | Returns: true if the attempt was accepted, indicating that theFuture was not previously
cancelled or set.the future to delegate to future)Sets the result of this |
| public String | |
| protected final Throwable | tryInternalFastPathGetFailure()
Implements abstract com. null but, if this Future has failed, may optionally
return the cause of the failure.
|
| protected final boolean |