Class FailsafeFuture<R>

  • Type Parameters:
    R - result type
    All Implemented Interfaces:
    java.util.concurrent.CompletionStage<R>, java.util.concurrent.Future<R>

    public class FailsafeFuture<R>
    extends java.util.concurrent.CompletableFuture<R>
    A CompletableFuture implementation that propagates cancellations and calls completion handlers.
    • Nested Class Summary

      • Nested classes/interfaces inherited from class java.util.concurrent.CompletableFuture

        java.util.concurrent.CompletableFuture.AsynchronousCompletionTask
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean cancel​(boolean mayInterruptIfRunning)
      Cancels the future along with any dependencies.
      void cancelDependencies​(PolicyExecutor<R> cancellingPolicyExecutor, boolean mayInterrupt, ExecutionResult<R> cancelResult)
      Applies any cancel functions with the cancelResult for PolicyExecutors whose policyIndex is < the policyIndex of the cancellingPolicyExecutor.
      boolean complete​(R value)
      If not already completed, completes the future with the value, calling the complete and success handlers.
      boolean completeExceptionally​(java.lang.Throwable exception)
      If not already completed, completes the future with the exception, calling the complete and failure handlers.
      boolean completeResult​(ExecutionResult<R> result)
      Completes the execution with the result and calls the completion handler.
      void propagateCancellation​(java.util.concurrent.Future<R> future)
      Propogates any previous cancellation to the future, either by cancelling it immediately or setting a cancel function to cancel it later.
      void setCancelFn​(int policyIndex, java.util.function.BiConsumer<java.lang.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.
      void setCancelFn​(PolicyExecutor<R> policyExecutor, java.util.function.BiConsumer<java.lang.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.
      void setExecution​(ExecutionInternal<R> execution)
      Sets the execution representing the most recent attempt, which will be cancelled if this future is cancelled.
      • Methods inherited from class java.util.concurrent.CompletableFuture

        acceptEither, acceptEitherAsync, acceptEitherAsync, allOf, anyOf, applyToEither, applyToEitherAsync, applyToEitherAsync, completedFuture, exceptionally, get, get, getNow, getNumberOfDependents, handle, handleAsync, handleAsync, isCancelled, isCompletedExceptionally, isDone, join, obtrudeException, obtrudeValue, runAfterBoth, runAfterBothAsync, runAfterBothAsync, runAfterEither, runAfterEitherAsync, runAfterEitherAsync, runAsync, runAsync, supplyAsync, supplyAsync, thenAccept, thenAcceptAsync, thenAcceptAsync, thenAcceptBoth, thenAcceptBothAsync, thenAcceptBothAsync, thenApply, thenApplyAsync, thenApplyAsync, thenCombine, thenCombineAsync, thenCombineAsync, thenCompose, thenComposeAsync, thenComposeAsync, thenRun, thenRunAsync, thenRunAsync, toCompletableFuture, toString, whenComplete, whenCompleteAsync, whenCompleteAsync
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • cancelFunctions

        private java.util.Map<java.lang.Integer,​java.util.function.BiConsumer<java.lang.Boolean,​ExecutionResult<R>>> cancelFunctions
      • cancelledWithInterrupt

        private boolean cancelledWithInterrupt
    • Method Detail

      • 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 java.util.concurrent.CompletableFuture<R>
      • completeExceptionally

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

        public boolean cancel​(boolean mayInterruptIfRunning)
        Cancels the future along with any dependencies.
        Specified by:
        cancel in interface java.util.concurrent.Future<R>
        Overrides:
        cancel in class java.util.concurrent.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 < 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,
                                java.util.function.BiConsumer<java.lang.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,
                                java.util.function.BiConsumer<java.lang.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​(java.util.concurrent.Future<R> future)
        Propogates any previous cancellation to the future, either by cancelling it immediately or setting a cancel function to cancel it later.