public static class CircuitBreakerConfig.Builder
extends java.lang.Object
Constructor and Description |
---|
Builder() |
Modifier and Type | Method and Description |
---|---|
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 above which the CircuitBreaker should trip open and start short-circuiting calls.
|
CircuitBreakerConfig.Builder |
ignoreExceptions(java.lang.Class<? extends java.lang.Throwable>... errorClasses)
Configures a list of error classes that are ignored as a failure and thus do not 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)
Configures a Predicate which evaluates if an exception should be recorded as a failure and thus increase the failure rate.
|
CircuitBreakerConfig.Builder |
ringBufferSizeInClosedState(int ringBufferSizeInClosedState)
Configures the size of the ring buffer when the CircuitBreaker is closed.
|
CircuitBreakerConfig.Builder |
ringBufferSizeInHalfOpenState(int ringBufferSizeInHalfOpenState)
Configures the size of the ring buffer when the CircuitBreaker is half open.
|
CircuitBreakerConfig.Builder |
waitDurationInOpenState(java.time.Duration waitDurationInOpenState)
Configures the wait duration which specifies how long the CircuitBreaker should stay open, before it switches to half open.
|
public CircuitBreakerConfig.Builder failureRateThreshold(float failureRateThreshold)
failureRateThreshold
- the failure rate threshold in percentagepublic CircuitBreakerConfig.Builder waitDurationInOpenState(java.time.Duration waitDurationInOpenState)
waitDurationInOpenState
- the wait duration which specifies how long the CircuitBreaker should stay openpublic CircuitBreakerConfig.Builder ringBufferSizeInHalfOpenState(int ringBufferSizeInHalfOpenState)
ringBufferSizeInClosedState
is 10, then at least 10 calls must be evaluated, before the failure rate can be calculated.
If only 9 calls have been evaluated the CircuitBreaker will not trip back to closed or open even if all 9 calls have failed.
The size must be greater than 0. Default size is 10.ringBufferSizeInHalfOpenState
- the size of the ring buffer when the CircuitBreaker is is half openpublic CircuitBreakerConfig.Builder ringBufferSizeInClosedState(int ringBufferSizeInClosedState)
ringBufferSizeInClosedState
is 100, then at least 100 calls must be evaluated, before the failure rate can be calculated.
If only 99 calls have been evaluated the CircuitBreaker will not trip open even if all 99 calls have failed.
The size must be greater than 0. Default size is 100.ringBufferSizeInClosedState
- the size of the ring buffer when the CircuitBreaker is closed.public CircuitBreakerConfig.Builder recordFailure(java.util.function.Predicate<java.lang.Throwable> predicate)
predicate
- the Predicate which evaluates if an exception should be recorded as a failure and thus trigger the CircuitBreaker@SafeVarargs public final CircuitBreakerConfig.Builder recordExceptions(java.lang.Class<? extends java.lang.Throwable>... errorClasses)
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 unchecked
For a more sophisticated exception management use the
,
method
@SafeVarargs public final CircuitBreakerConfig.Builder ignoreExceptions(java.lang.Class<? extends java.lang.Throwable>... errorClasses)
errorClasses
- the error classes that are recorded. 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 build()