Circuit Breaker
Thread-safe circuit breaker that automatically disables calls after repeated failures.
States:
CLOSED (normal): calls pass through. Failures are counted within a sliding window.
OPEN (tripped): calls are rejected immediately. After cooldownMs elapses, the breaker transitions to HALF_OPEN.
HALF_OPEN (probing): one call is allowed through. If it succeeds the breaker resets to CLOSED; if it fails the breaker re-opens.
Parameters
Human-readable label used in log messages
Number of failures within windowMs that trip the breaker
Sliding time window for counting failures (milliseconds)
How long the breaker stays OPEN before transitioning to HALF_OPEN
Constructors
Functions
Returns true if a call should be allowed through.
Number of failures recorded in the current window.
Records a failed call. In HALF_OPEN, immediately re-opens the breaker. In CLOSED, increments the failure counter and trips the breaker if the threshold is reached.
Records a successful call. Resets the breaker to CLOSED if it was HALF_OPEN.
Current breaker state.