Class SettableFuture<T>

  • All Implemented Interfaces:
    Future<T>

    public class SettableFuture<T>
    extends Object
    implements Future<T>
    A ListenableFuture whose value can be set via set(Object) or setException(Throwable). It may also be cancelled.

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

    Since:
    4.1
    Author:
    Mattias Severson, Rossen Stoyanchev
    • Constructor Detail

      • SettableFuture

        public SettableFuture()
    • Method Detail

      • set

        public boolean set​(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.
      • 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>
      • 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 does nothing.