This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch mp-health in repository https://gitbox.apache.org/repos/asf/camel.git
commit 3c26a135f54fa00929c8746434418449ba0d3432 Author: Claus Ibsen <[email protected]> AuthorDate: Thu Feb 10 16:16:34 2022 +0100 Upgrade microprofile smallrye. WIP --- .../faulttolerance/FaultToleranceProcessor.java | 8 ++-- .../health/CamelMicroProfileHealthHelper.java | 53 +++------------------- parent/pom.xml | 4 +- 3 files changed, 12 insertions(+), 53 deletions(-) diff --git a/components/camel-microprofile/camel-microprofile-fault-tolerance/src/main/java/org/apache/camel/component/microprofile/faulttolerance/FaultToleranceProcessor.java b/components/camel-microprofile/camel-microprofile-fault-tolerance/src/main/java/org/apache/camel/component/microprofile/faulttolerance/FaultToleranceProcessor.java index b29ead5..5e6c3a2 100644 --- a/components/camel-microprofile/camel-microprofile-fault-tolerance/src/main/java/org/apache/camel/component/microprofile/faulttolerance/FaultToleranceProcessor.java +++ b/components/camel-microprofile/camel-microprofile-fault-tolerance/src/main/java/org/apache/camel/component/microprofile/faulttolerance/FaultToleranceProcessor.java @@ -31,7 +31,7 @@ import io.smallrye.faulttolerance.core.stopwatch.SystemStopwatch; import io.smallrye.faulttolerance.core.timeout.ScheduledExecutorTimeoutWatcher; import io.smallrye.faulttolerance.core.timeout.Timeout; import io.smallrye.faulttolerance.core.timeout.TimeoutWatcher; -import io.smallrye.faulttolerance.core.util.SetOfThrowables; +import io.smallrye.faulttolerance.core.util.ExceptionDecision; import org.apache.camel.AsyncCallback; import org.apache.camel.CamelContext; import org.apache.camel.CamelContextAware; @@ -254,7 +254,7 @@ public class FaultToleranceProcessor extends AsyncProcessorSupport target = new Fallback(target, "fallback", fallbackContext -> { exchange.setException(fallbackContext.failure); return fFallbackTask.call(); - }, SetOfThrowables.ALL, SetOfThrowables.EMPTY); + }, ExceptionDecision.ALWAYS_FAILURE); } try { @@ -331,8 +331,8 @@ public class FaultToleranceProcessor extends AsyncProcessorSupport ObjectHelper.notNull(camelContext, "CamelContext", this); if (circuitBreaker == null) { circuitBreaker = new CircuitBreaker( - invocation(), id, SetOfThrowables.ALL, - SetOfThrowables.EMPTY, config.getDelay(), config.getRequestVolumeThreshold(), config.getFailureRatio(), + invocation(), id, ExceptionDecision.ALWAYS_FAILURE, config.getDelay(), config.getRequestVolumeThreshold(), + config.getFailureRatio(), config.getSuccessThreshold(), new SystemStopwatch()); } diff --git a/components/camel-microprofile/camel-microprofile-health/src/main/java/org/apache/camel/microprofile/health/CamelMicroProfileHealthHelper.java b/components/camel-microprofile/camel-microprofile-health/src/main/java/org/apache/camel/microprofile/health/CamelMicroProfileHealthHelper.java index ecd9fff..96cccc3 100644 --- a/components/camel-microprofile/camel-microprofile-health/src/main/java/org/apache/camel/microprofile/health/CamelMicroProfileHealthHelper.java +++ b/components/camel-microprofile/camel-microprofile-health/src/main/java/org/apache/camel/microprofile/health/CamelMicroProfileHealthHelper.java @@ -18,21 +18,14 @@ package org.apache.camel.microprofile.health; import java.io.PrintWriter; import java.io.StringWriter; -import java.lang.annotation.Annotation; import java.util.Set; -import javax.enterprise.inject.spi.Bean; -import javax.enterprise.inject.spi.BeanManager; -import javax.enterprise.inject.spi.CDI; - import io.smallrye.health.api.HealthRegistry; -import io.smallrye.health.registry.LivenessHealthRegistry; -import io.smallrye.health.registry.ReadinessHealthRegistry; +import io.smallrye.health.api.HealthType; +import io.smallrye.health.registry.HealthRegistries; import org.apache.camel.health.HealthCheck; import org.apache.camel.health.HealthCheck.Result; import org.eclipse.microprofile.health.HealthCheckResponseBuilder; -import org.eclipse.microprofile.health.Liveness; -import org.eclipse.microprofile.health.Readiness; /** * Helper utility class for MicroProfile health checks. @@ -72,51 +65,17 @@ final class CamelMicroProfileHealthHelper { } /** - * Retrieves the {@link LivenessHealthRegistry} bean instance. - * - * @return The {@link LivenessHealthRegistry} bean. + * Retrieves the liveness registry */ public static HealthRegistry getLivenessRegistry() { - return getHealthRegistryBean(LivenessHealthRegistry.class, Liveness.Literal.INSTANCE); + return HealthRegistries.getRegistry(HealthType.LIVENESS); } /** - * Retrieves the {@link ReadinessHealthRegistry} bean instance. - * - * @return The {@link ReadinessHealthRegistry} bean. + * Retrieves the readiness registry */ public static HealthRegistry getReadinessRegistry() { - return getHealthRegistryBean(ReadinessHealthRegistry.class, Readiness.Literal.INSTANCE); + return HealthRegistries.getRegistry(HealthType.READINESS); } - /** - * Retrieves a {@link HealthRegistry} bean from the CDI bean manager for the given type and qualifier. - * - * Registry beans are looked up from the CDI {@link BeanManager} to avoid CDI injection in - * {@link CamelMicroProfileHealthCheckRegistry} and also avoid having to add CDI bean defining annotations to - * {@link CamelMicroProfileHealthCheckRegistry}. - * - * Eventually this can be removed when upgrading to a future SmallRye Health release where static health registry - * lookups will be supported. - * - * https://github.com/smallrye/smallrye-health/issues/172 - * - * @param type The implementation class of the {@link HealthRegistry} bean - * @param qualifier The annotation qualifier applied to the {@link HealthRegistry} bean - * @return The {@link HealthRegistry} bean - * @throws IllegalStateException if no beans matching the {@link HealthRegistry} bean type and annotation qualifier - * were found - */ - private static HealthRegistry getHealthRegistryBean(Class<? extends HealthRegistry> type, Annotation qualifier) { - BeanManager beanManager = CDI.current().getBeanManager(); - Set<Bean<?>> beans = beanManager.getBeans(type, qualifier); - if (beans.isEmpty()) { - throw new IllegalStateException( - "Beans for type " + type.getName() + " with qualifier " + qualifier + " could not be found."); - } - - Bean<?> bean = beanManager.resolve(beans); - Object reference = beanManager.getReference(bean, type, beanManager.createCreationalContext(bean)); - return type.cast(reference); - } } diff --git a/parent/pom.xml b/parent/pom.xml index bb22fe9..eb017fa 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -488,8 +488,8 @@ <smack-version>4.3.5</smack-version> <smallrye-config-version>2.8.2</smallrye-config-version> <smallrye-metrics-version>3.0.4</smallrye-metrics-version> - <smallrye-health-version>3.1.2</smallrye-health-version> - <smallrye-fault-tolerance-version>5.2.1</smallrye-fault-tolerance-version> + <smallrye-health-version>3.2.0</smallrye-health-version> + <smallrye-fault-tolerance-version>5.3.0</smallrye-fault-tolerance-version> <snakeyaml-version>1.30</snakeyaml-version> <snakeyaml-engine-version>2.3</snakeyaml-engine-version> <snmp4j-version>2.6.3_1</snmp4j-version>
