org.springframework.util.concurrent

## Class SettableListenableFuture<T>

- java.lang.Object
- - org.springframework.util.concurrent.SettableListenableFuture<T>

- Type Parameters:
    `T` - the result type returned by this Future's `get` method
  All Implemented Interfaces:
    Future<T>, ListenableFuture<T>

      public class SettableListenableFuture<T>
      extends Object
      implements ListenableFuture<T>

  A `ListenableFuture` whose value can be set via `set(Object)` or `setException(Throwable)`. It may also get cancelled.

  Inspired by `com.google.common.util.concurrent.SettableFuture`.

  Since:
    4.1
  Author:
    Mattias Severson, Rossen Stoyanchev, Juergen Hoeller

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `SettableListenableFuture()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addCallback(ListenableFutureCallback<? super T> callback)` Register the given `ListenableFutureCallback`.
    `void` | `addCallback(SuccessCallback<? super T> successCallback, FailureCallback failureCallback)` Java 8 lambda-friendly alternative with success and failure callbacks.
    `boolean` | `cancel(boolean mayInterruptIfRunning)`
    `CompletableFuture<T>` | `completable()` Expose this `ListenableFuture` as a JDK `CompletableFuture`.
    `T` | `get()` Retrieve the value.
    `T` | `get(long timeout, TimeUnit unit)` Retrieve the value.
    `protected void` | `interruptTask()` Subclasses can override this method to implement interruption of the future's computation.
    `boolean` | `isCancelled()`
    `boolean` | `isDone()`
    `boolean` | `set(T value)` Set the value of this future.
    `boolean` | `setException(Throwable exception)` Set the exception of this future.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### SettableListenableFuture

          public SettableListenableFuture()

  - ### Method Detail

    - #### set

          public boolean set(@Nullable
                             T value)

      Set the value of this future. This method will return `true` if the value was set successfully, or `false` if the future has already been set or cancelled.
      Parameters:
        `value` - the value that will be set
      Returns:
        `true` if the value was successfully set, else `false`

    - #### setException

          public boolean setException(Throwable exception)

      Set the exception of this future. This method will return `true` if the exception was set successfully, or `false` if the future has already been set or cancelled.
      Parameters:
        `exception` - the value that will be set
      Returns:
        `true` if the exception was successfully set, else `false`

    - #### addCallback

          public void addCallback(ListenableFutureCallback<? super T> callback)

      Description copied from interface: `ListenableFuture`
      Register the given `ListenableFutureCallback`.
      Specified by:
        `addCallback` in interface `ListenableFuture<T>`
      Parameters:
        `callback` - the callback to register

    - #### addCallback

          public void addCallback(SuccessCallback<? super T> successCallback,
                                  FailureCallback failureCallback)

      Description copied from interface: `ListenableFuture`
      Java 8 lambda-friendly alternative with success and failure callbacks.
      Specified by:
        `addCallback` in interface `ListenableFuture<T>`
      Parameters:
        `successCallback` - the success callback
        `failureCallback` - the failure callback

    - #### completable

          public CompletableFuture<T> completable()

      Description copied from interface: `ListenableFuture`
      Expose this `ListenableFuture` as a JDK `CompletableFuture`.
      Specified by:
        `completable` in interface `ListenableFuture<T>`

    - #### cancel

          public boolean cancel(boolean mayInterruptIfRunning)

      Specified by:
        `cancel` in interface `Future<T>`

    - #### isCancelled

          public boolean isCancelled()

      Specified by:
        `isCancelled` in interface `Future<T>`

    - #### isDone

          public boolean isDone()

      Specified by:
        `isDone` in interface `Future<T>`

    - #### get

          @Nullable
          public T get()
                          throws InterruptedException,
                                 ExecutionException

      Retrieve the value.

      This method returns the value if it has been set via `set(Object)`, throws an `ExecutionException` if an exception has been set via `setException(Throwable)`, or throws a `CancellationException` if the future has been cancelled.

      Specified by:
        `get` in interface `Future<T>`
      Returns:
        the value associated with this future
      Throws:
        `InterruptedException`
        `ExecutionException`

    - #### get

          @Nullable
          public T get(long timeout,
                                 TimeUnit unit)
                          throws InterruptedException,
                                 ExecutionException,
                                 TimeoutException

      Retrieve the value.

      This method returns the value if it has been set via `set(Object)`, throws an `ExecutionException` if an exception has been set via `setException(Throwable)`, or throws a `CancellationException` if the future has been cancelled.

      Specified by:
        `get` in interface `Future<T>`
      Parameters:
        `timeout` - the maximum time to wait
        `unit` - the unit of the timeout argument
      Returns:
        the value associated with this future
      Throws:
        `InterruptedException`
        `ExecutionException`
        `TimeoutException`

    - #### interruptTask

          protected void interruptTask()

      Subclasses can override this method to implement interruption of the future's computation. The method is invoked automatically by a successful call to `cancel(true)`.

      The default implementation is empty.