All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.smallrye.faulttolerance.config.ExponentialBackoffConfigImpl Maven / Gradle / Ivy

There is a newer version: 6.4.0
Show newest version
package io.smallrye.faulttolerance.config;

import io.smallrye.faulttolerance.api.ExponentialBackoff;
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.Integer;
import java.lang.Long;
import java.lang.Override;
import java.lang.annotation.Annotation;
import java.time.temporal.ChronoUnit;
import org.eclipse.microprofile.config.ConfigProvider;

/**
 * Automatically generated from the {@link ExponentialBackoffConfig} config interface, do not modify.
 */
public final class ExponentialBackoffConfigImpl implements ExponentialBackoffConfig {
    private final Class beanClass;

    private final MethodDescriptor method;

    /**
     * Backing annotation instance. Used when runtime configuration doesn't override it.
     */
    private final ExponentialBackoff 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 ExponentialBackoff.factor} annotation member; {@code null} if not looked up yet.
     */
    private Integer _factor;

    /**
     * Cached value of the {@code ExponentialBackoff.maxDelay} annotation member; {@code null} if not looked up yet.
     */
    private Long _maxDelay;

    /**
     * Cached value of the {@code ExponentialBackoff.maxDelayUnit} annotation member; {@code null} if not looked up yet.
     */
    private ChronoUnit _maxDelayUnit;

    private ExponentialBackoffConfigImpl(FaultToleranceMethod method) {
        this.beanClass = method.beanClass;
        this.method = method.method;
        this.instance = method.exponentialBackoff;
        this.onMethod = method.annotationsPresentDirectly.contains(ExponentialBackoff.class);
    }

    public static ExponentialBackoffConfigImpl create(FaultToleranceMethod method) {
        if (method.exponentialBackoff == null) {
            return null;
        }
        if (!Config.isEnabled(ExponentialBackoff.class, method.method)) {
            return null;
        }
        return new ExponentialBackoffConfigImpl(method);
    }

    @Override
    public Class beanClass() {
        return beanClass;
    }

    @Override
    public MethodDescriptor method() {
        return method;
    }

    @Override
    public Class annotationType() {
        return ExponentialBackoff.class;
    }

    @Override
    public boolean isOnMethod() {
        return onMethod;
    }

    @Override
    public int factor() {
        if (_factor == null) {
            org.eclipse.microprofile.config.Config config = ConfigProvider.getConfig();
            if (onMethod) {
                // ///
                String key = method.declaringClass.getName() + "/" + method.name + "/ExponentialBackoff/factor";
                _factor = config.getOptionalValue(key, int.class).orElse(null);
            } else {
                // //
                String key = method.declaringClass.getName() + "/ExponentialBackoff/factor";
                _factor = config.getOptionalValue(key, int.class).orElse(null);
            }
            if (_factor == null) {
                // /
                _factor = config.getOptionalValue("ExponentialBackoff/factor", int.class).orElse(null);
            }
            if (_factor == null) {
                // annotation value
                _factor = instance.factor();
            }
        }
        return _factor;
    }

    @Override
    public long maxDelay() {
        if (_maxDelay == null) {
            org.eclipse.microprofile.config.Config config = ConfigProvider.getConfig();
            if (onMethod) {
                // ///
                String key = method.declaringClass.getName() + "/" + method.name + "/ExponentialBackoff/maxDelay";
                _maxDelay = config.getOptionalValue(key, long.class).orElse(null);
            } else {
                // //
                String key = method.declaringClass.getName() + "/ExponentialBackoff/maxDelay";
                _maxDelay = config.getOptionalValue(key, long.class).orElse(null);
            }
            if (_maxDelay == null) {
                // /
                _maxDelay = config.getOptionalValue("ExponentialBackoff/maxDelay", long.class).orElse(null);
            }
            if (_maxDelay == null) {
                // annotation value
                _maxDelay = instance.maxDelay();
            }
        }
        return _maxDelay;
    }

    @Override
    public ChronoUnit maxDelayUnit() {
        if (_maxDelayUnit == null) {
            org.eclipse.microprofile.config.Config config = ConfigProvider.getConfig();
            if (onMethod) {
                // ///
                String key = method.declaringClass.getName() + "/" + method.name + "/ExponentialBackoff/maxDelayUnit";
                _maxDelayUnit = config.getOptionalValue(key, ChronoUnit.class).orElse(null);
            } else {
                // //
                String key = method.declaringClass.getName() + "/ExponentialBackoff/maxDelayUnit";
                _maxDelayUnit = config.getOptionalValue(key, ChronoUnit.class).orElse(null);
            }
            if (_maxDelayUnit == null) {
                // /
                _maxDelayUnit = config.getOptionalValue("ExponentialBackoff/maxDelayUnit", ChronoUnit.class).orElse(null);
            }
            if (_maxDelayUnit == null) {
                // annotation value
                _maxDelayUnit = instance.maxDelayUnit();
            }
        }
        return _maxDelayUnit;
    }

    @Override
    public void materialize() {
        factor();
        maxDelay();
        maxDelayUnit();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy