public final class SettableFuture<V> extends Object implements ListenableFuture<V>
Future that can be completed.
Inspired by com.google.common.util.concurrent.SettableFuture which we cannot use in remoting because we
need to keep external dependencies to a minimum.
| Modifier and Type | Method and Description |
|---|---|
void |
addListener(Runnable listener,
Executor executor)
Registers a listener to be run.
|
boolean |
cancel(boolean mayInterruptIfRunning)
Completes the future by cancellation.
|
static <V> SettableFuture<V> |
create()
Creates a new
SettableFuture. |
V |
get() |
V |
get(long timeout,
TimeUnit unit) |
boolean |
isCancelled() |
boolean |
isDone() |
boolean |
set(V value)
Completes the future with the supplied value.
|
boolean |
setException(Throwable throwable)
Completes the future with the supplied exception.
|
public static <V> SettableFuture<V> create()
SettableFuture.V - generic type of value.SettableFuture.public boolean set(@Nullable V value)
value - the value (may be null.true if the future is now completed, false if the future has already been completed.public boolean setException(@Nonnull Throwable throwable)
throwable - the exception.true if the future is now completed, false if the future has already been completed.public boolean cancel(boolean mayInterruptIfRunning)
public boolean isCancelled()
isCancelled in interface Future<V>public V get() throws InterruptedException, ExecutionException
get in interface Future<V>InterruptedExceptionExecutionExceptionpublic V get(long timeout, @Nonnull TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException
get in interface Future<V>InterruptedExceptionExecutionExceptionTimeoutExceptionpublic void addListener(@Nonnull Runnable listener, @Nonnull Executor executor)
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(Runnable)
(e.g., a RejectedExecutionException or an exception thrown by direct execution) will be caught and
logged.addListener in interface ListenableFuture<V>listener - the listener to execute.executor - the executor to run the listener in.Copyright © 2004–2018. All rights reserved.