class ImmediateFuture<V> extends java.lang.Object implements ListenableFuture<V>
Futures.immediateFuture(V)
.Modifier and Type | Class and Description |
---|---|
(package private) static class |
ImmediateFuture.ImmediateCancelledFuture<V> |
(package private) static class |
ImmediateFuture.ImmediateFailedFuture<V> |
Modifier and Type | Field and Description |
---|---|
private static java.util.logging.Logger |
log |
(package private) static ListenableFuture<?> |
NULL |
private V |
value |
Constructor and Description |
---|
ImmediateFuture(V value) |
Modifier and Type | Method and Description |
---|---|
void |
addListener(java.lang.Runnable listener,
java.util.concurrent.Executor executor)
Registers a listener to be run on the given executor.
|
boolean |
cancel(boolean mayInterruptIfRunning) |
V |
get() |
V |
get(long timeout,
java.util.concurrent.TimeUnit unit) |
boolean |
isCancelled() |
boolean |
isDone() |
java.lang.String |
toString() |
static final ListenableFuture<?> NULL
private static final java.util.logging.Logger log
private final V value
ImmediateFuture(V value)
public void addListener(java.lang.Runnable listener, java.util.concurrent.Executor executor)
ListenableFuture
Future
's computation is complete or, if the computation is already complete, immediately.
There is no guaranteed ordering of execution of listeners, but any listener added through this method is guaranteed to be called once the computation is complete.
Exceptions thrown by a listener will be propagated up to the executor. Any exception thrown
during Executor.execute
(e.g., a RejectedExecutionException
or an exception
thrown by direct execution) will be caught and
logged.
Note: If your listener is lightweight -- and will not cause stack overflow by completing
more futures or adding more directExecutor()
listeners inline -- consider MoreExecutors.directExecutor()
. Otherwise, avoid it: See the warnings on the docs for directExecutor
.
This is the most general listener interface. For common operations performed using
listeners, see Futures
. For a simplified but general listener interface, see addCallback()
.
Memory consistency effects: Actions in a thread prior to adding a listener happen-before its execution begins, perhaps in another thread.
Guava implementations of ListenableFuture
promptly release references to listeners
after executing them.
addListener
in interface ListenableFuture<V>
listener
- the listener to run when the computation is completeexecutor
- the executor to run the listener inpublic boolean cancel(boolean mayInterruptIfRunning)
cancel
in interface java.util.concurrent.Future<V>
public V get(long timeout, java.util.concurrent.TimeUnit unit) throws java.util.concurrent.ExecutionException
get
in interface java.util.concurrent.Future<V>
java.util.concurrent.ExecutionException
public boolean isCancelled()
isCancelled
in interface java.util.concurrent.Future<V>
public boolean isDone()
isDone
in interface java.util.concurrent.Future<V>
public java.lang.String toString()
toString
in class java.lang.Object