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
public class RetryPolicyExecutor<R> extends PolicyExecutor<R>
A PolicyExecutor that handles failures according to aRetryPolicy
.
-
-
Field Summary
Fields Modifier and Type Field Description private EventHandler<R>
abortHandler
private RetryPolicyConfig<R>
config
private EventHandler<R>
failedAttemptHandler
private int
failedAttempts
private long
lastDelayNanos
The last fixed, backoff, random or computed delay time in nanoseconds.private boolean
retriesExceeded
private EventHandler<R>
retriesExceededHandler
private EventHandler<R>
retryHandler
private RetryPolicyImpl<R>
retryPolicy
private EventHandler<R>
retryScheduledHandler
-
Constructor Summary
Constructors Constructor Description RetryPolicyExecutor(RetryPolicyImpl<R> retryPolicy, int policyIndex)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private long
adjustForBackoff(ExecutionContext<R> context, long delayNanos)
private long
adjustForJitter(long delayNanos)
private long
adjustForMaxDuration(long delayNanos, long elapsedNanos)
java.util.function.Function<SyncExecutionInternal<R>,ExecutionResult<R>>
apply(java.util.function.Function<SyncExecutionInternal<R>,ExecutionResult<R>> innerFn, Scheduler scheduler)
Performs an execution by calling pre-execute else calling the supplier and doing a post-execute.java.util.function.Function<AsyncExecutionInternal<R>,java.util.concurrent.CompletableFuture<ExecutionResult<R>>>
applyAsync(java.util.function.Function<AsyncExecutionInternal<R>,java.util.concurrent.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)
java.lang.Object
handleAsync(AsyncExecutionInternal<R> execution, java.util.function.Function<AsyncExecutionInternal<R>,java.util.concurrent.CompletableFuture<ExecutionResult<R>>> innerFn, Scheduler scheduler, FailsafeFuture<R> future, java.util.concurrent.CompletableFuture<ExecutionResult<R>> promise, java.util.concurrent.atomic.AtomicReference<ExecutionResult<R>> previousResultRef)
(package private) boolean
isValidResult(ExecutionResult<R> result, java.lang.Throwable error, java.util.concurrent.CompletableFuture<ExecutionResult<R>> promise)
Completes thepromise
and returnsfalse
if theresult
orerror
are invalid, else returnstrue
.ExecutionResult<R>
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
.java.util.concurrent.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
.-
Methods inherited from class dev.failsafe.spi.PolicyExecutor
getPolicyIndex, isFailure, onSuccess, postExecute, postExecuteAsync, preExecute, preExecuteAsync
-
-
-
-
Field Detail
-
retryPolicy
private final RetryPolicyImpl<R> retryPolicy
-
config
private final RetryPolicyConfig<R> config
-
failedAttempts
private volatile int failedAttempts
-
retriesExceeded
private volatile boolean retriesExceeded
-
lastDelayNanos
private volatile long lastDelayNanos
The last fixed, backoff, random or computed delay time in nanoseconds.
-
abortHandler
private final EventHandler<R> abortHandler
-
failedAttemptHandler
private final EventHandler<R> failedAttemptHandler
-
retriesExceededHandler
private final EventHandler<R> retriesExceededHandler
-
retryHandler
private final EventHandler<R> retryHandler
-
retryScheduledHandler
private final EventHandler<R> retryScheduledHandler
-
-
Constructor Detail
-
RetryPolicyExecutor
public RetryPolicyExecutor(RetryPolicyImpl<R> retryPolicy, int policyIndex)
-
-
Method Detail
-
apply
public java.util.function.Function<SyncExecutionInternal<R>,ExecutionResult<R>> apply(java.util.function.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 java.util.function.Function<AsyncExecutionInternal<R>,java.util.concurrent.CompletableFuture<ExecutionResult<R>>> applyAsync(java.util.function.Function<AsyncExecutionInternal<R>,java.util.concurrent.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 java.lang.Object handleAsync(AsyncExecutionInternal<R> execution, java.util.function.Function<AsyncExecutionInternal<R>,java.util.concurrent.CompletableFuture<ExecutionResult<R>>> innerFn, Scheduler scheduler, FailsafeFuture<R> future, java.util.concurrent.CompletableFuture<ExecutionResult<R>> promise, java.util.concurrent.atomic.AtomicReference<ExecutionResult<R>> previousResultRef)
-
isValidResult
boolean isValidResult(ExecutionResult<R> result, java.lang.Throwable error, java.util.concurrent.CompletableFuture<ExecutionResult<R>> promise)
Completes thepromise
and returnsfalse
if theresult
orerror
are invalid, else returnstrue
.
-
onFailure
public ExecutionResult<R> onFailure(ExecutionContext<R> context, ExecutionResult<R> result)
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 java.util.concurrent.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
private long adjustForBackoff(ExecutionContext<R> context, long delayNanos)
-
adjustForJitter
private long adjustForJitter(long delayNanos)
-
adjustForMaxDuration
private long adjustForMaxDuration(long delayNanos, long elapsedNanos)
-
-