CircuitBreakerRegistry

Registry of named DefaultCircuitBreaker instances so multiple com.santimattius.resilient.ResilientPolicy configurations can share the same circuit breaker (e.g. one breaker per downstream service "payments", "db").

Thread-safety: getOrCreate is not synchronized across platforms. Typical use is to build policies on a single thread at startup; do not call getOrCreate concurrently for the same registry without external synchronization.

The first getOrCreate call for a given name wins; subsequent calls return the same instance and ignore the configure block (document your convention: one name, one config).

Telemetry limitation: because a DefaultCircuitBreaker accepts a single onStateChanged callback at construction time, only the first policy that registers a name receives state-change events via its com.santimattius.resilient.ResilientPolicy.events SharedFlow. Policies that reuse an existing registry entry will not receive com.santimattius.resilient.telemetry.ResilientEvent.CircuitStateChanged events from the shared breaker. Use the registry DefaultCircuitBreaker.state StateFlow directly for shared observability.

Constructors

Link copied to clipboard
constructor()

Functions

Link copied to clipboard
fun getOrCreate(name: String, configure: CircuitBreakerConfig.() -> Unit, onStateChanged: (CircuitState, CircuitState) -> Unit? = null): DefaultCircuitBreaker

Returns an existing DefaultCircuitBreaker for name, or creates one with configure.