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 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 the wait duration which specifies 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 percentagepublic CircuitBreakerConfig.Builder slowCallRateThreshold(float slowCallRateThreshold)
slowCallDurationThreshold(Duration).
When the percentage of slow calls is equal or greater 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 percentagepublic 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).public CircuitBreakerConfig.Builder waitDurationInOpenState(java.time.Duration waitDurationInOpenState)
waitDurationInOpenState - the wait duration which specifies how long the CircuitBreaker should stay openpublic CircuitBreakerConfig.Builder slowCallDurationThreshold(java.time.Duration slowCallDurationThreshold)
slowCallDurationThreshold - the duration above which calls are considered as slowpublic 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 open@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.
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 cannot be greater than slidingWindowSize.
If the slidingWindowType is TIME_BASED, you can pick whatever you want.
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.public CircuitBreakerConfig.Builder slidingWindowSize(int slidingWindowSize)
slidingWindowSize configures the size of the sliding window. Sliding window can either be count-based or time-based.
If slidingWindowType is COUNT_BASED, the last slidingWindowSize calls are recorded and aggregated.
If slidingWindowType is TIME_BASED, the calls of the last slidingWindowSize 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 cannot be greater than slidingWindowSize.
If the slidingWindowType is TIME_BASED, you can pick whatever you want.
Default slidingWindowSize is 100.
slidingWindowSize - the size of the sliding window when the CircuitBreaker is closed.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 100minimumNumberOfCalls - the minimum number of calls that must be recorded before the failure rate can be calculated.public CircuitBreakerConfig.Builder slidingWindowType(CircuitBreakerConfig.SlidingWindowType slidingWindowType)
slidingWindowType is COUNT_BASED, the last slidingWindowSize calls are recorded and aggregated.
If slidingWindowType is TIME_BASED, the calls of the last slidingWindowSize seconds are recorded and aggregated.
Default slidingWindowType is COUNT_BASED.slidingWindowType - the type of the sliding window. Either COUNT_BASED or TIME_BASED.@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)
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)
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
,
methodpublic CircuitBreakerConfig.Builder enableAutomaticTransitionFromOpenToHalfOpen()
public CircuitBreakerConfig.Builder automaticTransitionFromOpenToHalfOpenEnabled(boolean enableAutomaticTransitionFromOpenToHalfOpen)
public CircuitBreakerConfig build()