Interface FaultTolerance.Builder.CircuitBreakerBuilder<T,R>
-
- Enclosing interface:
- FaultTolerance.Builder<T,R>
public static interface FaultTolerance.Builder.CircuitBreakerBuilder<T,R>Configures a circuit breaker.- See Also:
@CircuitBreaker
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description FaultTolerance.Builder.CircuitBreakerBuilder<T,R>delay(long value, ChronoUnit unit)Sets the delay after which an open circuit moves to half-open.FaultTolerance.Builder<T,R>done()Returns the original fault tolerance builder.default FaultTolerance.Builder.CircuitBreakerBuilder<T,R>failOn(Class<? extends Throwable> value)Equivalent tofailOn(Collections.singleton(value)).FaultTolerance.Builder.CircuitBreakerBuilder<T,R>failOn(Collection<Class<? extends Throwable>> value)Sets the set of exception types considered failure.FaultTolerance.Builder.CircuitBreakerBuilder<T,R>failureRatio(double value)Sets the failure ratio that, once reached, will move a closed circuit breaker to open.FaultTolerance.Builder.CircuitBreakerBuilder<T,R>name(String value)Sets a circuit breaker name.FaultTolerance.Builder.CircuitBreakerBuilder<T,R>onFailure(Runnable callback)Sets a callback that will be invoked when this circuit breaker treats a finished invocation as failure.FaultTolerance.Builder.CircuitBreakerBuilder<T,R>onPrevented(Runnable callback)Sets a callback that will be invoked when this circuit breaker prevents an invocation, because it is in the open or half-open state.FaultTolerance.Builder.CircuitBreakerBuilder<T,R>onStateChange(Consumer<CircuitBreakerState> callback)Sets a callback that will be invoked upon each state change of this circuit breaker.FaultTolerance.Builder.CircuitBreakerBuilder<T,R>onSuccess(Runnable callback)Sets a callback that will be invoked when this circuit breaker treats a finished invocation as success.FaultTolerance.Builder.CircuitBreakerBuilder<T,R>requestVolumeThreshold(int value)Sets the size of the circuit breaker's rolling window.default FaultTolerance.Builder.CircuitBreakerBuilder<T,R>skipOn(Class<? extends Throwable> value)Equivalent toskipOn(Collections.singleton(value)).FaultTolerance.Builder.CircuitBreakerBuilder<T,R>skipOn(Collection<Class<? extends Throwable>> value)Sets the set of exception types considered success.FaultTolerance.Builder.CircuitBreakerBuilder<T,R>successThreshold(int value)Sets the number of successful executions that, once reached, will move a half-open circuit breaker to closed.default FaultTolerance.Builder.CircuitBreakerBuilder<T,R>with(Consumer<FaultTolerance.Builder.CircuitBreakerBuilder<T,R>> consumer)
-
-
-
Method Detail
-
failOn
FaultTolerance.Builder.CircuitBreakerBuilder<T,R> failOn(Collection<Class<? extends Throwable>> value)
Sets the set of exception types considered failure. Defaults to all exceptions (Throwable).- Parameters:
value- collection of exception types, must not benull- Returns:
- this circuit breaker builder
- See Also:
@CircuitBreaker.failOn
-
failOn
default FaultTolerance.Builder.CircuitBreakerBuilder<T,R> failOn(Class<? extends Throwable> value)
Equivalent tofailOn(Collections.singleton(value)).- Parameters:
value- an exception class, must not benull- Returns:
- this circuit breaker builder
-
skipOn
FaultTolerance.Builder.CircuitBreakerBuilder<T,R> skipOn(Collection<Class<? extends Throwable>> value)
Sets the set of exception types considered success. Defaults to no exception (empty set).- Parameters:
value- collection of exception types, must not benull- Returns:
- this circuit breaker builder
- See Also:
@CircuitBreaker.skipOn
-
skipOn
default FaultTolerance.Builder.CircuitBreakerBuilder<T,R> skipOn(Class<? extends Throwable> value)
Equivalent toskipOn(Collections.singleton(value)).- Parameters:
value- an exception class, must not benull- Returns:
- this circuit breaker builder
-
delay
FaultTolerance.Builder.CircuitBreakerBuilder<T,R> delay(long value, ChronoUnit unit)
Sets the delay after which an open circuit moves to half-open. Defaults to 5 seconds.- Parameters:
value- the delay length, must be >= 0unit- the delay unit, must not benull- Returns:
- this circuit breaker builder
- See Also:
@CircuitBreaker.delay,@CircuitBreaker.delayUnit
-
requestVolumeThreshold
FaultTolerance.Builder.CircuitBreakerBuilder<T,R> requestVolumeThreshold(int value)
Sets the size of the circuit breaker's rolling window.- Parameters:
value- the size of the circuit breaker's rolling window, must be >= 1- Returns:
- this circuit breaker builder
- See Also:
@CircuitBreaker.requestVolumeThreshold
-
failureRatio
FaultTolerance.Builder.CircuitBreakerBuilder<T,R> failureRatio(double value)
Sets the failure ratio that, once reached, will move a closed circuit breaker to open. Defaults to 0.5.- Parameters:
value- the failure ratio, must be >= 0 and <= 1- Returns:
- this circuit breaker builder
- See Also:
@CircuitBreaker.failureRatio
-
successThreshold
FaultTolerance.Builder.CircuitBreakerBuilder<T,R> successThreshold(int value)
Sets the number of successful executions that, once reached, will move a half-open circuit breaker to closed. Defaults to 1.- Parameters:
value- the number of successful executions, must be >= 1- Returns:
- this circuit breaker builder
- See Also:
@CircuitBreaker.successThreshold
-
name
FaultTolerance.Builder.CircuitBreakerBuilder<T,R> name(String value)
Sets a circuit breaker name. Required to use theCircuitBreakerMaintenancemethods. Defaults to unnamed. It is an error to use the same name for multiple circuit breakers.If a circuit breaker is not given a name, its state will not be affected by
CircuitBreakerMaintenance.resetAll(). This is unlike unnamed circuit breakers declared using@CircuitBreaker, because there's a fixed number of circuit breakers created using the declarative API, but a potentially unbounded number of circuit breakers created using the programmatic API. In other words, automatically remembering all circuit breakers created using the programmatic API would easily lead to a memory leak.- Parameters:
value- the circuit breaker name, must not benull- Returns:
- this circuit breaker builder
- See Also:
@CircuitBreakerName
-
onStateChange
FaultTolerance.Builder.CircuitBreakerBuilder<T,R> onStateChange(Consumer<CircuitBreakerState> callback)
Sets a callback that will be invoked upon each state change of this circuit breaker.The callback must be fast and non-blocking and must not throw an exception.
- Parameters:
callback- the state change callback, must not benull- Returns:
- this circuit breaker builder
-
onSuccess
FaultTolerance.Builder.CircuitBreakerBuilder<T,R> onSuccess(Runnable callback)
Sets a callback that will be invoked when this circuit breaker treats a finished invocation as success.The callback must be fast and non-blocking and must not throw an exception.
- Parameters:
callback- the success callback, must not benull- Returns:
- this circuit breaker builder
-
onFailure
FaultTolerance.Builder.CircuitBreakerBuilder<T,R> onFailure(Runnable callback)
Sets a callback that will be invoked when this circuit breaker treats a finished invocation as failure.The callback must be fast and non-blocking and must not throw an exception.
- Parameters:
callback- the failure callback, must not benull- Returns:
- this circuit breaker builder
-
onPrevented
FaultTolerance.Builder.CircuitBreakerBuilder<T,R> onPrevented(Runnable callback)
Sets a callback that will be invoked when this circuit breaker prevents an invocation, because it is in the open or half-open state.The callback must be fast and non-blocking and must not throw an exception.
- Parameters:
callback- the prevented callback, must not benull- Returns:
- this circuit breaker builder
-
done
FaultTolerance.Builder<T,R> done()
Returns the original fault tolerance builder.- Returns:
- the original fault tolerance builder
-
with
default FaultTolerance.Builder.CircuitBreakerBuilder<T,R> with(Consumer<FaultTolerance.Builder.CircuitBreakerBuilder<T,R>> consumer)
-
-