Package dev.failsafe.internal
Class RetryPolicyExecutor<R>
java.lang.Object
dev.failsafe.spi.PolicyExecutor<R>
dev.failsafe.internal.RetryPolicyExecutor<R>
- Type Parameters:
R
- result type
A PolicyExecutor that handles failures according to a
RetryPolicy
.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final EventHandler
<R> private final RetryPolicyConfig
<R> private final EventHandler
<R> private int
private long
The last fixed, backoff, random or computed delay time in nanoseconds.private boolean
private final EventHandler
<R> private final EventHandler
<R> private final RetryPolicyImpl
<R> private final EventHandler
<R> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate long
adjustForBackoff
(ExecutionContext<R> context, long delayNanos) private long
adjustForJitter
(long delayNanos) private long
adjustForMaxDuration
(long delayNanos, long elapsedNanos) apply
(Function<SyncExecutionInternal<R>, ExecutionResult<R>> innerFn, Scheduler scheduler) Performs an execution by calling pre-execute else calling the supplier and doing a post-execute.applyAsync
(Function<AsyncExecutionInternal<R>, CompletableFuture<ExecutionResult<R>>> innerFn, Scheduler scheduler, FailsafeFuture<R> future) Performs an async execution by calling pre-execute else calling the supplier and doing a post-execute.private long
getFixedOrRandomDelayNanos
(long delayNanos) handleAsync
(AsyncExecutionInternal<R> execution, Function<AsyncExecutionInternal<R>, CompletableFuture<ExecutionResult<R>>> innerFn, Scheduler scheduler, FailsafeFuture<R> future, CompletableFuture<ExecutionResult<R>> promise, AtomicReference<ExecutionResult<R>> previousResultRef) (package private) boolean
isValidResult
(ExecutionResult<R> result, Throwable error, CompletableFuture<ExecutionResult<R>> promise) Completes thepromise
and returnsfalse
if theresult
orerror
are invalid, else returnstrue
.onFailure
(ExecutionContext<R> context, ExecutionResult<R> result) Performs post-execution handling for aresult
that is considered a failure according toPolicyExecutor.isFailure(ExecutionResult)
, possibly creating a new result, else returning the originalresult
.onFailureAsync
(ExecutionContext<R> context, ExecutionResult<R> result, Scheduler scheduler, FailsafeFuture<R> future) Defaults async executions to not be complete untilsays they are
.Methods inherited from class dev.failsafe.spi.PolicyExecutor
getPolicyIndex, isFailure, onSuccess, postExecute, postExecuteAsync, preExecute, preExecuteAsync
-
Field Details
-
retryPolicy
-
config
-
failedAttempts
private volatile int failedAttempts -
retriesExceeded
private volatile boolean retriesExceeded -
lastDelayNanos
private volatile long lastDelayNanosThe last fixed, backoff, random or computed delay time in nanoseconds. -
abortHandler
-
failedAttemptHandler
-
retriesExceededHandler
-
retryHandler
-
retryScheduledHandler
-
-
Constructor Details
-
RetryPolicyExecutor
-
-
Method Details
-
apply
public Function<SyncExecutionInternal<R>,ExecutionResult<R>> apply(Function<SyncExecutionInternal<R>, ExecutionResult<R>> innerFn, Scheduler scheduler) Description copied from class:PolicyExecutor
Performs an execution by calling pre-execute else calling the supplier and doing a post-execute.- Overrides:
apply
in classPolicyExecutor<R>
-
applyAsync
public Function<AsyncExecutionInternal<R>,CompletableFuture<ExecutionResult<R>>> applyAsync(Function<AsyncExecutionInternal<R>, CompletableFuture<ExecutionResult<R>>> innerFn, Scheduler scheduler, FailsafeFuture<R> future) Description copied from class:PolicyExecutor
Performs an async execution by calling pre-execute else calling the supplier and doing a post-execute. Implementors must handle a null result from a supplier, which indicates that an async execution has occurred, that a result will be recorded separately, and that postExecute handling should not be performed.- Overrides:
applyAsync
in classPolicyExecutor<R>
-
handleAsync
public Object handleAsync(AsyncExecutionInternal<R> execution, Function<AsyncExecutionInternal<R>, CompletableFuture<ExecutionResult<R>>> innerFn, Scheduler scheduler, FailsafeFuture<R> future, CompletableFuture<ExecutionResult<R>> promise, AtomicReference<ExecutionResult<R>> previousResultRef) -
isValidResult
boolean isValidResult(ExecutionResult<R> result, Throwable error, CompletableFuture<ExecutionResult<R>> promise) Completes thepromise
and returnsfalse
if theresult
orerror
are invalid, else returnstrue
. -
onFailure
Description copied from class:PolicyExecutor
Performs post-execution handling for aresult
that is considered a failure according toPolicyExecutor.isFailure(ExecutionResult)
, possibly creating a new result, else returning the originalresult
.- Overrides:
onFailure
in classPolicyExecutor<R>
-
onFailureAsync
public CompletableFuture<ExecutionResult<R>> onFailureAsync(ExecutionContext<R> context, ExecutionResult<R> result, Scheduler scheduler, FailsafeFuture<R> future) Defaults async executions to not be complete untilsays they are
.- Overrides:
onFailureAsync
in classPolicyExecutor<R>
-
getFixedOrRandomDelayNanos
private long getFixedOrRandomDelayNanos(long delayNanos) -
adjustForBackoff
-
adjustForJitter
private long adjustForJitter(long delayNanos) -
adjustForMaxDuration
private long adjustForMaxDuration(long delayNanos, long elapsedNanos)
-