- java.lang.Object
-
- io.helidon.faulttolerance.CircuitBreaker.Builder
-
- All Implemented Interfaces:
Builder<CircuitBreaker>
,Supplier<CircuitBreaker>
- Enclosing interface:
- CircuitBreaker
public static class CircuitBreaker.Builder extends Object implements Builder<CircuitBreaker>
Fluent API builder forCircuitBreaker
.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CircuitBreaker.Builder
addApplyOn(Class<? extends Throwable> clazz)
Add a throwable to be considered a failure.CircuitBreaker.Builder
addSkipOn(Class<? extends Throwable> clazz)
This throwable will not be considered failure.CircuitBreaker.Builder
applyOn(Class<? extends Throwable>... classes)
These throwables will be considered failures, and all other will not.CircuitBreaker
build()
Build the instance from this builder.CircuitBreaker.Builder
cancelSource(boolean cancelSource)
Policy to cancel any source stage if the value return byFtHandler.invoke(java.util.function.Supplier<? extends java.util.concurrent.CompletionStage<T>>)
is cancelled.CircuitBreaker.Builder
config(Config config)
Load all properties for this circuit breaker from configuration.CircuitBreaker.Builder
delay(Duration delay)
How long to wait before transitioning from open to half-open state.CircuitBreaker.Builder
errorRatio(int ratio)
How many failures out of 100 will trigger the circuit to open.CircuitBreaker.Builder
executor(ScheduledExecutorService scheduledExecutor)
Executor service to schedule future tasks.CircuitBreaker.Builder
name(String name)
A name assigned for debugging, error reporting or configuration purposes.CircuitBreaker.Builder
skipOn(Class<? extends Throwable>... classes)
These throwables will not be considered failures, all other will.CircuitBreaker.Builder
successThreshold(int successThreshold)
How many successful calls will close a half-open circuit.CircuitBreaker.Builder
volume(int volume)
Rolling window size used to calculate ratio of failed requests.
-
-
-
Method Detail
-
build
public CircuitBreaker build()
Description copied from interface:Builder
Build the instance from this builder.- Specified by:
build
in interfaceBuilder<CircuitBreaker>
- Returns:
- instance of the built type
-
delay
public CircuitBreaker.Builder delay(Duration delay)
How long to wait before transitioning from open to half-open state.- Parameters:
delay
- to wait- Returns:
- updated builder instance
-
errorRatio
public CircuitBreaker.Builder errorRatio(int ratio)
How many failures out of 100 will trigger the circuit to open. This is adapted to thevolume(int)
used to handle the window of requests.If errorRatio is 40, and volume is 10, 4 failed requests will open the circuit.
- Parameters:
ratio
- percent of failure that trigger the circuit to open- Returns:
- updated builder instance
- See Also:
volume(int)
-
successThreshold
public CircuitBreaker.Builder successThreshold(int successThreshold)
How many successful calls will close a half-open circuit. Nevertheless the first failed call will open the circuit again.- Parameters:
successThreshold
- number of calls- Returns:
- updated builder instance
-
volume
public CircuitBreaker.Builder volume(int volume)
Rolling window size used to calculate ratio of failed requests.- Parameters:
volume
- how big a window is used to calculate error errorRatio- Returns:
- updated builder instance
- See Also:
errorRatio(int)
-
applyOn
@SafeVarargs public final CircuitBreaker.Builder applyOn(Class<? extends Throwable>... classes)
These throwables will be considered failures, and all other will not.Cannot be combined with
skipOn
.- Parameters:
classes
- to consider failures to calculate failure ratio- Returns:
- updated builder instance
-
addApplyOn
public CircuitBreaker.Builder addApplyOn(Class<? extends Throwable> clazz)
Add a throwable to be considered a failure.- Parameters:
clazz
- to consider failure to calculate failure ratio- Returns:
- updated builder instance
- See Also:
applyOn
-
skipOn
@SafeVarargs public final CircuitBreaker.Builder skipOn(Class<? extends Throwable>... classes)
These throwables will not be considered failures, all other will.Cannot be combined with
applyOn
.- Parameters:
classes
- to consider successful- Returns:
- updated builder instance
-
addSkipOn
public CircuitBreaker.Builder addSkipOn(Class<? extends Throwable> clazz)
This throwable will not be considered failure.- Parameters:
clazz
- to consider successful- Returns:
- updated builder instance
-
executor
public CircuitBreaker.Builder executor(ScheduledExecutorService scheduledExecutor)
Executor service to schedule future tasks. By default uses an executor configured onFaultTolerance.scheduledExecutor(java.util.function.Supplier)
.- Parameters:
scheduledExecutor
- executor to use- Returns:
- updated builder instance
-
name
public CircuitBreaker.Builder name(String name)
A name assigned for debugging, error reporting or configuration purposes.- Parameters:
name
- the name- Returns:
- updated builder instance
-
cancelSource
public CircuitBreaker.Builder cancelSource(boolean cancelSource)
Policy to cancel any source stage if the value return byFtHandler.invoke(java.util.function.Supplier<? extends java.util.concurrent.CompletionStage<T>>)
is cancelled. Default istrue
; mostly used by FT MP to change default.- Parameters:
cancelSource
- cancel source policy- Returns:
- updated builder instance
-
config
public CircuitBreaker.Builder config(Config config)
Load all properties for this circuit breaker from configuration.
Configuration key default value description delay 5 seconds Delay to transition from open to half-open name CircuitBreaker-N Name used for debugging error-ratio 60 Failure percentage that will open the breaker success-threshold 1 Number of successful calls will close a half-open breaker volume 10 Rolling window size cancel-source true Cancel task source if task is cancelled - Parameters:
config
- the config node to use- Returns:
- updated builder instance
-
-