[GitHub] [camel-quarkus] jamesnetherton commented on a change in pull request #3151: Register CDI event bridges only when required
jamesnetherton commented on a change in pull request #3151: URL: https://github.com/apache/camel-quarkus/pull/3151#discussion_r721951657 ## File path: extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelContextProcessor.java ## @@ -163,4 +168,50 @@ public CamelRuntimeBuildItem runtime( recorder.createRuntime(beanContainer.getValue(), context.getCamelContext()), config.bootstrap.enabled); } + +/** + * Registers Camel CDI event bridges if quarkus.camel.event-bridge.enabled=true and if + * the relevant events have CDI observers configured for them. + * + * @param beanDiscovery build item containing the results of bean discovery + * @param context build item containing the CamelContext instance + * @param recorder the CamelContext recorder instance + */ +@Record(ExecutionTime.STATIC_INIT) +@BuildStep(onlyIf = EventBridgeEnabled.class) +public void registerCamelEventBridges( +BeanDiscoveryFinishedBuildItem beanDiscovery, +CamelContextBuildItem context, +CamelContextRecorder recorder) { + +Set observedLifecycleEvents = beanDiscovery.getObservers() +.stream() +.map(observerInfo -> observerInfo.getObservedType().name().toString()) +.filter(observedType -> observedType.startsWith("org.apache.camel.quarkus.core.events")) + .collect(Collectors.collectingAndThen(Collectors.toUnmodifiableSet(), HashSet::new)); + +Set observedManagementEvents = beanDiscovery.getObservers() +.stream() +.filter(observerInfo -> observerInfo.getObservedType().name().toString() +.matches("org.apache.camel(?!.quarkus).*Event$")) +.map(observerInfo -> observerInfo.getObservedType().name().local()) Review comment: I tweaked things a bit to obtain an instance of the observed event class and then use it to get the simple name. Hopefully that's acceptable. I also added some comments explaining why simple name is used. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@camel.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[GitHub] [camel-quarkus] jamesnetherton commented on a change in pull request #3151: Register CDI event bridges only when required
jamesnetherton commented on a change in pull request #3151: URL: https://github.com/apache/camel-quarkus/pull/3151#discussion_r721481859 ## File path: extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelContextProcessor.java ## @@ -163,4 +168,50 @@ public CamelRuntimeBuildItem runtime( recorder.createRuntime(beanContainer.getValue(), context.getCamelContext()), config.bootstrap.enabled); } + +/** + * Registers Camel CDI event bridges if quarkus.camel.event-bridge.enabled=true and if + * the relevant events have CDI observers configured for them. + * + * @param beanDiscovery build item containing the results of bean discovery + * @param context build item containing the CamelContext instance + * @param recorder the CamelContext recorder instance + */ +@Record(ExecutionTime.STATIC_INIT) +@BuildStep(onlyIf = EventBridgeEnabled.class) +public void registerCamelEventBridges( +BeanDiscoveryFinishedBuildItem beanDiscovery, +CamelContextBuildItem context, +CamelContextRecorder recorder) { + +Set observedLifecycleEvents = beanDiscovery.getObservers() +.stream() +.map(observerInfo -> observerInfo.getObservedType().name().toString()) +.filter(observedType -> observedType.startsWith("org.apache.camel.quarkus.core.events")) + .collect(Collectors.collectingAndThen(Collectors.toUnmodifiableSet(), HashSet::new)); + +Set observedManagementEvents = beanDiscovery.getObservers() +.stream() +.filter(observerInfo -> observerInfo.getObservedType().name().toString() +.matches("org.apache.camel(?!.quarkus).*Event$")) +.map(observerInfo -> observerInfo.getObservedType().name().local()) Review comment: > I still wonder why we cannot use FQ names here? Because in theory for Camel management events someone may code their app to either observe on the interface type. E.g `org.apache.camel.spi.CamelEvent.ExchangeCompletedEvent` or on the implementation class `org.apache.camel.impl.event.ExchangeCompletedEvent`. In that case we need to match on the simple name, because the event type receieved at runtime is always the implementation class. Hence the usage of `local()` to avoid additional bits like '$' etc. Maybe we should not support observing on the plain interface type and we just mandate observing on the impl classes? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@camel.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[GitHub] [camel-quarkus] jamesnetherton commented on a change in pull request #3151: Register CDI event bridges only when required
jamesnetherton commented on a change in pull request #3151: URL: https://github.com/apache/camel-quarkus/pull/3151#discussion_r721473206 ## File path: extensions-core/core/deployment/src/test/java/org/apache/camel/quarkus/core/deployment/main/CamelMainEventBridgeDisabledConfigTest.java ## @@ -0,0 +1,113 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.camel.quarkus.core.deployment.main; + +import java.io.IOException; +import java.io.StringWriter; +import java.io.Writer; +import java.util.Properties; +import java.util.Set; +import java.util.concurrent.CopyOnWriteArraySet; + +import javax.enterprise.context.ApplicationScoped; +import javax.enterprise.event.Observes; +import javax.inject.Inject; + +import io.quarkus.test.QuarkusUnitTest; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.model.ModelCamelContext; +import org.apache.camel.quarkus.main.CamelMain; +import org.apache.camel.quarkus.main.CamelMainEventBridge; +import org.apache.camel.quarkus.main.events.AfterConfigure; +import org.apache.camel.quarkus.main.events.AfterStart; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.Asset; +import org.jboss.shrinkwrap.api.asset.StringAsset; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import static org.junit.jupiter.api.Assertions.assertFalse; + +public class CamelMainEventBridgeDisabledConfigTest { +@RegisterExtension +static final QuarkusUnitTest CONFIG = new QuarkusUnitTest() +.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) +.addAsResource(applicationProperties(), "application.properties")); + +@Inject +CamelMain main; + +@Test +public void testObservers() { +assertFalse(main.getMainListeners().stream().anyMatch(mainListener -> mainListener +.getClass() +.equals(CamelMainEventBridge.class))); +} Review comment: There's an existing test for that `CamelMainObserversTest`. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@camel.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[GitHub] [camel-quarkus] jamesnetherton commented on a change in pull request #3151: Register CDI event bridges only when required
jamesnetherton commented on a change in pull request #3151: URL: https://github.com/apache/camel-quarkus/pull/3151#discussion_r721464858 ## File path: docs/modules/ROOT/pages/reference/extensions/core.adoc ## @@ -239,6 +239,14 @@ What to do if it is not possible to extract CSimple expressions from a route def | `org.apache.camel.quarkus.core.CamelConfig.FailureRemedy` | `warn` +|icon:lock[title=Fixed at build time] [[quarkus.camel.event-bridge.enabled]]`link:#quarkus.camel.event-bridge.enabled[quarkus.camel.event-bridge.enabled]` + +Whether to enable the bridging of Camel events to CDI events. + This allows CDI observers to be configured for Camel events. E.g. those belonging to the `org.apache.camel.quarkus.core.events`, `org.apache.camel.quarkus.main.events` & `org.apache.camel.impl.event` packages. + Note that his configuration item only has any effect when observers configured for Camel management events are present in the application. +| `boolean` +| `true` Review comment: Correct. Arguably you could not have a config param at all and just determine it based on whether observers are present. But I thought it'd still be worth having some option of forcably disabling the event bridge if required. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@camel.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[GitHub] [camel-quarkus] jamesnetherton commented on a change in pull request #3151: Register CDI event bridges only when required
jamesnetherton commented on a change in pull request #3151: URL: https://github.com/apache/camel-quarkus/pull/3151#discussion_r721461240 ## File path: extensions-core/core/deployment/src/test/java/org/apache/camel/quarkus/core/deployment/main/CamelMainEventBridgeDisabledConfigTest.java ## @@ -0,0 +1,113 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.camel.quarkus.core.deployment.main; + +import java.io.IOException; +import java.io.StringWriter; +import java.io.Writer; +import java.util.Properties; +import java.util.Set; +import java.util.concurrent.CopyOnWriteArraySet; + +import javax.enterprise.context.ApplicationScoped; +import javax.enterprise.event.Observes; +import javax.inject.Inject; + +import io.quarkus.test.QuarkusUnitTest; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.model.ModelCamelContext; +import org.apache.camel.quarkus.main.CamelMain; +import org.apache.camel.quarkus.main.CamelMainEventBridge; +import org.apache.camel.quarkus.main.events.AfterConfigure; +import org.apache.camel.quarkus.main.events.AfterStart; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.Asset; +import org.jboss.shrinkwrap.api.asset.StringAsset; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import static org.junit.jupiter.api.Assertions.assertFalse; + +public class CamelMainEventBridgeDisabledConfigTest { +@RegisterExtension +static final QuarkusUnitTest CONFIG = new QuarkusUnitTest() +.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) +.addAsResource(applicationProperties(), "application.properties")); + +@Inject +CamelMain main; + +@Test +public void testObservers() { +assertFalse(main.getMainListeners().stream().anyMatch(mainListener -> mainListener +.getClass() +.equals(CamelMainEventBridge.class))); +} + +public static Asset applicationProperties() { +Writer writer = new StringWriter(); + +Properties props = new Properties(); +props.setProperty("quarkus.banner.enabled", "false"); +props.setProperty("quarkus.camel.event-bridge.enabled", "false"); + +try { +props.store(writer, ""); +} catch (IOException e) { +throw new RuntimeException(e); +} + +return new StringAsset(writer.toString()); +} + +@ApplicationScoped Review comment: Well spotted! I wanted to verify that even if the observers are still present that they are effectively inactive. So I'll add the missing assertions -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@camel.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org