A circuit breaker aims to prevent further damage by not executing functionality that is doomed to fail. After a failure situation has been detected, circuit breakers prevent methods from being executed and instead throw exceptions immediately. After a certain delay or wait time, the functionality is attempted to be executed again.
A circuit breaker can be in one of the following states:
requestVolumeThreshold and failureRatio parameters may be configured in
order to specify the conditions under which the breaker will transition the circuit to open. If the failure
conditions are met, the circuit will be opened.successThreshold
parameter allows the configuration of the number of trial executions that must succeed before the circuit can be
closed. After the specified number of successful executions, the circuit will be closed. If a failure occurs before
the successThreshold is reached the circuit will transition to open.When a method returns a result, the following rules are applied to determine whether the result is a success or a failure:
Throwable, it is considered a success
skipOn() parameter, it is considered a
success
failOn() parameter, it is considered a
failure
Throwable which is not an Error or Exception, non-portable behavior
results.
failOn(), skipOn(), delay(), delayUnit(), requestVolumeThreshold(), failureRatio(), successThreshold()
| Modifier and Type | Method and Description |
|---|---|
| public long | Returns: the delay time after which an open circuit transitions to half-open stateThe delay after which an open circuit will transitions to half-open state. |
| public ChronoUnit | Returns: The unit of the delayThe unit of the delay after which an open circuit will transitions to half-open state. |
| public Class | Returns: the exception types which should be considered failuresThe list of exception types which should be considered failures. |
| public double | Returns: the failure ratio thresholdThe ratio of failures within the rolling window that will trip the circuit to open. |
| public int | Returns: the number of the consecutive requests in a rolling windowThe number of consecutive requests in a rolling window. |
| public Class | Returns: the exception types which should not be considered failuresThe list of exception types which should not be considered failures. |
| public int | Returns: the success threshold to fully close the circuitThe number of successful executions, before a half-open circuit is closed again. |
| delay | back to summary |
|---|---|
| public long delay() The delay after which an open circuit will transitions to half-open state.
The amount of delay is taken from this delay value and the
| |
| delayUnit | back to summary |
|---|---|
| public ChronoUnit delayUnit() The unit of the delay after which an open circuit will transitions to half-open state.
| |
| failOn | back to summary |
|---|---|
| public Class The list of exception types which should be considered failures.
Note that if a method throws a | |
| failureRatio | back to summary |
|---|---|
| public double failureRatio() The ratio of failures within the rolling window that will trip the circuit to open.
The circuit breaker will trip if the number of failures exceed the
| |
| requestVolumeThreshold | back to summary |
|---|---|
| public int requestVolumeThreshold() The number of consecutive requests in a rolling window.
The circuit breaker will trip if the number of failures exceed the
| |
| skipOn | back to summary |
|---|---|
| public Class The list of exception types which should not be considered failures.
This list takes priority over the types listed in
Note that if a method throws a | |
| successThreshold | back to summary |
|---|---|
| public int successThreshold() The number of successful executions, before a half-open circuit is closed again.
A half-open circuit will be closed once
| |