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 boolean
private final BiConsumer
<ExecutionResult<R>, ExecutionContext<R>> private ExecutionInternal
<R> -
Constructor Summary
ConstructorsConstructorDescriptionFailsafeFuture
(BiConsumer<ExecutionResult<R>, ExecutionContext<R>> completionHandler) -
Method Summary
Modifier and TypeMethodDescriptionboolean
cancel
(boolean mayInterruptIfRunning) Cancels the future along with any dependencies.void
cancelDependencies
(PolicyExecutor<R> cancellingPolicyExecutor, boolean mayInterrupt, ExecutionResult<R> cancelResult) Applies anycancel functions
with thecancelResult
for PolicyExecutors whose policyIndex is invalid input: '<' the policyIndex of thecancellingPolicyExecutor
.boolean
If not already completed, completes the future with thevalue
, calling the complete and success handlers.boolean
completeExceptionally
(Throwable exception) If not already completed, completes the future with theexception
, calling the complete and failure handlers.boolean
completeResult
(ExecutionResult<R> result) Completes the execution with theresult
and calls the completion handler.void
propagateCancellation
(Future<R> future) Propogates any previous cancellation to thefuture
, either by cancelling it immediately or setting a cancel function to cancel it later.void
setCancelFn
(int policyIndex, BiConsumer<Boolean, ExecutionResult<R>> cancelFn) Sets acancelFn
to be called when a PolicyExecutorcancels dependencies
with a policyIndex > the givenpolicyIndex
, or when this future iscancelled
.void
setCancelFn
(PolicyExecutor<R> policyExecutor, BiConsumer<Boolean, ExecutionResult<R>> cancelFn) Sets acancelFn
to be called when a PolicyExecutorcancels dependencies
with a policyIndex > the policyIndex of the givenpolicyExecutor
, or when this future iscancelled
.void
setExecution
(ExecutionInternal<R> execution) Sets theexecution
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
-
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:
complete
in classCompletableFuture<R>
-
completeExceptionally
If not already completed, completes the future with theexception
, calling the complete and failure handlers.- Overrides:
completeExceptionally
in classCompletableFuture<R>
-
cancel
public boolean cancel(boolean mayInterruptIfRunning) Cancels the future along with any dependencies. -
completeResult
Completes the execution with theresult
and calls the completion handler. -
cancelDependencies
public void cancelDependencies(PolicyExecutor<R> cancellingPolicyExecutor, boolean mayInterrupt, ExecutionResult<R> cancelResult) Applies anycancel functions
with thecancelResult
for 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 theexecution
representing the most recent attempt, which will be cancelled if this future is cancelled. -
setCancelFn
Sets acancelFn
to be called when a PolicyExecutorcancels dependencies
with a policyIndex > the givenpolicyIndex
, or when this future iscancelled
. -
setCancelFn
public void setCancelFn(PolicyExecutor<R> policyExecutor, BiConsumer<Boolean, ExecutionResult<R>> cancelFn) Sets acancelFn
to be called when a PolicyExecutorcancels dependencies
with 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.
-