Package dev.failsafe
Interface Timeout<R>
- Type Parameters:
R
- result type
- All Superinterfaces:
Policy<R>
- All Known Implementing Classes:
TimeoutImpl
A policy that cancels and fails an excecution with a
TimeoutExceededException
if a
timeout is exceeded. Execution interruption
is optionally supported.
Asynchronous executions are cancelled by calling cancel
on their
underlying future. Executions can internally cooperate with cancellation by checking ExecutionContext.isCancelled()
.
This policy uses a separate thread on the configured scheduler or the common pool to perform timeouts checks.
The PolicyBuilder.onFailure(EventListener)
and PolicyBuilder.onSuccess(EventListener)
event
handlers can be used to handle a timeout being exceeded or not.
Note: interruption
will have no effect when performing an async execution
since the async thread is unknown to Failsafe.
This class is threadsafe.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic <R> TimeoutBuilder
<R> builder
(TimeoutConfig<R> config) Creates a new TimeoutBuilder that will be based on theconfig
.static <R> TimeoutBuilder
<R> Returns theTimeoutConfig
that the Timeout was built with.static <R> Timeout
<R> Methods inherited from interface dev.failsafe.Policy
toExecutor
-
Method Details
-
builder
- Parameters:
timeout
- the duration after which an execution is failed withTimeoutExceededException
.- Throws:
NullPointerException
- Iftimeout
is nullIllegalArgumentException
- Iftimeout
is invalid input: '<'= 0
-
builder
Creates a new TimeoutBuilder that will be based on theconfig
. -
of
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:
NullPointerException
- Iftimeout
is nullIllegalArgumentException
- Iftimeout
is invalid input: '<'= 0- See Also:
-
getConfig
TimeoutConfig<R> getConfig()Returns theTimeoutConfig
that the Timeout was built with.
-