Skip to content

Commit

Permalink
PAYARA-3468 fixed conversion of config overrides from String
Browse files Browse the repository at this point in the history
  • Loading branch information
jbee committed Mar 28, 2019
1 parent aa4302d commit 143e9f6
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -241,21 +241,21 @@ private Object retry(InvocationContext invocationContext) throws Exception {
.orElse(retry.delay());
// Look for a String and cast to ChronoUnit - Use the Common Sense Convertor
ChronoUnit delayUnit = FaultToleranceCdiUtils.getOverrideValue(
config, Retry.class, "delayUnit", invocationContext, ChronoUnit.class)
config, Retry.class, "delayUnit", invocationContext, String.class).map(ChronoUnit::valueOf)
.orElse(retry.delayUnit());
long maxDuration = FaultToleranceCdiUtils.getOverrideValue(
config, Retry.class, "maxDuration", invocationContext, Long.class)
.orElse(retry.maxDuration());
// Look for a String and cast to ChronoUnit - Use the Common Sense Convertor
ChronoUnit durationUnit = FaultToleranceCdiUtils.getOverrideValue(
config, Retry.class, "durationUnit", invocationContext, ChronoUnit.class)
config, Retry.class, "durationUnit", invocationContext, String.class).map(ChronoUnit::valueOf)
.orElse(retry.durationUnit());
long jitter = FaultToleranceCdiUtils.getOverrideValue(
config, Retry.class, "jitter", invocationContext, Long.class)
.orElse(retry.jitter());
// Look for a String and cast to ChronoUnit - Use the Common Sense Convertor
ChronoUnit jitterDelayUnit = FaultToleranceCdiUtils.getOverrideValue(
config, Retry.class, "jitterDelayUnit", invocationContext, ChronoUnit.class)
config, Retry.class, "jitterDelayUnit", invocationContext, String.class).map(ChronoUnit::valueOf)
.orElse(retry.jitterDelayUnit());

long delayMillis = Duration.of(delay, delayUnit).toMillis();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ private Object timeout(InvocationContext invocationContext) throws Exception {
.orElse(timeout.value());
// Look for a String and cast to ChronoUnit - Use the Common Sense Convertor
ChronoUnit unit = FaultToleranceCdiUtils.getOverrideValue(
config, Timeout.class, "unit", invocationContext, ChronoUnit.class)
config, Timeout.class, "unit", invocationContext, String.class).map(ChronoUnit::valueOf)
.orElse(timeout.unit());

Future<?> timeoutFuture = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import static fish.payara.microprofile.faulttolerance.FaultToleranceService.FALLBACK_HANDLER_METHOD_NAME;
import fish.payara.microprofile.faulttolerance.cdi.FaultToleranceCdiUtils;
import java.lang.reflect.Method;
import java.util.Optional;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.interceptor.InvocationContext;
Expand Down Expand Up @@ -72,11 +73,12 @@ public class FallbackPolicy {
@SuppressWarnings("unchecked")
public FallbackPolicy(Fallback fallback, Config config, InvocationContext invocationContext)
throws ClassNotFoundException {
fallbackClass = (Class<? extends FallbackHandler<?>>) Thread.currentThread().getContextClassLoader().loadClass(
FaultToleranceCdiUtils.getOverrideValue(config, Fallback.class, "value",
invocationContext, Class.class)
.orElse(fallback.value()).getName());

Optional<String> className = FaultToleranceCdiUtils.getOverrideValue(config, Fallback.class, "value",
invocationContext, String.class);
fallbackClass = className.isPresent()
? (Class<? extends FallbackHandler<?>>) Thread.currentThread().getContextClassLoader()
.loadClass(className.get())
: fallback.value();
fallbackMethod = FaultToleranceCdiUtils.getOverrideValue(config, Fallback.class,
"fallbackMethod", invocationContext, String.class)
.orElse(fallback.fallbackMethod());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
package fish.payara.microprofile.faulttolerance.validators;

import static fish.payara.microprofile.faulttolerance.FaultToleranceService.FALLBACK_HANDLER_METHOD_NAME;

import java.util.Optional;

import fish.payara.microprofile.faulttolerance.cdi.FaultToleranceCdiUtils;
import javax.enterprise.inject.spi.AnnotatedMethod;
import org.eclipse.microprofile.config.Config;
Expand Down Expand Up @@ -71,13 +74,15 @@ public static void validateAnnotation(Fallback fallback, AnnotatedMethod<?> anno
.orElse(fallback.fallbackMethod());

// Get the fallbackClass, and check that it can be found
@SuppressWarnings("unchecked")
Class<? extends FallbackHandler<?>> fallbackClass = (Class<? extends FallbackHandler<?>>) Thread.currentThread()
.getContextClassLoader().loadClass(FaultToleranceCdiUtils
Optional<String> fallbackClassName = FaultToleranceCdiUtils
.getOverrideValue(config, Fallback.class, "value", annotatedMethod.getJavaMember().getName(),
annotatedMethod.getJavaMember().getDeclaringClass().getCanonicalName(), Class.class)
.orElse(fallback.value()).getName());

annotatedMethod.getJavaMember().getDeclaringClass().getCanonicalName(), String.class);
@SuppressWarnings("unchecked")
Class<? extends FallbackHandler<?>> fallbackClass = fallbackClassName.isPresent()
? (Class<? extends FallbackHandler<?>>) Thread.currentThread().getContextClassLoader()
.loadClass(fallbackClassName.get())
: fallback.value();

// Validate the annotated method
if (fallbackMethod != null && !fallbackMethod.isEmpty()) {
if (fallbackClass != null && fallbackClass != Fallback.DEFAULT.class) {
Expand Down

0 comments on commit 143e9f6

Please sign in to comment.