Class BaseFuture<V>

java.lang.Object
org.elasticsearch.common.util.concurrent.BaseFuture<V>
All Implemented Interfaces:
Future<V>
Direct Known Subclasses:
AdapterActionFuture, ListenableFuture, PlainTransportFuture

public abstract class BaseFuture<V> extends Object implements Future<V>
  • Constructor Details

    • BaseFuture

      public BaseFuture()
  • Method Details

    • get

      public V get(long timeout, TimeUnit unit) throws InterruptedException, TimeoutException, ExecutionException

      The default BaseFuture implementation throws InterruptedException if the current thread is interrupted before or during the call, even if the value is already available.

      Specified by:
      get in interface Future<V>
      Throws:
      InterruptedException - if the current thread was interrupted before or during the call (optional but recommended).
      CancellationException
      TimeoutException
      ExecutionException
    • get

      The default BaseFuture implementation throws InterruptedException if the current thread is interrupted before or during the call, even if the value is already available.

      Specified by:
      get in interface Future<V>
      Throws:
      InterruptedException - if the current thread was interrupted before or during the call (optional but recommended).
      CancellationException
      ExecutionException
    • blockingAllowed

      protected boolean blockingAllowed()
    • isDone

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

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

      public boolean cancel(boolean mayInterruptIfRunning)
      Specified by:
      cancel in interface Future<V>
    • 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.

      Since:
      10.0
    • set

      protected boolean set(@Nullable V value)
      Subclasses should invoke this method to set the result of the computation to value. This will set the state of the future to BaseFuture.Sync.COMPLETED and call done(boolean) if the state was successfully changed.
      Parameters:
      value - the value that was the result of the task.
      Returns:
      true if the state was successfully changed.
    • setException

      protected boolean setException(Throwable throwable)
      Subclasses should invoke this method to set the result of the computation to an error, throwable. This will set the state of the future to BaseFuture.Sync.COMPLETED and call done(boolean) if the state was successfully changed.
      Parameters:
      throwable - the exception that the task failed with.
      Returns:
      true if the state was successfully changed.
      Throws:
      Error - if the throwable was an Error.
    • done

      protected void done(boolean success)
      Called when the BaseFuture is completed. The success boolean indicates if the BaseFuture was successfully completed (the value is true). In the cases the BaseFuture was completed with an error or cancelled the value is false.
      Parameters:
      success - indicates if the BaseFuture was completed with success (true); in other cases it equals to false