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>
public final class SettableFuture<V> extends Object implements ListenableFuture<V>
AFuture
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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method 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 newSettableFuture
.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.
-
-
-
Method Detail
-
create
public static <V> SettableFuture<V> create()
Creates a newSettableFuture
.- Type Parameters:
V
- generic type of value.- Returns:
- a new
SettableFuture
.
-
set
public boolean set(@Nullable V value)
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
public boolean setException(@NonNull Throwable throwable)
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>
-
get
public V get() throws InterruptedException, ExecutionException
- 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
public void addListener(@NonNull Runnable listener, @NonNull Executor executor)
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.
-
-