A CircuitBreaker manages the state of a backend system. The CircuitBreaker is implemented
via a finite state machine with five states: CLOSED, OPEN, HALF_OPEN, DISABLED AND FORCED_OPEN.
The CircuitBreaker does not know anything about the backend's state by itself, but uses the
information provided by the decorators via CircuitBreaker#onSuccess and CircuitBreaker#onError events. Before communicating with the backend, the permission to do so
must be obtained via the method CircuitBreaker#tryAcquirePermission().
The state of the CircuitBreaker changes from CLOSED to OPEN when the failure rate is greater than or equal to a (configurable) threshold. Then, all access to the backend is rejected for a (configurable) time duration. No further calls are permitted.
After the time duration has elapsed, the CircuitBreaker state changes from OPEN to HALF_OPEN and allows a number of calls to see if the backend is still unavailable or has become available again. If the failure rate is greater than or equal to the configured threshold, the state changes back to OPEN. If the failure rate is below or equal to the threshold, the state changes back to CLOSED.
| Modifier and Type | Class and Description |
|---|---|
| public static class | CircuitBreaker.
of return type T>This class decorates future to add CircuitBreaking functionality around invocation. |
| public static interface | CircuitBreaker.
An EventPublisher can be used to register event consumers. |
| public static interface | |
| public static enum | CircuitBreaker.
States of the CircuitBreaker state machine. |
| public static enum | CircuitBreaker.
State transitions of the CircuitBreaker state machine. |
| Modifier and Type | Method and Description |
|---|---|
| public void | |
| public static < the result type of callable T> Callable | Returns: a supplier which is decorated by a CircuitBreaker.the CircuitBreaker circuitBreaker, Callable<T> the original Callable callable)Returns a callable which is decorated by a CircuitBreaker. |
| public default < the result type of callable T> Callable | Returns: a supplier which is decorated by a CircuitBreaker.the original Callable callable)Returns a callable which is decorated by a CircuitBreaker. |
| public static < the type of the input to the consumer T> CheckedConsumer | Returns: a consumer which is decorated by a CircuitBreaker.the CircuitBreaker circuitBreaker, CheckedConsumer<T> the original consumer consumer)Returns a consumer which is decorated by a CircuitBreaker. |
| public default < the type of the input to the consumer T> CheckedConsumer | Returns: a consumer which is decorated by a CircuitBreaker.the original consumer consumer)Returns a consumer which is decorated by a CircuitBreaker. |
| public static < the type of the input to the function T, the type of the result of the function R> CheckedFunction | Returns: a function which is decorated by a CircuitBreaker.the CircuitBreaker circuitBreaker, CheckedFunction<T, R> the original function function)Returns a function which is decorated by a CircuitBreaker. |
| public static CheckedRunnable | Returns: a runnable which is decorated by a CircuitBreaker.the CircuitBreaker circuitBreaker, CheckedRunnable the original runnable runnable)Returns a runnable which is decorated by a CircuitBreaker. |
| public default CheckedRunnable | Returns: a runnable which is decorated by a CircuitBreaker.the original runnable runnable)Returns a runnable which is decorated by a CircuitBreaker. |
| public static < the type of results supplied by this supplier T> CheckedSupplier | Returns: a supplier which is decorated by a CircuitBreaker.the CircuitBreaker circuitBreaker, CheckedSupplier<T> the original supplier supplier)Returns a supplier which is decorated by a CircuitBreaker. |
| public default < the type of results supplied by this supplier T> CheckedSupplier | Returns: a supplier which is decorated by a CircuitBreaker.the original supplier checkedSupplier)Returns a supplier which is decorated by a CircuitBreaker. |
| public static < the type of the returned CompletionStage's result T> Supplier | Returns: a supplier which is decorated by a CircuitBreaker.the CircuitBreaker circuitBreaker, Supplier<CompletionStage<T>> the original supplier supplier)Returns a supplier which is decorated by a CircuitBreaker. |
| public default < the type of the returned CompletionStage's result T> Supplier | Returns: a supplier which is decorated by a CircuitBreaker.the original supplier supplier)Returns a supplier which is decorated by a CircuitBreaker. |
| public static < the type of the input to the consumer T> Consumer | Returns: a consumer which is decorated by a CircuitBreaker.the CircuitBreaker circuitBreaker, Consumer<T> the original consumer consumer)Returns a consumer which is decorated by a CircuitBreaker. |
| public default < the type of the input to the consumer T> Consumer | Returns: a consumer which is decorated by a CircuitBreaker.the original consumer consumer)Returns a consumer which is decorated by a CircuitBreaker. |
| public static < the type of the input to the function T, the type of the result of the function R> Function | Returns: a function which is decorated by a CircuitBreaker.the CircuitBreaker circuitBreaker, Function<T, R> the original function function)Returns a function which is decorated by a CircuitBreaker. |
| public static < the type of the returned Future's result T> Supplier | Returns: a supplier which is decorated by a CircuitBreaker.the CircuitBreaker circuitBreaker, Supplier<Future<T>> the original supplier supplier)Returns a supplier of type Future which is decorated by a CircuitBreaker. |
| public default < the type of the returned CompletionStage's result T> Supplier | Returns: a supplier which is decorated by a CircuitBreaker.the original supplier supplier)Returns a supplier of type Future which is decorated by a CircuitBreaker. |
| public static Runnable | Returns: a runnable which is decorated by a CircuitBreaker.the CircuitBreaker circuitBreaker, Runnable the original runnable runnable)Returns a runnable which is decorated by a CircuitBreaker. |
| public default Runnable | Returns: a runnable which is decorated by a CircuitBreaker.the original runnable runnable)Returns a runnable which is decorated by a CircuitBreaker. |
| public static < the type of results supplied by this supplier T> Supplier | Returns: a supplier which is decorated by a CircuitBreaker.the CircuitBreaker circuitBreaker, Supplier<T> the original supplier supplier)Returns a supplier which is decorated by a CircuitBreaker. |
| public default < the type of results supplied by this supplier T> Supplier | Returns: a supplier which is decorated by a CircuitBreaker.the original supplier supplier)Returns a supplier which is decorated by a CircuitBreaker. |
| public default < the result type of callable T> T | Returns: the result of the decorated Callable.the original Callable callable)Decorates and executes the decorated Callable. |
| public default void | executeCheckedRunnable(CheckedRunnable
the original runnable runnable)Decorates and executes the decorated Runnable. |
| public default < the type of results supplied by this supplier T> T | Returns: the result of the decorated Supplier.the original Supplier checkedSupplier)Decorates and executes the decorated Supplier. |
| public default < the type of results supplied by this supplier T> CompletionStage | Returns: the decorated CompletionStage.the original CompletionStage supplier)Decorates and executes the decorated CompletionStage. |
| public default void | executeRunnable(Runnable
the original Runnable runnable)Decorates and executes the decorated Runnable. |
| public default < the type of results supplied by this supplier T> T | Returns: the result of the decorated Supplier.the original Supplier supplier)Decorates and executes the decorated Supplier. |
| public CircuitBreakerConfig | Returns: the CircuitBreakerConfig of this CircuitBreakerReturns the CircuitBreakerConfig of this CircuitBreaker. |
| public long | Returns: current timestampReturns the current time with respect to the CircuitBreaker currentTimeFunction. |
| public CircuitBreaker. | Returns: an EventPublisherReturns an EventPublisher which can be used to register event consumers. |
| public CircuitBreaker. | |
| public String | |
| public CircuitBreaker. | |
| public Map | Returns: the tags assigned to this CircuitBreaker in an unmodifiable mapReturns an unmodifiable map with tags assigned to this CircuitBreaker. |
| public TimeUnit | Returns: the timeUnit of current timestampReturns the timeUnit of current timestamp. |
| public static CircuitBreaker | Returns: a CircuitBreaker with a custom CircuitBreaker configuration.the name of the CircuitBreaker name, CircuitBreakerConfig a custom CircuitBreaker configuration circuitBreakerConfig)Creates a CircuitBreaker with a custom CircuitBreaker configuration. |
| public static CircuitBreaker | Returns: a CircuitBreaker with a custom CircuitBreaker configuration.the name of the CircuitBreaker name, CircuitBreakerConfig a custom CircuitBreaker configuration circuitBreakerConfig, Map<String, String> tags added to the CircuitBreaker tags)Creates a CircuitBreaker with a custom CircuitBreaker configuration. |
| public static CircuitBreaker | Returns: a CircuitBreaker with a custom CircuitBreaker configuration.the name of the CircuitBreaker name, Supplier<CircuitBreakerConfig> a supplier of a custom CircuitBreaker configuration circuitBreakerConfigSupplier)Creates a CircuitBreaker with a custom CircuitBreaker configuration. |
| public static CircuitBreaker | Returns: a CircuitBreaker with a custom CircuitBreaker configuration.the name of the CircuitBreaker name, Supplier<CircuitBreakerConfig> a supplier of a custom CircuitBreaker configuration circuitBreakerConfigSupplier, Map<String, String> tags added to the CircuitBreaker tags)Creates a CircuitBreaker with a custom CircuitBreaker configuration. |
| public static CircuitBreaker | Returns: a CircuitBreaker with a default CircuitBreaker configuration.the name of the CircuitBreaker name)Creates a CircuitBreaker with a default CircuitBreaker configuration. |
| public void | |
| public void | |
| public void | |
| public void | |
| public void | |
| public void | |
| public void | transitionToDisabledState()
Transitions the state machine to a DISABLED state, stopping state transition, metrics and event publishing. |
| public void | transitionToForcedOpenState()
Transitions the state machine to a FORCED_OPEN state, stopping state transition, metrics and event publishing. |
| public void | |
| public void | transitionToMetricsOnlyState()
Transitions the state machine to METRICS_ONLY state, stopping all state transitions but continues to capture metrics and publish events. |
| public void | |
| public void | transitionToOpenStateFor(Duration
how long should we wait in open state waitDuration)Same as |
| public void | transitionToOpenStateUntil(Instant
how long should we wait in open state waitUntil)Same as |
| public boolean | Returns: true if a permission was acquired and false otherwiseAcquires a permission to execute a call, only if one is available at the time of invocation. |