Interface CircuitBreaker
public interface CircuitBreaker
ServiceTalk API for a Circuit Breaker.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Forcefully open the breaker, if automatic state transition is supported it should be disabled after this call.void
Releases a previouslyacquired
permit, without influencing the breaker in any way.name()
Return the name of thisCircuitBreaker
.void
Track a failed call and the reason.void
Track a successful call.If the state of the breaker is open, this retrieves the remaining duration it should stay open.void
reset()
Returns the circuit breaker to its original closed state and resetting any internal state (timers, metrics).boolean
Attempt to acquire a permit to execute a call.
-
Method Details
-
name
String name()Return the name of thisCircuitBreaker
.- Returns:
- the name of this
CircuitBreaker
.
-
tryAcquirePermit
boolean tryAcquirePermit()Attempt to acquire a permit to execute a call.- Returns:
true
when a permit was successfully acquired.
-
ignorePermit
void ignorePermit()Releases a previouslyacquired
permit, without influencing the breaker in any way. In other words this permit is considered ignored. -
onError
Track a failed call and the reason.- Parameters:
duration
- – The elapsed time duration of the calldurationUnit
- – The duration unitthrowable
- – The throwable which must be recorded
-
onSuccess
Track a successful call.- Parameters:
duration
- The elapsed time duration of the calldurationUnit
- The duration unit
-
forceOpenState
void forceOpenState()Forcefully open the breaker, if automatic state transition is supported it should be disabled after this call. -
reset
void reset()Returns the circuit breaker to its original closed state and resetting any internal state (timers, metrics). -
remainingDurationInOpenState
Duration remainingDurationInOpenState()If the state of the breaker is open, this retrieves the remaining duration it should stay open. Expectation is that after this duration, the breaker shall allow/offer more permits.- Returns:
- The remaining duration that the breaker will remain open.
-