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>
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 Details

    • create

      public static <V> SettableFuture<V> create()
      Creates a new SettableFuture.
      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 be null.
      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.
      Specified by:
      cancel in interface Future<V>
      Parameters:
      mayInterruptIfRunning - ignored.
      Returns:
      true if the future is now cancelled, false if the future has already been completed.
    • isCancelled

      public boolean isCancelled()
      Specified by:
      isCancelled in interface Future<V>
    • isDone

      public boolean isDone()
      Specified by:
      isDone in interface Future<V>
    • get

      Specified by:
      get in interface Future<V>
      Throws:
      InterruptedException
      ExecutionException
    • get

      public V get(long timeout, @NonNull TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException
      Specified by:
      get in interface Future<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 the 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.
      Specified by:
      addListener in interface ListenableFuture<V>
      Parameters:
      listener - the listener to execute.
      executor - the executor to run the listener in.