public static class CircuitBreakerConfig.Builder
extends java.lang.Object
Constructor and Description |
---|
Builder() |
Builder(CircuitBreakerConfig baseConfig) |
Modifier and Type | Method and Description |
---|---|
CircuitBreakerConfig.Builder |
automaticTransitionFromOpenToHalfOpenEnabled(boolean enableAutomaticTransitionFromOpenToHalfOpen)
Enables automatic transition from OPEN to HALF_OPEN state once the
waitDurationInOpenState has passed.
|
CircuitBreakerConfig |
build()
Builds a CircuitBreakerConfig
|
CircuitBreakerConfig.Builder |
enableAutomaticTransitionFromOpenToHalfOpen()
Enables automatic transition from OPEN to HALF_OPEN state once the
waitDurationInOpenState has passed.
|
CircuitBreakerConfig.Builder |
failureRateThreshold(float failureRateThreshold)
Configures the failure rate threshold in percentage.
|
CircuitBreakerConfig.Builder |
ignoreException(java.util.function.Predicate<java.lang.Throwable> predicate)
Configures a Predicate which evaluates if an exception should be ignored and neither
count as a failure nor success.
|
CircuitBreakerConfig.Builder |
ignoreExceptions(java.lang.Class<? extends java.lang.Throwable>... errorClasses)
Configures a list of error classes that are ignored and thus neither count as a failure
nor success.
|
CircuitBreakerConfig.Builder |
minimumNumberOfCalls(int minimumNumberOfCalls)
Configures the minimum number of calls which are required (per sliding window period)
before the CircuitBreaker can calculate the error rate.
|
CircuitBreakerConfig.Builder |
permittedNumberOfCallsInHalfOpenState(int permittedNumberOfCallsInHalfOpenState)
Configures the number of permitted calls when the CircuitBreaker is half open.
|
CircuitBreakerConfig.Builder |
recordException(java.util.function.Predicate<java.lang.Throwable> predicate)
Configures a Predicate which evaluates if an exception should be recorded as a failure
and thus increase the failure rate.
|
CircuitBreakerConfig.Builder |
recordExceptions(java.lang.Class<? extends java.lang.Throwable>... errorClasses)
Configures a list of error classes that are recorded as a failure and thus increase the
failure rate.
|
CircuitBreakerConfig.Builder |
recordFailure(java.util.function.Predicate<java.lang.Throwable> predicate)
Deprecated.
use
recordException(Predicate) instead. |
CircuitBreakerConfig.Builder |
ringBufferSizeInClosedState(int ringBufferSizeInClosedState)
Deprecated.
Use
#slidingWindow(int, int, SlidingWindowType) instead. |
CircuitBreakerConfig.Builder |
ringBufferSizeInHalfOpenState(int ringBufferSizeInHalfOpenState)
Deprecated.
Use
permittedNumberOfCallsInHalfOpenState(int) instead. |
CircuitBreakerConfig.Builder |
slidingWindow(int slidingWindowSize,
int minimumNumberOfCalls,
CircuitBreakerConfig.SlidingWindowType slidingWindowType)
Configures the sliding window which is used to record the outcome of calls when the
CircuitBreaker is closed.
|
CircuitBreakerConfig.Builder |
slidingWindowSize(int slidingWindowSize)
Configures the size of the sliding window which is used to record the outcome of calls
when the CircuitBreaker is closed.
|
CircuitBreakerConfig.Builder |
slidingWindowType(CircuitBreakerConfig.SlidingWindowType slidingWindowType)
Configures the type of the sliding window which is used to record the outcome of calls
when the CircuitBreaker is closed.
|
CircuitBreakerConfig.Builder |
slowCallDurationThreshold(java.time.Duration slowCallDurationThreshold)
Configures the duration threshold above which calls are considered as slow and increase
the slow calls percentage.
|
CircuitBreakerConfig.Builder |
slowCallRateThreshold(float slowCallRateThreshold)
Configures a threshold in percentage.
|
CircuitBreakerConfig.Builder |
waitDurationInOpenState(java.time.Duration waitDurationInOpenState)
Configures an interval function with a fixed wait duration which controls how long the
CircuitBreaker should stay open, before it switches to half open.
|
CircuitBreakerConfig.Builder |
waitIntervalFunctionInOpenState(io.github.resilience4j.core.IntervalFunction waitIntervalFunctionInOpenState)
Configures an interval function which controls how long the CircuitBreaker should stay
open, before it switches to half open.
|
CircuitBreakerConfig.Builder |
writableStackTraceEnabled(boolean writableStackTraceEnabled)
Enables writable stack traces.
|
public Builder(CircuitBreakerConfig baseConfig)
public Builder()
public CircuitBreakerConfig.Builder failureRateThreshold(float failureRateThreshold)
The threshold must be greater than 0 and not greater than 100. Default value is 50 percentage.
failureRateThreshold
- the failure rate threshold in percentagejava.lang.IllegalArgumentException
- if failureRateThreshold <= 0 ||
failureRateThreshold > 100
public CircuitBreakerConfig.Builder slowCallRateThreshold(float slowCallRateThreshold)
slowCallDurationThreshold(Duration)
. When the
percentage of slow calls is equal to or greater than the threshold, the CircuitBreaker
transitions to open and starts short-circuiting calls.
The threshold must be greater than 0 and not greater than 100. Default value is 100
percentage which means that all recorded calls must be slower than slowCallDurationThreshold(Duration)
.
slowCallRateThreshold
- the slow calls threshold in percentagejava.lang.IllegalArgumentException
- if slowCallRateThreshold <= 0 ||
slowCallRateThreshold > 100
public CircuitBreakerConfig.Builder writableStackTraceEnabled(boolean writableStackTraceEnabled)
Throwable.getStackTrace()
returns a zero length array. This may be used to reduce log spam when the circuit breaker
is open as the cause of the exceptions is already known (the circuit breaker is
short-circuiting calls).writableStackTraceEnabled
- the flag to enable writable stack traces.public CircuitBreakerConfig.Builder waitDurationInOpenState(java.time.Duration waitDurationInOpenState)
waitDurationInOpenState
- the wait duration which specifies how long the
CircuitBreaker should stay openjava.lang.IllegalArgumentException
- if waitDurationInOpenState.toMillis() < 1
public CircuitBreakerConfig.Builder waitIntervalFunctionInOpenState(io.github.resilience4j.core.IntervalFunction waitIntervalFunctionInOpenState)
A custom interval function is useful if you need an exponential backoff algorithm.
waitIntervalFunctionInOpenState
- Interval function that returns wait time as a
function of attemptspublic CircuitBreakerConfig.Builder slowCallDurationThreshold(java.time.Duration slowCallDurationThreshold)
slowCallDurationThreshold
- the duration above which calls are considered as slowjava.lang.IllegalArgumentException
- if slowCallDurationThreshold.toNanos() < 1
public CircuitBreakerConfig.Builder permittedNumberOfCallsInHalfOpenState(int permittedNumberOfCallsInHalfOpenState)
The size must be greater than 0. Default size is 10.
permittedNumberOfCallsInHalfOpenState
- the permitted number of calls when the
CircuitBreaker is half openjava.lang.IllegalArgumentException
- if permittedNumberOfCallsInHalfOpenState < 1
@Deprecated public CircuitBreakerConfig.Builder ringBufferSizeInHalfOpenState(int ringBufferSizeInHalfOpenState)
permittedNumberOfCallsInHalfOpenState(int)
instead.@Deprecated public CircuitBreakerConfig.Builder ringBufferSizeInClosedState(int ringBufferSizeInClosedState)
#slidingWindow(int, int, SlidingWindowType)
instead.public CircuitBreakerConfig.Builder slidingWindow(int slidingWindowSize, int minimumNumberOfCalls, CircuitBreakerConfig.SlidingWindowType slidingWindowType)
slidingWindowSize
configures the size of the sliding
window. Sliding window can either be count-based or time-based, specified by slidingWindowType
. minimumNumberOfCalls
configures the minimum number of calls
which are required (per sliding window period) before the CircuitBreaker can calculate
the error rate. For example, if minimumNumberOfCalls
is 10, then at least 10
calls must be recorded, before the failure rate can be calculated. If only 9 calls have
been recorded, the CircuitBreaker will not transition to open, even if all 9 calls have
failed.
If slidingWindowSize
is 100 and slidingWindowType
is COUNT_BASED, the
last 100 calls are recorded and aggregated. If slidingWindowSize
is 10 and slidingWindowType
is TIME_BASED, the calls of the last 10 seconds are recorded and
aggregated.
The slidingWindowSize
must be greater than 0. The minimumNumberOfCalls
must be greater than 0. If the slidingWindowType
is COUNT_BASED, the minimumNumberOfCalls
may not be greater than slidingWindowSize
. If a greater
value is provided, minimumNumberOfCalls
will be equal to slidingWindowSize
. If the slidingWindowType
is TIME_BASED, the minimumNumberOfCalls
may be any amount.
Default slidingWindowSize is 100, minimumNumberOfCalls is 100 and slidingWindowType is COUNT_BASED.
slidingWindowSize
- the size of the sliding window when the CircuitBreaker is
closed.minimumNumberOfCalls
- the minimum number of calls that must be recorded before the
failure rate can be calculated.slidingWindowType
- the type of the sliding window. Either COUNT_BASED or
TIME_BASED.java.lang.IllegalArgumentException
- if slidingWindowSize < 1 || minimumNumberOfCalls
< 1
public CircuitBreakerConfig.Builder slidingWindowSize(int slidingWindowSize)
slidingWindowSize
configures the size of the
sliding window.
The slidingWindowSize
must be greater than 0.
Default slidingWindowSize is 100.
slidingWindowSize
- the size of the sliding window when the CircuitBreaker is
closed.java.lang.IllegalArgumentException
- if slidingWindowSize < 1
#slidingWindow(int, int, SlidingWindowType)
public CircuitBreakerConfig.Builder minimumNumberOfCalls(int minimumNumberOfCalls)
minimumNumberOfCalls
is 10, then at least 10 calls must be recorded, before the failure
rate can be calculated. If only 9 calls have been recorded, the CircuitBreaker will not
transition to open, even if all 9 calls have failed.
Default minimumNumberOfCalls is 100
minimumNumberOfCalls
- the minimum number of calls that must be recorded before the
failure rate can be calculated.java.lang.IllegalArgumentException
- if minimumNumberOfCalls < 1
#slidingWindow(int, int, SlidingWindowType)
public CircuitBreakerConfig.Builder slidingWindowType(CircuitBreakerConfig.SlidingWindowType slidingWindowType)
Default slidingWindowType is COUNT_BASED.
slidingWindowType
- the type of the sliding window. Either COUNT_BASED or
TIME_BASED.#slidingWindow(int, int, SlidingWindowType)
@Deprecated public CircuitBreakerConfig.Builder recordFailure(java.util.function.Predicate<java.lang.Throwable> predicate)
recordException(Predicate)
instead.public CircuitBreakerConfig.Builder recordException(java.util.function.Predicate<java.lang.Throwable> predicate)
ignoreExceptions(Class[])
or ignoreException(Predicate)
.predicate
- the Predicate which evaluates if an exception should count as a failurepublic CircuitBreakerConfig.Builder ignoreException(java.util.function.Predicate<java.lang.Throwable> predicate)
predicate
- the Predicate which evaluates if an exception should count as a failure@SafeVarargs public final CircuitBreakerConfig.Builder recordExceptions(@Nullable java.lang.Class<? extends java.lang.Throwable>... errorClasses)
ignoreExceptions(Class[])
or ignoreException(Predicate)
.errorClasses
- the error classes that are recorded). Ignoring an exception has priority over recording an
exception.
Example: recordExceptions(Throwable.class) and ignoreExceptions(RuntimeException.class)
would capture all Errors and checked Exceptions, and ignore RuntimeExceptions.
For a more sophisticated exception management use the
,
method
@SafeVarargs public final CircuitBreakerConfig.Builder ignoreExceptions(@Nullable java.lang.Class<? extends java.lang.Throwable>... errorClasses)
recordExceptions(Class[])
or recordException(Predicate)
.errorClasses
- the error classes that are ignored. Ignoring an exception has priority over recording an
exception.
Example: ignoreExceptions(Throwable.class) and recordExceptions(Exception.class) would
capture nothing.
Example: ignoreExceptions(Exception.class) and recordExceptions(Throwable.class) would
capture Errors.
For a more sophisticated exception management use the
,
method
public CircuitBreakerConfig.Builder enableAutomaticTransitionFromOpenToHalfOpen()
public CircuitBreakerConfig.Builder automaticTransitionFromOpenToHalfOpenEnabled(boolean enableAutomaticTransitionFromOpenToHalfOpen)
enableAutomaticTransitionFromOpenToHalfOpen
- the flag to enable the automatic
transitioning.public CircuitBreakerConfig build()