Package dev.failsafe.spi
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>
A CompletableFuture implementation that propagates cancellations and calls completion handlers.
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.concurrent.CompletableFuture
CompletableFuture.AsynchronousCompletionTask -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Map<Integer, BiConsumer<Boolean, ExecutionResult<R>>> private booleanprivate final BiConsumer<ExecutionResult<R>, ExecutionContext<R>> private ExecutionInternal<R> -
Constructor Summary
ConstructorsConstructorDescriptionFailsafeFuture(BiConsumer<ExecutionResult<R>, ExecutionContext<R>> completionHandler) -
Method Summary
Modifier and TypeMethodDescriptionbooleancancel(boolean mayInterruptIfRunning) Cancels the future along with any dependencies.voidcancelDependencies(PolicyExecutor<R> cancellingPolicyExecutor, boolean mayInterrupt, ExecutionResult<R> cancelResult) Applies anycancel functionswith thecancelResultfor PolicyExecutors whose policyIndex is invalid input: '<' the policyIndex of thecancellingPolicyExecutor.booleanIf not already completed, completes the future with thevalue, calling the complete and success handlers.booleancompleteExceptionally(Throwable exception) If not already completed, completes the future with theexception, calling the complete and failure handlers.booleancompleteResult(ExecutionResult<R> result) Completes the execution with theresultand calls the completion handler.voidpropagateCancellation(Future<R> future) Propogates any previous cancellation to thefuture, either by cancelling it immediately or setting a cancel function to cancel it later.voidsetCancelFn(int policyIndex, BiConsumer<Boolean, ExecutionResult<R>> cancelFn) Sets acancelFnto be called when a PolicyExecutorcancels dependencieswith a policyIndex > the givenpolicyIndex, or when this future iscancelled.voidsetCancelFn(PolicyExecutor<R> policyExecutor, BiConsumer<Boolean, ExecutionResult<R>> cancelFn) Sets acancelFnto be called when a PolicyExecutorcancels dependencieswith a policyIndex > the policyIndex of the givenpolicyExecutor, or when this future iscancelled.voidsetExecution(ExecutionInternal<R> execution) Sets theexecutionrepresenting 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
-
Field Details
-
completionHandler
-
newestExecution
-
cancelFunctions
-
cancelledWithInterrupt
private boolean cancelledWithInterrupt
-
-
Constructor Details
-
FailsafeFuture
-
-
Method Details
-
complete
If not already completed, completes the future with thevalue, calling the complete and success handlers.- Overrides:
completein classCompletableFuture<R>
-
completeExceptionally
If not already completed, completes the future with theexception, calling the complete and failure handlers.- Overrides:
completeExceptionallyin classCompletableFuture<R>
-
cancel
public boolean cancel(boolean mayInterruptIfRunning) Cancels the future along with any dependencies. -
completeResult
Completes the execution with theresultand calls the completion handler. -
cancelDependencies
public void cancelDependencies(PolicyExecutor<R> cancellingPolicyExecutor, boolean mayInterrupt, ExecutionResult<R> cancelResult) Applies anycancel functionswith thecancelResultfor PolicyExecutors whose policyIndex is invalid input: '<' the policyIndex of thecancellingPolicyExecutor.- Parameters:
cancellingPolicyExecutor- the PolicyExecutor that is requesting the cancellation of inner policy executors
-
setExecution
Sets theexecutionrepresenting the most recent attempt, which will be cancelled if this future is cancelled. -
setCancelFn
Sets acancelFnto be called when a PolicyExecutorcancels dependencieswith a policyIndex > the givenpolicyIndex, or when this future iscancelled. -
setCancelFn
public void setCancelFn(PolicyExecutor<R> policyExecutor, BiConsumer<Boolean, ExecutionResult<R>> cancelFn) Sets acancelFnto be called when a PolicyExecutorcancels dependencieswith a policyIndex > the policyIndex of the givenpolicyExecutor, or when this future iscancelled. -
propagateCancellation
Propogates any previous cancellation to thefuture, either by cancelling it immediately or setting a cancel function to cancel it later.
-