Class CircuitBreakerBuilder<T extends io.dropwizard.core.Configuration>
java.lang.Object
org.sdase.commons.server.circuitbreaker.builder.CircuitBreakerBuilder<T>
- All Implemented Interfaces:
CircuitBreakerConfigurationBuilder<T>
,CircuitBreakerExceptionBuilder<T>
,CircuitBreakerFinalBuilder
public class CircuitBreakerBuilder<T extends io.dropwizard.core.Configuration>
extends Object
implements CircuitBreakerConfigurationBuilder<T>, CircuitBreakerExceptionBuilder<T>, CircuitBreakerFinalBuilder
-
Constructor Summary
ConstructorDescriptionCircuitBreakerBuilder
(String name, io.github.resilience4j.circuitbreaker.CircuitBreakerRegistry registry, T configuration) -
Method Summary
Modifier and TypeMethodDescriptionio.github.resilience4j.circuitbreaker.CircuitBreaker
build()
Create a new circuit breaker instance.final CircuitBreakerExceptionBuilder<T>
ignoreExceptions
(Class<? extends Throwable>... errorClasses) Configures a list of error classes that are ignored as a failure and thus do not increase the failure rate.final CircuitBreakerExceptionBuilder<T>
recordExceptions
(Class<? extends Throwable>... errorClasses) Configures a list of error classes that are recorded as a failure and thus increase the failure rate.Set a provider for a custom configuration for the circuit breaker.Set a custom configuration for the circuit breaker.Use the default configuration of the bundle for the circuit breaker.<U> U
wrap
(U target) Wrap target with a circuit breaker
-
Constructor Details
-
CircuitBreakerBuilder
-
-
Method Details
-
withCustomConfig
Description copied from interface:CircuitBreakerConfigurationBuilder
Set a custom configuration for the circuit breaker.- Specified by:
withCustomConfig
in interfaceCircuitBreakerConfigurationBuilder<T extends io.dropwizard.core.Configuration>
- Parameters:
config
- The config to apply.- Returns:
- the same builder instance
-
withConfigProvider
public CircuitBreakerExceptionBuilder<T> withConfigProvider(CircuitBreakerConfigurationProvider<T> provider) Description copied from interface:CircuitBreakerConfigurationBuilder
Set a provider for a custom configuration for the circuit breaker.- Specified by:
withConfigProvider
in interfaceCircuitBreakerConfigurationBuilder<T extends io.dropwizard.core.Configuration>
- Parameters:
provider
- The provider to load the config from the Dropwizard config.- Returns:
- the same builder instance
-
withDefaultConfig
Description copied from interface:CircuitBreakerConfigurationBuilder
Use the default configuration of the bundle for the circuit breaker.- Specified by:
withDefaultConfig
in interfaceCircuitBreakerConfigurationBuilder<T extends io.dropwizard.core.Configuration>
- Returns:
- the same builder instance
-
recordExceptions
@SafeVarargs public final CircuitBreakerExceptionBuilder<T> recordExceptions(Class<? extends Throwable>... errorClasses) Description copied from interface:CircuitBreakerExceptionBuilder
Configures a list of error classes that are recorded as a failure and thus increase the failure rate. Any exception matching or inheriting from one of the list should count as a failure, unless ignored- Specified by:
recordExceptions
in interfaceCircuitBreakerExceptionBuilder<T extends io.dropwizard.core.Configuration>
- Parameters:
errorClasses
- the error classes that are recorded- Returns:
- the same builder instance
-
ignoreExceptions
@SafeVarargs public final CircuitBreakerExceptionBuilder<T> ignoreExceptions(Class<? extends Throwable>... errorClasses) Description copied from interface:CircuitBreakerExceptionBuilder
Configures a list of error classes that are ignored as a failure and thus do not increase the failure rate. Any exception matching or inheriting from one of the list will not count as a failure, even if marked via record.- Specified by:
ignoreExceptions
in interfaceCircuitBreakerExceptionBuilder<T extends io.dropwizard.core.Configuration>
- Parameters:
errorClasses
- the error classes that are ignored- Returns:
- the same builder instance
-
build
public io.github.resilience4j.circuitbreaker.CircuitBreaker build()Description copied from interface:CircuitBreakerFinalBuilder
Create a new circuit breaker instance.- Specified by:
build
in interfaceCircuitBreakerFinalBuilder
- Returns:
- A new
CircuitBreaker
-
wrap
public <U> U wrap(U target) Description copied from interface:CircuitBreakerFinalBuilder
Wrap target with a circuit breaker- Specified by:
wrap
in interfaceCircuitBreakerFinalBuilder
- Type Parameters:
U
- The type of the target- Parameters:
target
- The target to wrap. Final classes have to implement an interface.- Returns:
- A proxy object that passes all calls to target, but wraps them in a circuit breaker.
-