Top Description Methods
org.eclipse.microprofile.faulttolerance

public @Interface CircuitBreaker

extends Annotation
Annotations
@Inherited
@Retention:RUNTIME
@Documented
@InterceptorBinding
@Target:METHOD, TYPE
Imports
java.lang.annotation.Documented, .ElementType, .Inherited, .Retention, .RetentionPolicy, .Target, java.time.temporal.ChronoUnit, jakarta.enterprise.util.Nonbinding, jakarta.interceptor.InterceptorBinding

Defines a circuit breaker policy to an individual method or a class.

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:

Circuit state transitions will reset the circuit breaker's records.

When a method returns a result, the following rules are applied to determine whether the result is a success or a failure:

If a method throws a Throwable which is not an Error or Exception, non-portable behavior results.
Author
Emily Jiang
See Also
failOn(), skipOn(), delay(), delayUnit(), requestVolumeThreshold(), failureRatio(), successThreshold()

Method Summary

Modifier and TypeMethod and Description
public long

Returns:

the delay time after which an open circuit transitions to half-open state
delay
()

The delay after which an open circuit will transitions to half-open state.

public ChronoUnit

Returns:

The unit of the delay
delayUnit
()

The unit of the delay after which an open circuit will transitions to half-open state.

public Class<? extends Throwable>[]

Returns:

the exception types which should be considered failures
failOn
()

The list of exception types which should be considered failures.

public double

Returns:

the failure ratio threshold
failureRatio
()

The 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 window
requestVolumeThreshold
()

The number of consecutive requests in a rolling window.

public Class<? extends Throwable>[]

Returns:

the exception types which should not be considered failures
skipOn
()

The list of exception types which should not be considered failures.

public int

Returns:

the success threshold to fully close the circuit
successThreshold
()

The number of successful executions, before a half-open circuit is closed again.

Inherited from java.lang.annotation.Annotation:
annotationTypeequalshashCodetoString

Method Detail

delayback 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, and defaults to five seconds. The value must be greater than or equal to 0. 0 means no delay.

Returns:long

the delay time after which an open circuit transitions to half-open state

Annotations
@Nonbinding
delayUnitback to summary
public ChronoUnit delayUnit()

The unit of the delay after which an open circuit will transitions to half-open state.

Returns:ChronoUnit

The unit of the delay

Annotations
@Nonbinding
See Also
CircuitBreaker#delay()
failOnback to summary
public Class<? extends Throwable>[] failOn()

The list of exception types which should be considered failures.

Note that if a method throws a Throwable which is not an Error or Exception, non-portable behavior results.

Returns:Class<? extends Throwable>[]

the exception types which should be considered failures

Annotations
@Nonbinding
failureRatioback 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 failureRatio within the rolling window of consecutive requests. For example, if the requestVolumeThreshold is 20 and failureRatio is .50, ten or more failures in 20 consecutive requests will trigger the circuit to open. The value must be between 0 and 1 inclusive.

Returns:double

the failure ratio threshold

Annotations
@Nonbinding
requestVolumeThresholdback 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 failureRatio within the rolling window of consecutive requests. The value must be greater than or equal to 1.

Returns:int

the number of the consecutive requests in a rolling window

Annotations
@Nonbinding
skipOnback to summary
public Class<? extends Throwable>[] skipOn()

The list of exception types which should not be considered failures.

This list takes priority over the types listed in failOn.

Note that if a method throws a Throwable which is not an Error or Exception, non-portable behavior results.

Returns:Class<? extends Throwable>[]

the exception types which should not be considered failures

Annotations
@Nonbinding
successThresholdback 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 successThreshold executions were made without failures. If a failure occurs while in half-open state the circuit is immediately opened again. The value must be greater than or equal to 1.

Returns:int

the success threshold to fully close the circuit

Annotations
@Nonbinding