Class FailsafeFuture<R>

java.lang.Object
java.util.concurrent.CompletableFuture<R>
dev.failsafe.spi.FailsafeFuture<R>
Type Parameters:
R - result type
All Implemented Interfaces:
CompletionStage<R>, Future<R>

public class FailsafeFuture<R> extends CompletableFuture<R>
A CompletableFuture implementation that propagates cancellations and calls completion handlers.
  • Field Details

  • Constructor Details

  • Method Details

    • complete

      public boolean complete(R value)
      If not already completed, completes the future with the value, calling the complete and success handlers.
      Overrides:
      complete in class CompletableFuture<R>
    • completeExceptionally

      public boolean completeExceptionally(Throwable exception)
      If not already completed, completes the future with the exception, calling the complete and failure handlers.
      Overrides:
      completeExceptionally in class CompletableFuture<R>
    • cancel

      public boolean cancel(boolean mayInterruptIfRunning)
      Cancels the future along with any dependencies.
      Specified by:
      cancel in interface Future<R>
      Overrides:
      cancel in class CompletableFuture<R>
    • completeResult

      public boolean completeResult(ExecutionResult<R> result)
      Completes the execution with the result and calls the completion handler.
    • cancelDependencies

      public void cancelDependencies(PolicyExecutor<R> cancellingPolicyExecutor, boolean mayInterrupt, ExecutionResult<R> cancelResult)
      Applies any cancel functions with the cancelResult for PolicyExecutors whose policyIndex is invalid input: '<' the policyIndex of the cancellingPolicyExecutor.
      Parameters:
      cancellingPolicyExecutor - the PolicyExecutor that is requesting the cancellation of inner policy executors
    • setExecution

      public void setExecution(ExecutionInternal<R> execution)
      Sets the execution representing the most recent attempt, which will be cancelled if this future is cancelled.
    • setCancelFn

      public void setCancelFn(int policyIndex, BiConsumer<Boolean,ExecutionResult<R>> cancelFn)
      Sets a cancelFn to be called when a PolicyExecutor cancels dependencies with a policyIndex > the given policyIndex, or when this future is cancelled.
    • setCancelFn

      public void setCancelFn(PolicyExecutor<R> policyExecutor, BiConsumer<Boolean,ExecutionResult<R>> cancelFn)
      Sets a cancelFn to be called when a PolicyExecutor cancels dependencies with a policyIndex > the policyIndex of the given policyExecutor, or when this future is cancelled.
    • propagateCancellation

      public void propagateCancellation(Future<R> future)
      Propogates any previous cancellation to the future, either by cancelling it immediately or setting a cancel function to cancel it later.