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 aTimeoutExceededException
if a timeout is exceeded. Executioninterruption
is optionally supported. Asynchronous executions are cancelled by callingcancel
on 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:
interruption
will have no effect when performing anasync execution
since 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 theTimeoutConfig
that 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
- Iftimeout
is nulljava.lang.IllegalArgumentException
- Iftimeout
is <= 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 aTimeout
that fails an execution withTimeoutExceededException
if 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
- Iftimeout
is nulljava.lang.IllegalArgumentException
- Iftimeout
is <= 0- See Also:
builder(Duration)
-
getConfig
TimeoutConfig<R> getConfig()
Returns theTimeoutConfig
that the Timeout was built with.
-
-