Package dev.failsafe
Interface Timeout<R>
-
- Type Parameters:
R- result type
- All Superinterfaces:
Policy<R>
- All Known Implementing Classes:
TimeoutImpl
public interface Timeout<R> extends Policy<R>
A policy that cancels and fails an excecution with aTimeoutExceededExceptionif a timeout is exceeded. Executioninterruptionis optionally supported. Asynchronous executions are cancelled by callingcancelon their underlying future. Executions can internally cooperate with cancellation by checkingExecutionContext.isCancelled().This policy uses a separate thread on the configured scheduler or the common pool to perform timeouts checks.
The
PolicyBuilder.onFailure(EventListener)andPolicyBuilder.onSuccess(EventListener)event handlers can be used to handle a timeout being exceeded or not.Note:
interruptionwill have no effect when performing anasync executionsince the async thread is unknown to Failsafe.This class is threadsafe.
- See Also:
TimeoutConfig,TimeoutBuilder,TimeoutExceededException
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description static <R> TimeoutBuilder<R>builder(TimeoutConfig<R> config)Creates a new TimeoutBuilder that will be based on theconfig.static <R> TimeoutBuilder<R>builder(java.time.Duration timeout)TimeoutConfig<R>getConfig()Returns theTimeoutConfigthat the Timeout was built with.static <R> Timeout<R>of(java.time.Duration timeout)-
Methods inherited from interface dev.failsafe.Policy
toExecutor
-
-
-
-
Method Detail
-
builder
static <R> TimeoutBuilder<R> builder(java.time.Duration timeout)
- Parameters:
timeout- the duration after which an execution is failed withTimeoutExceededException.- Throws:
java.lang.NullPointerException- Iftimeoutis nulljava.lang.IllegalArgumentException- Iftimeoutis <= 0
-
builder
static <R> TimeoutBuilder<R> builder(TimeoutConfig<R> config)
Creates a new TimeoutBuilder that will be based on theconfig.
-
of
static <R> Timeout<R> of(java.time.Duration timeout)
Returns aTimeoutthat fails an execution withTimeoutExceededExceptionif it exceeds thetimeout. Alias forTimeout.builder(timeout).build(). To configure additional options on a Timeout, usebuilder(Duration)instead.- Type Parameters:
R- result type- Parameters:
timeout- the duration after which an execution is failed withTimeoutExceededException.- Throws:
java.lang.NullPointerException- Iftimeoutis nulljava.lang.IllegalArgumentException- Iftimeoutis <= 0- See Also:
builder(Duration)
-
getConfig
TimeoutConfig<R> getConfig()
Returns theTimeoutConfigthat the Timeout was built with.
-
-