Package dev.failsafe.internal
Class TimeoutExecutor<R>
java.lang.Object
dev.failsafe.spi.PolicyExecutor<R>
dev.failsafe.internal.TimeoutExecutor<R>
- Type Parameters:
R
- result type
A PolicyExecutor that handles failures according to a
Timeout
.
Timeouts are scheduled to occur in a separate thread. When exceeded, a TimeoutExceededException
is recorded
as the execution result. If another result is recorded before the timeout is exceeded, any pending timeouts are
cancelled.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionapply
(Function<SyncExecutionInternal<R>, ExecutionResult<R>> innerFn, Scheduler scheduler) Schedules a separate timeout call that fails withTimeoutExceededException
if the policy's timeout is exceeded.applyAsync
(Function<AsyncExecutionInternal<R>, CompletableFuture<ExecutionResult<R>>> innerFn, Scheduler scheduler, FailsafeFuture<R> future) Schedules a separate timeout call that blocks and fails withTimeoutExceededException
if the policy's timeout is exceeded.boolean
isFailure
(ExecutionResult<R> result) Returns whether theresult
is a success according to the policy.Methods inherited from class dev.failsafe.spi.PolicyExecutor
getPolicyIndex, onFailure, onFailureAsync, onSuccess, postExecute, postExecuteAsync, preExecute, preExecuteAsync
-
Field Details
-
policy
-
config
-
-
Constructor Details
-
TimeoutExecutor
-
-
Method Details
-
isFailure
Description copied from class:PolicyExecutor
Returns whether theresult
is a success according to the policy. If the {code result} has no result, it is not a failure.- Overrides:
isFailure
in classPolicyExecutor<R>
-
apply
public Function<SyncExecutionInternal<R>,ExecutionResult<R>> apply(Function<SyncExecutionInternal<R>, ExecutionResult<R>> innerFn, Scheduler scheduler) Schedules a separate timeout call that fails withTimeoutExceededException
if the policy's timeout is exceeded.This implementation sets up a race between a timeout being triggered and the
innerFn
returning. Whichever completes first will be the result that's returned.- 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) Schedules a separate timeout call that blocks and fails withTimeoutExceededException
if the policy's timeout is exceeded.This implementation sets up a race between a timeout being triggered and the
innerFn
returning. Whichever completes first will be the result that's recorded and used to complete the resulting promise.- Overrides:
applyAsync
in classPolicyExecutor<R>
-