Skip to content

Commit

Permalink
WIP SmallRye Fault Tolerance: upgrade to 6.8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Ladicek committed Feb 3, 2025
1 parent 711452c commit b165455
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 17 deletions.
2 changes: 1 addition & 1 deletion bom/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<smallrye-metrics.version>4.0.0</smallrye-metrics.version>
<smallrye-open-api.version>4.0.8</smallrye-open-api.version>
<smallrye-graphql.version>2.12.1</smallrye-graphql.version>
<smallrye-fault-tolerance.version>6.7.3</smallrye-fault-tolerance.version>
<smallrye-fault-tolerance.version>6.7.4-SNAPSHOT</smallrye-fault-tolerance.version>
<smallrye-jwt.version>4.6.1</smallrye-jwt.version>
<smallrye-context-propagation.version>2.2.0</smallrye-context-propagation.version>
<smallrye-reactive-streams-operators.version>1.0.13</smallrye-reactive-streams-operators.version>
Expand Down
1 change: 1 addition & 0 deletions docs/src/main/asciidoc/smallrye-fault-tolerance.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,7 @@ The `"<identifier>"` below is:
* `"<classname>/<methodname>"` for per method configuration
* `"<classname>"` for per class configuration
* `global` for global configuration
* It may also be an `@Identifier` value for configuring a declarative use (`@ApplyGuard`) of a programmatically constructed `Guard` or `TypedGuard`.

include::{generated-dir}/config/quarkus-smallrye-fault-tolerance.adoc[opts=optional, leveloffset=+1]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@

import java.lang.annotation.Annotation;

import io.smallrye.config.common.utils.StringUtil;
import io.smallrye.faulttolerance.autoconfig.ConfigConstants;
import org.jboss.jandex.ClassInfo;
import org.jboss.jandex.MethodInfo;

import io.smallrye.faulttolerance.config.ConfigPrefix;
import io.smallrye.faulttolerance.config.NewConfig;

// copy of `io.smallrye.faulttolerance.config.ConfigUtil` and translation from reflection to Jandex
// copy of `io.smallrye.faulttolerance.basicconfig.ConfigUtil` and translation from reflection to Jandex
final class ConfigUtilJandex {
static final String GLOBAL = "global";

static String newKey(Class<? extends Annotation> annotation, String member, MethodInfo declaringMethod) {
return ConfigPrefix.VALUE + "\"" + declaringMethod.declaringClass().name() + "/" + declaringMethod.name()
+ "\"." + NewConfig.get(annotation, member);
return ConfigConstants.PREFIX+ "\"" + declaringMethod.declaringClass().name() + "/" + declaringMethod.name()
+ "\"." + newAnnotationName(annotation) + "." + newMemberName(member);
}

static String oldKey(Class<? extends Annotation> annotation, String member, MethodInfo declaringMethod) {
Expand All @@ -23,21 +22,41 @@ static String oldKey(Class<? extends Annotation> annotation, String member, Meth
}

static String newKey(Class<? extends Annotation> annotation, String member, ClassInfo declaringClass) {
return ConfigPrefix.VALUE + "\"" + declaringClass.name() + "\"."
+ NewConfig.get(annotation, member);
return ConfigConstants.PREFIX + "\"" + declaringClass.name() + "\"."
+ newAnnotationName(annotation) + "." + newMemberName(member);
}

static String oldKey(Class<? extends Annotation> annotation, String member, ClassInfo declaringClass) {
return declaringClass.name() + "/" + annotation.getSimpleName() + "/" + member;
}

static String newKey(Class<? extends Annotation> annotation, String member) {
return ConfigPrefix.VALUE + GLOBAL + "." + NewConfig.get(annotation, member);
return ConfigConstants.PREFIX + GLOBAL + "." + newAnnotationName(annotation) + "." + newMemberName(member);
}

static String oldKey(Class<? extends Annotation> annotation, String member) {
return annotation.getSimpleName() + "/" + member;
}

// no need to have the `isEnabled()` method, that is only needed at runtime

// ---

private static String newAnnotationName(Class<? extends Annotation> annotationDeclaration) {
return StringUtil.skewer(annotationDeclaration.getSimpleName());
}

private static String newMemberName(String annotationMember) {
String result = annotationMember;
switch (result) {
case "jitterDelayUnit":
result = "jitterUnit";
break;
case "durationUnit":
result = "maxDurationUnit";
break;
}
result = StringUtil.skewer(result);
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,17 @@ public FaultToleranceOperation get(Class<?> beanClass, Method method) {

private FaultToleranceOperation createAtRuntime(CacheKey key) {
LOG.debugf("FaultToleranceOperation not found in the cache for %s creating it at runtime", key);
return FaultToleranceOperation.create(FaultToleranceMethods.create(key.beanClass, key.method));
return new FaultToleranceOperation(FaultToleranceMethods.create(key.beanClass, key.method));
}

public Map<CacheKey, FaultToleranceOperation> getOperationCache() {
return operationCache;
}

static class CacheKey {
private Class<?> beanClass;
private Method method;
private int hashCode;
private final Class<?> beanClass;
private final Method method;
private final int hashCode;

public CacheKey(Class<?> beanClass, Method method) {
this.beanClass = beanClass;
Expand All @@ -73,8 +73,8 @@ public boolean equals(Object o) {
return false;
}
CacheKey cacheKey = (CacheKey) o;
return Objects.equals(beanClass, cacheKey.beanClass) &&
Objects.equals(method, cacheKey.method);
return Objects.equals(beanClass, cacheKey.beanClass)
&& Objects.equals(method, cacheKey.method);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public void createFaultToleranceOperation(List<FaultToleranceMethod> ftMethods)
Map<QuarkusFaultToleranceOperationProvider.CacheKey, FaultToleranceOperation> operationCache = new HashMap<>(
ftMethods.size());
for (FaultToleranceMethod ftMethod : ftMethods) {
FaultToleranceOperation operation = FaultToleranceOperation.create(ftMethod);
FaultToleranceOperation operation = new FaultToleranceOperation(ftMethod);
try {
operation.validate();

Expand Down

0 comments on commit b165455

Please sign in to comment.