CircuitBreakerConfigBuilder

class CircuitBreakerConfigBuilder(val baseConfig: CircuitBreakerConfig = defaultCircuitBreakerConfig) : ConfigBuilder<CircuitBreakerConfig> (source)

Builder for configuring a CircuitBreakerConfig instance. Use circuitBreakerConfig to create one.

Constructors

Link copied to clipboard
constructor(baseConfig: CircuitBreakerConfig = defaultCircuitBreakerConfig)

Types

Link copied to clipboard
private object Companion

Properties

Link copied to clipboard
open override val baseConfig: CircuitBreakerConfig

The base configuration object to be used as a starting point for building the final configuration object.

Link copied to clipboard

Configures the rate in percentage (e.g., 0.5 for 50%) of calls recorded as failure that will trigger the circuit breaker to transition to the Open state, if equalled or exceeded.

Link copied to clipboard

Configures the maximum duration the circuit breaker will wait in the HalfOpen state before transitioning to the Open state automatically. If set to Duration.ZERO, the circuit breaker will wait indefinitely in the HalfOpen state until permittedNumberOfCallsInHalfOpenState is reached.

Link copied to clipboard

Configures the number of calls that are allowed to be made in the HalfOpen state. If this number is exceeded, further calls will be rejected. If maxWaitDurationInHalfOpenState is set to Duration.ZERO, the circuit breaker will wait indefinitely in the HalfOpen state until the permitted number of calls is reached.

Link copied to clipboard
Link copied to clipboard

Functions

Link copied to clipboard
open override fun build(): CircuitBreakerConfig

Builds the final configuration object after applying possible modifications to the base configuration.

Link copied to clipboard

Configures the circuit breaker delay strategy to use a constant delay between transitions from Open to HalfOpen.

Link copied to clipboard
fun customDelayInOpenState(delayStrategyInOpenState: DelayStrategy)

Configures the circuit breaker delay strategy to use a custom delay between transitions from Open to HalfOpen, based on the current attempt and additional context. The current attempt is the number of times the circuit breaker is in the Open state in one cycle.

Link copied to clipboard

Configures the circuit breaker delay strategy to use a custom delay provider between transitions from Open to HalfOpen. In contrast to customDelayInOpenState, this method enables caller control over the delay provider (which is the kotlinx.coroutines.delay by default) and optional additional state between transitions. See DelayProvider for more information.

Link copied to clipboard
fun exponentialDelayInOpenState(initialDelay: Duration = 500L.milliseconds, multiplier: Double = 2.0, maxDelay: Duration = 1.minutes)

Configures the circuit breaker delay strategy to use an exponential backoff algorithm to calculate the next delay duration between transitions from Open to HalfOpen. The algorithm is based on the formula:

Link copied to clipboard
fun linearDelayInOpenState(initialDelay: Duration = 500L.milliseconds, multiplier: Double = 1.0, maxDelay: Duration = 1.minutes)

Configures the circuit breaker delay strategy to use a linear backoff algorithm to calculate the next delay duration between transitions from Open to HalfOpen.

Link copied to clipboard

Configures the circuit breaker delay strategy to use no delay between transitions from Open to HalfOpen.

Link copied to clipboard

Configures the predicate that determines whether an exception should be recorded as a failure, and as such, increase the failure rate.

Link copied to clipboard

Configures the predicate that determines whether a result of an operation should be recorded as a failure, and as such, increase the failure rate.

Link copied to clipboard
fun slidingWindow(size: Int, minimumThroughput: Int = 100, type: SlidingWindowType = COUNT_BASED)

Configures the sliding window used to record calls and calculate the failure rate.