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>abortHandlerprivate RetryPolicyConfig<R>configprivate EventHandler<R>failedAttemptHandlerprivate intfailedAttemptsprivate longlastDelayNanosThe last fixed, backoff, random or computed delay time in nanoseconds.private booleanretriesExceededprivate EventHandler<R>retriesExceededHandlerprivate EventHandler<R>retryHandlerprivate RetryPolicyImpl<R>retryPolicyprivate 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 longadjustForBackoff(ExecutionContext<R> context, long delayNanos)private longadjustForJitter(long delayNanos)private longadjustForMaxDuration(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 longgetFixedOrRandomDelayNanos(long delayNanos)java.lang.ObjecthandleAsync(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) booleanisValidResult(ExecutionResult<R> result, java.lang.Throwable error, java.util.concurrent.CompletableFuture<ExecutionResult<R>> promise)Completes thepromiseand returnsfalseif theresultorerrorare invalid, else returnstrue.ExecutionResult<R>onFailure(ExecutionContext<R> context, ExecutionResult<R> result)Performs post-execution handling for aresultthat 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:PolicyExecutorPerforms an execution by calling pre-execute else calling the supplier and doing a post-execute.- Overrides:
applyin 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:PolicyExecutorPerforms 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:
applyAsyncin 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 thepromiseand returnsfalseif theresultorerrorare invalid, else returnstrue.
-
onFailure
public ExecutionResult<R> onFailure(ExecutionContext<R> context, ExecutionResult<R> result)
Description copied from class:PolicyExecutorPerforms post-execution handling for aresultthat is considered a failure according toPolicyExecutor.isFailure(ExecutionResult), possibly creating a new result, else returning the originalresult.- Overrides:
onFailurein 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:
onFailureAsyncin 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)
-
-