Package org.jenkinsci.remoting.util
Class SettableFuture<V>
java.lang.Object
org.jenkinsci.remoting.util.SettableFuture<V>
- All Implemented Interfaces:
Future<V>,Future<V>,ListenableFuture<V>
A
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.
- Since:
- 3.0
-
Method Summary
Modifier and TypeMethodDescriptionvoidaddListener(Runnable listener, Executor executor) Registers a listener to be run.booleancancel(boolean mayInterruptIfRunning) Completes the future by cancellation.static <V> SettableFuture<V> create()Creates a newSettableFuture.get()booleanbooleanisDone()booleanCompletes the future with the supplied value.booleansetException(Throwable throwable) Completes the future with the supplied exception.
-
Method Details
-
create
Creates a newSettableFuture.- Type Parameters:
V- generic type of value.- Returns:
- a new
SettableFuture.
-
set
Completes the future with the supplied value.- Parameters:
value- the value (may benull.- Returns:
trueif the future is now completed,falseif the future has already been completed.
-
setException
Completes the future with the supplied exception.- Parameters:
throwable- the exception.- Returns:
trueif the future is now completed,falseif the future has already been completed.
-
cancel
public boolean cancel(boolean mayInterruptIfRunning) Completes the future by cancellation. -
isCancelled
public boolean isCancelled()- Specified by:
isCancelledin interfaceFuture<V>
-
isDone
public boolean isDone() -
get
- Specified by:
getin interfaceFuture<V>- Throws:
InterruptedExceptionExecutionException
-
get
public V get(long timeout, @NonNull TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException - Specified by:
getin interfaceFuture<V>- Throws:
InterruptedExceptionExecutionExceptionTimeoutException
-
addListener
Registers a listener to be run. The listener will be run on the specified executor either when theFuture'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 duringExecutor.execute(Runnable)(e.g., aRejectedExecutionExceptionor an exception thrown by direct execution) will be caught and logged.- Specified by:
addListenerin interfaceListenableFuture<V>- Parameters:
listener- the listener to execute.executor- the executor to run the listener in.
-