io.helidon.microprofile.faulttolerance.CircuitBreakerAntn Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of helidon-microprofile-fault-tolerance Show documentation
Show all versions of helidon-microprofile-fault-tolerance Show documentation
Microprofile fault tolerance implementation
The newest version!
/*
* Copyright (c) 2018, 2022 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.helidon.microprofile.faulttolerance;
import java.time.temporal.ChronoUnit;
import jakarta.enterprise.inject.spi.AnnotatedMethod;
import org.eclipse.microprofile.faulttolerance.CircuitBreaker;
import org.eclipse.microprofile.faulttolerance.exceptions.FaultToleranceDefinitionException;
class CircuitBreakerAntn extends MethodAntn implements CircuitBreaker {
/**
* Constructor.
*
* @param annotatedMethod The annotated method.
*/
CircuitBreakerAntn(AnnotatedMethod> annotatedMethod) {
super(annotatedMethod);
}
@Override
public void validate() {
if (delay() < 0) {
throw new FaultToleranceDefinitionException("Invalid @CircuitBreaker annotation, "
+ "delay must be >= 0");
}
if (requestVolumeThreshold() < 1) {
throw new FaultToleranceDefinitionException("Invalid @CircuitBreaker annotation, "
+ "requestVolumeThreshold must be >= 1");
}
double failureRatio = failureRatio();
if (failureRatio < 0 || failureRatio > 1) {
throw new FaultToleranceDefinitionException("Invalid @CircuitBreaker annotation, "
+ "failureRatio must be >= 0 and <= 1");
}
if (successThreshold() < 1) {
throw new FaultToleranceDefinitionException("Invalid @CircuitBreaker annotation, "
+ "successThreshold must be >= 1");
}
}
@Override
public long delay() {
LookupResult lookupResult = lookupAnnotation(CircuitBreaker.class);
final String override = getParamOverride("delay", lookupResult.getType());
return override != null ? Long.parseLong(override) : lookupResult.getAnnotation().delay();
}
@Override
public ChronoUnit delayUnit() {
LookupResult lookupResult = lookupAnnotation(CircuitBreaker.class);
final String override = getParamOverride("delayUnit", lookupResult.getType());
return override != null ? ChronoUnit.valueOf(override) : lookupResult.getAnnotation().delayUnit();
}
@Override
public int requestVolumeThreshold() {
LookupResult lookupResult = lookupAnnotation(CircuitBreaker.class);
final String override = getParamOverride("requestVolumeThreshold", lookupResult.getType());
return override != null ? Integer.parseInt(override) : lookupResult.getAnnotation().requestVolumeThreshold();
}
@Override
public double failureRatio() {
LookupResult lookupResult = lookupAnnotation(CircuitBreaker.class);
final String override = getParamOverride("failureRatio", lookupResult.getType());
return override != null ? Double.parseDouble(override) : lookupResult.getAnnotation().failureRatio();
}
@Override
public int successThreshold() {
LookupResult lookupResult = lookupAnnotation(CircuitBreaker.class);
final String override = getParamOverride("successThreshold", lookupResult.getType());
return override != null ? Integer.parseInt(override) : lookupResult.getAnnotation().successThreshold();
}
@Override
public Class extends Throwable>[] failOn() {
LookupResult lookupResult = lookupAnnotation(CircuitBreaker.class);
final String override = getParamOverride("failOn", lookupResult.getType());
return override != null ? parseThrowableArray(override) : lookupResult.getAnnotation().failOn();
}
@Override
public Class extends Throwable>[] skipOn() {
LookupResult lookupResult = lookupAnnotation(CircuitBreaker.class);
final String override = getParamOverride("skipOn", lookupResult.getType());
return override != null ? parseThrowableArray(override) : lookupResult.getAnnotation().skipOn();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy