private abstract static class Futures.ImmediateFuture<V> extends java.lang.Object implements ListenableFuture<V>
Modifier and Type | Field and Description |
---|---|
private static java.util.logging.Logger |
log |
Modifier | Constructor and Description |
---|---|
private |
ImmediateFuture() |
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) |
abstract V |
get() |
V |
get(long timeout,
java.util.concurrent.TimeUnit unit) |
boolean |
isCancelled() |
boolean |
isDone() |
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: For fast, lightweight listeners that would be safe to execute in
any thread, consider MoreExecutors.directExecutor()
. For heavier
listeners, directExecutor()
carries some caveats. For
example, the listener may run on an unpredictable or undesirable thread:
Future
is done at the time addListener
is
called, addListener
will execute the listener inline.
Future
is not yet done, addListener
will
schedule the listener to be run by the thread that completes this Future
, which may be an internal system thread such as an RPC network
thread.
Also note that, regardless of which thread executes the
directExecutor()
listener, all other registered but unexecuted
listeners are prevented from running during its execution, even if those
listeners are to run in other executors.
This is the most general listener interface. For common operations
performed using listeners, see Futures
. For a simplified but general
listener interface, see addCallback()
.
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 abstract V get() throws java.util.concurrent.ExecutionException
get
in interface java.util.concurrent.Future<V>
java.util.concurrent.ExecutionException
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>