CircuitBreakerStateReducer

A thread-safe state machine that acts as a reducer for a CircuitBreaker. Using the dispatch method, events can be dispatched to the state machine to trigger state transitions. The current state can be consulted using the currentState method.

Parameters

slidingWindow

the sliding window used to record the result (success or failure) of operations and calculate the failure rate.

config

the configuration of the circuit breaker.

events

the shared flow to emit circuit breaker events to.

Constructors

Link copied to clipboard
constructor(slidingWindow: FailureRateSlidingWindow<T>, config: CircuitBreakerConfig, events: MutableSharedFlow<CircuitBreakerEvent>)

Properties

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
val events: MutableSharedFlow<CircuitBreakerEvent>
Link copied to clipboard
Link copied to clipboard
private val lock: Mutex
Link copied to clipboard

Functions

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open suspend override fun currentState(): CircuitBreakerState

Returns the current state of the reducer.

Link copied to clipboard
open suspend override fun dispatch(event: CircuitBreakerReducerEvent)

Dispatches an event to the reducer to trigger a state transition.

Link copied to clipboard
private suspend fun recordFailure()
Link copied to clipboard
private suspend fun recordSuccess()
Link copied to clipboard

Given the current state and an event, reduces the event to a new state and a list of effects.

Link copied to clipboard
private suspend fun reset(): CircuitBreakerState