io.smallrye.faulttolerance.config.CircuitBreakerConfigImpl Maven / Gradle / Ivy
package io.smallrye.faulttolerance.config;
import io.smallrye.faulttolerance.autoconfig.Config;
import io.smallrye.faulttolerance.autoconfig.FaultToleranceMethod;
import io.smallrye.faulttolerance.autoconfig.MethodDescriptor;
import java.lang.Class;
import java.lang.Double;
import java.lang.Integer;
import java.lang.Long;
import java.lang.Override;
import java.lang.Throwable;
import java.lang.annotation.Annotation;
import java.time.temporal.ChronoUnit;
import org.eclipse.microprofile.config.ConfigProvider;
import org.eclipse.microprofile.faulttolerance.CircuitBreaker;
/**
* Automatically generated from the {@link CircuitBreakerConfig} config interface, do not modify.
*/
public final class CircuitBreakerConfigImpl implements CircuitBreakerConfig {
private final Class> beanClass;
private final MethodDescriptor method;
/**
* Backing annotation instance. Used when runtime configuration doesn't override it.
*/
private final CircuitBreaker instance;
/**
* {@code true} if annotation was placed on a method; {@code false} if annotation was placed on a class.
*/
private final boolean onMethod;
/**
* Cached value of the {@code CircuitBreaker.failOn} annotation member; {@code null} if not looked up yet.
*/
private Class extends Throwable>[] _failOn;
/**
* Cached value of the {@code CircuitBreaker.skipOn} annotation member; {@code null} if not looked up yet.
*/
private Class extends Throwable>[] _skipOn;
/**
* Cached value of the {@code CircuitBreaker.delay} annotation member; {@code null} if not looked up yet.
*/
private Long _delay;
/**
* Cached value of the {@code CircuitBreaker.delayUnit} annotation member; {@code null} if not looked up yet.
*/
private ChronoUnit _delayUnit;
/**
* Cached value of the {@code CircuitBreaker.requestVolumeThreshold} annotation member; {@code null} if not looked up yet.
*/
private Integer _requestVolumeThreshold;
/**
* Cached value of the {@code CircuitBreaker.failureRatio} annotation member; {@code null} if not looked up yet.
*/
private Double _failureRatio;
/**
* Cached value of the {@code CircuitBreaker.successThreshold} annotation member; {@code null} if not looked up yet.
*/
private Integer _successThreshold;
private CircuitBreakerConfigImpl(FaultToleranceMethod method) {
this.beanClass = method.beanClass;
this.method = method.method;
this.instance = method.circuitBreaker;
this.onMethod = method.annotationsPresentDirectly.contains(CircuitBreaker.class);
}
public static CircuitBreakerConfigImpl create(FaultToleranceMethod method) {
if (method.circuitBreaker == null) {
return null;
}
if (!Config.isEnabled(CircuitBreaker.class, method.method)) {
return null;
}
return new CircuitBreakerConfigImpl(method);
}
@Override
public Class> beanClass() {
return beanClass;
}
@Override
public MethodDescriptor method() {
return method;
}
@Override
public Class extends Annotation> annotationType() {
return CircuitBreaker.class;
}
@Override
public boolean isOnMethod() {
return onMethod;
}
@Override
public Class extends Throwable>[] failOn() {
if (_failOn == null) {
org.eclipse.microprofile.config.Config config = ConfigProvider.getConfig();
if (onMethod) {
// ///
String key = method.declaringClass.getName() + "/" + method.name + "/CircuitBreaker/failOn";
_failOn = config.getOptionalValue(key, Class[].class).orElse(null);
} else {
// //
String key = method.declaringClass.getName() + "/CircuitBreaker/failOn";
_failOn = config.getOptionalValue(key, Class[].class).orElse(null);
}
if (_failOn == null) {
// /
_failOn = config.getOptionalValue("CircuitBreaker/failOn", Class[].class).orElse(null);
}
if (_failOn == null) {
// annotation value
_failOn = instance.failOn();
}
}
return _failOn;
}
@Override
public Class extends Throwable>[] skipOn() {
if (_skipOn == null) {
org.eclipse.microprofile.config.Config config = ConfigProvider.getConfig();
if (onMethod) {
// ///
String key = method.declaringClass.getName() + "/" + method.name + "/CircuitBreaker/skipOn";
_skipOn = config.getOptionalValue(key, Class[].class).orElse(null);
} else {
// //
String key = method.declaringClass.getName() + "/CircuitBreaker/skipOn";
_skipOn = config.getOptionalValue(key, Class[].class).orElse(null);
}
if (_skipOn == null) {
// /
_skipOn = config.getOptionalValue("CircuitBreaker/skipOn", Class[].class).orElse(null);
}
if (_skipOn == null) {
// annotation value
_skipOn = instance.skipOn();
}
}
return _skipOn;
}
@Override
public long delay() {
if (_delay == null) {
org.eclipse.microprofile.config.Config config = ConfigProvider.getConfig();
if (onMethod) {
// ///
String key = method.declaringClass.getName() + "/" + method.name + "/CircuitBreaker/delay";
_delay = config.getOptionalValue(key, long.class).orElse(null);
} else {
// //
String key = method.declaringClass.getName() + "/CircuitBreaker/delay";
_delay = config.getOptionalValue(key, long.class).orElse(null);
}
if (_delay == null) {
// /
_delay = config.getOptionalValue("CircuitBreaker/delay", long.class).orElse(null);
}
if (_delay == null) {
// annotation value
_delay = instance.delay();
}
}
return _delay;
}
@Override
public ChronoUnit delayUnit() {
if (_delayUnit == null) {
org.eclipse.microprofile.config.Config config = ConfigProvider.getConfig();
if (onMethod) {
// ///
String key = method.declaringClass.getName() + "/" + method.name + "/CircuitBreaker/delayUnit";
_delayUnit = config.getOptionalValue(key, ChronoUnit.class).orElse(null);
} else {
// //
String key = method.declaringClass.getName() + "/CircuitBreaker/delayUnit";
_delayUnit = config.getOptionalValue(key, ChronoUnit.class).orElse(null);
}
if (_delayUnit == null) {
// /
_delayUnit = config.getOptionalValue("CircuitBreaker/delayUnit", ChronoUnit.class).orElse(null);
}
if (_delayUnit == null) {
// annotation value
_delayUnit = instance.delayUnit();
}
}
return _delayUnit;
}
@Override
public int requestVolumeThreshold() {
if (_requestVolumeThreshold == null) {
org.eclipse.microprofile.config.Config config = ConfigProvider.getConfig();
if (onMethod) {
// ///
String key = method.declaringClass.getName() + "/" + method.name + "/CircuitBreaker/requestVolumeThreshold";
_requestVolumeThreshold = config.getOptionalValue(key, int.class).orElse(null);
} else {
// //
String key = method.declaringClass.getName() + "/CircuitBreaker/requestVolumeThreshold";
_requestVolumeThreshold = config.getOptionalValue(key, int.class).orElse(null);
}
if (_requestVolumeThreshold == null) {
// /
_requestVolumeThreshold = config.getOptionalValue("CircuitBreaker/requestVolumeThreshold", int.class).orElse(null);
}
if (_requestVolumeThreshold == null) {
// annotation value
_requestVolumeThreshold = instance.requestVolumeThreshold();
}
}
return _requestVolumeThreshold;
}
@Override
public double failureRatio() {
if (_failureRatio == null) {
org.eclipse.microprofile.config.Config config = ConfigProvider.getConfig();
if (onMethod) {
// ///
String key = method.declaringClass.getName() + "/" + method.name + "/CircuitBreaker/failureRatio";
_failureRatio = config.getOptionalValue(key, double.class).orElse(null);
} else {
// //
String key = method.declaringClass.getName() + "/CircuitBreaker/failureRatio";
_failureRatio = config.getOptionalValue(key, double.class).orElse(null);
}
if (_failureRatio == null) {
// /
_failureRatio = config.getOptionalValue("CircuitBreaker/failureRatio", double.class).orElse(null);
}
if (_failureRatio == null) {
// annotation value
_failureRatio = instance.failureRatio();
}
}
return _failureRatio;
}
@Override
public int successThreshold() {
if (_successThreshold == null) {
org.eclipse.microprofile.config.Config config = ConfigProvider.getConfig();
if (onMethod) {
// ///
String key = method.declaringClass.getName() + "/" + method.name + "/CircuitBreaker/successThreshold";
_successThreshold = config.getOptionalValue(key, int.class).orElse(null);
} else {
// //
String key = method.declaringClass.getName() + "/CircuitBreaker/successThreshold";
_successThreshold = config.getOptionalValue(key, int.class).orElse(null);
}
if (_successThreshold == null) {
// /
_successThreshold = config.getOptionalValue("CircuitBreaker/successThreshold", int.class).orElse(null);
}
if (_successThreshold == null) {
// annotation value
_successThreshold = instance.successThreshold();
}
}
return _successThreshold;
}
@Override
public void materialize() {
failOn();
skipOn();
delay();
delayUnit();
requestVolumeThreshold();
failureRatio();
successThreshold();
}
}