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
public class TimeoutExecutor<R> extends PolicyExecutor<R>
A PolicyExecutor that handles failures according to aTimeout
.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.
-
-
Constructor Summary
Constructors Constructor Description TimeoutExecutor(TimeoutImpl<R> timeout, int policyIndex)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.function.Function<SyncExecutionInternal<R>,ExecutionResult<R>>
apply(java.util.function.Function<SyncExecutionInternal<R>,ExecutionResult<R>> innerFn, Scheduler scheduler)
Schedules a separate timeout call that fails withTimeoutExceededException
if the policy's timeout is exceeded.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)
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 Detail
-
config
private final TimeoutConfig<R> config
-
-
Constructor Detail
-
TimeoutExecutor
public TimeoutExecutor(TimeoutImpl<R> timeout, int policyIndex)
-
-
Method Detail
-
isFailure
public boolean isFailure(ExecutionResult<R> result)
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 java.util.function.Function<SyncExecutionInternal<R>,ExecutionResult<R>> apply(java.util.function.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 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)
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>
-
-