Class CircuitBreaker
java.lang.Object
com.cockroachlabs.crdb.circuit.CircuitBreaker
A thread-safe circuit breaker.
In State.CLOSED it counts consecutive failures; once the count
reaches the threshold it trips State.OPEN and rejects calls with
CrdbException(CircuitOpen) until the reset timeout elapses,
after which a single State.HALF_OPEN trial probes recovery.
-
Constructor Summary
ConstructorsConstructorDescriptionCircuitBreaker(int failureThreshold, long resetTimeoutMillis) CircuitBreaker(int failureThreshold, long resetTimeoutMillis, LongSupplier clock) -
Method Summary
-
Constructor Details
-
CircuitBreaker
public CircuitBreaker(int failureThreshold, long resetTimeoutMillis) -
CircuitBreaker
- Parameters:
clock- supplies the current time in millis (inject for tests)
-
-
Method Details
-
state
Current breaker state (snapshot). -
execute
Executeworkthrough the breaker.- Throws:
CrdbException- with aCircuitOpenanomaly when the breaker is open (call is not attempted)
-