public class Failsafe extends Object
Constructor and Description |
---|
Failsafe() |
Modifier and Type | Method and Description |
---|---|
static <R> FailsafeExecutor<R> |
with(List<? extends Policy<R>> policies)
Creates and returns a new
FailsafeExecutor instance that will handle failures according to the given policies . |
static <R,P extends Policy<R>> |
with(P... policies)
Creates and returns a new
FailsafeExecutor instance that will handle failures according to the given policies . |
@SafeVarargs public static <R,P extends Policy<R>> FailsafeExecutor<R> with(P... policies)
FailsafeExecutor
instance that will handle failures according to the given policies
. The policies
are composed around an execution and will handle execution results in reverse, with
the last policy being applied first. For example, consider:
Failsafe.with(fallback, retryPolicy, circuitBreaker).get(supplier);This results in the following internal composition when executing the
supplier
and handling its result:
Fallback(RetryPolicy(CircuitBreaker(Supplier)))This means the
CircuitBreaker
is first to evaluate the Supplier
's result, then the RetryPolicy
, then the Fallback
. Each policy makes its own determination as to whether the result
represents a failure. This allows different policies to be used for handling different types of failures.R
- result typeP
- policy typeNullPointerException
- if policies
is nullIllegalArgumentException
- if policies
is emptypublic static <R> FailsafeExecutor<R> with(List<? extends Policy<R>> policies)
FailsafeExecutor
instance that will handle failures according to the given policies
. The policies
are composed around an execution and will handle execution results in reverse, with
the last policy being applied first. For example, consider:
Failsafe.with(fallback, retryPolicy, circuitBreaker).get(supplier);This results in the following internal composition when executing the
supplier
and handling its result:
Fallback(RetryPolicy(CircuitBreaker(Supplier)))This means the
CircuitBreaker
is first to evaluate the Supplier
's result, then the RetryPolicy
, then the Fallback
. Each policy makes its own determination as to whether the result
represents a failure. This allows different policies to be used for handling different types of failures.R
- result typeNullPointerException
- if policies
is nullIllegalArgumentException
- if policies
is emptyCopyright © 2020. All rights reserved.