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 TypeMethodDescriptionvoid
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 newSettableFuture
.get()
boolean
boolean
isDone()
boolean
Completes the future with the supplied value.boolean
setException
(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:
true
if the future is now completed,false
if the future has already been completed.
-
setException
Completes the future with the supplied exception.- Parameters:
throwable
- the exception.- Returns:
true
if the future is now completed,false
if the future has already been completed.
-
cancel
public boolean cancel(boolean mayInterruptIfRunning) Completes the future by cancellation. -
isCancelled
public boolean isCancelled()- Specified by:
isCancelled
in interfaceFuture<V>
-
isDone
public boolean isDone() -
get
- Specified by:
get
in interfaceFuture<V>
- Throws:
InterruptedException
ExecutionException
-
get
public V get(long timeout, @NonNull TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException - Specified by:
get
in interfaceFuture<V>
- Throws:
InterruptedException
ExecutionException
TimeoutException
-
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., aRejectedExecutionException
or an exception thrown by direct execution) will be caught and logged.- Specified by:
addListener
in interfaceListenableFuture<V>
- Parameters:
listener
- the listener to execute.executor
- the executor to run the listener in.
-