R
- result typepublic abstract class PolicyExecutor<R> extends Object
Modifier | Constructor and Description |
---|---|
protected |
PolicyExecutor(Policy<R> policy,
int policyIndex) |
Modifier and Type | Method and Description |
---|---|
Function<SyncExecutionInternal<R>,ExecutionResult<R>> |
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.
|
Function<AsyncExecutionInternal<R>,CompletableFuture<ExecutionResult<R>>> |
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.
|
int |
getPolicyIndex()
Returns the index of the policy relative to other policies in a composition, where the innermost policy in a
composition has an index of
0 . |
protected boolean |
isFailure(ExecutionResult<R> result)
Returns whether the
result is a success according to the policy. |
protected ExecutionResult<R> |
onFailure(ExecutionContext<R> context,
ExecutionResult<R> result)
Performs post-execution handling for a
result that is considered a failure according to isFailure(ExecutionResult) , possibly creating a new result, else returning the original result . |
protected CompletableFuture<ExecutionResult<R>> |
onFailureAsync(ExecutionContext<R> context,
ExecutionResult<R> result,
Scheduler scheduler,
FailsafeFuture<R> future)
Performs potentially asynchrononus post-execution handling for a failed
result , possibly creating a new
result, else returning the original result . |
protected void |
onSuccess(ExecutionResult<R> result)
Performs post-execution handling for a
result that is considered a success according to isFailure(ExecutionResult) . |
ExecutionResult<R> |
postExecute(ExecutionInternal<R> execution,
ExecutionResult<R> result)
Performs synchronous post-execution handling for a
result . |
protected CompletableFuture<ExecutionResult<R>> |
postExecuteAsync(AsyncExecutionInternal<R> execution,
ExecutionResult<R> result,
Scheduler scheduler,
FailsafeFuture<R> future)
Performs potentially asynchronous post-execution handling for a
result . |
protected ExecutionResult<R> |
preExecute()
Called before execution to return an alternative result or exception such as if execution is not allowed or needed.
|
protected CompletableFuture<ExecutionResult<R>> |
preExecuteAsync(Scheduler scheduler,
FailsafeFuture<R> future)
Called before an async execution to return an alternative result or exception such as if execution is not allowed or
needed.
|
public int getPolicyIndex()
0
.protected ExecutionResult<R> preExecute()
protected CompletableFuture<ExecutionResult<R>> preExecuteAsync(Scheduler scheduler, FailsafeFuture<R> future)
null
if pre execution is not performed. If the resulting future is completed with a non-result
, then execution and post-execution should still be performed. If the
resulting future is completed with null
, then the execution is assumed to have been cancelled.public Function<SyncExecutionInternal<R>,ExecutionResult<R>> apply(Function<SyncExecutionInternal<R>,ExecutionResult<R>> innerFn, Scheduler scheduler)
public Function<AsyncExecutionInternal<R>,CompletableFuture<ExecutionResult<R>>> applyAsync(Function<AsyncExecutionInternal<R>,CompletableFuture<ExecutionResult<R>>> innerFn, Scheduler scheduler, FailsafeFuture<R> future)
public ExecutionResult<R> postExecute(ExecutionInternal<R> execution, ExecutionResult<R> result)
result
.protected CompletableFuture<ExecutionResult<R>> postExecuteAsync(AsyncExecutionInternal<R> execution, ExecutionResult<R> result, Scheduler scheduler, FailsafeFuture<R> future)
result
.protected boolean isFailure(ExecutionResult<R> result)
result
is a success according to the policy. If the {code result} has no result, it is
not a failure.protected void onSuccess(ExecutionResult<R> result)
result
that is considered a success according to isFailure(ExecutionResult)
.protected ExecutionResult<R> onFailure(ExecutionContext<R> context, ExecutionResult<R> result)
result
that is considered a failure according to isFailure(ExecutionResult)
, possibly creating a new result, else returning the original result
.protected CompletableFuture<ExecutionResult<R>> onFailureAsync(ExecutionContext<R> context, ExecutionResult<R> result, Scheduler scheduler, FailsafeFuture<R> future)
result
, possibly creating a new
result, else returning the original result
.Copyright © 2022. All rights reserved.