ppalaga commented on a change in pull request #3151:
URL: https://github.com/apache/camel-quarkus/pull/3151#discussion_r721425980



##########
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<String> 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<String> observedManagementEvents = beanDiscovery.getObservers()
+                .stream()
+                .filter(observerInfo -> 
observerInfo.getObservedType().name().toString()
+                        .matches("org.apache.camel(?!.quarkus).*Event$"))
+                .map(observerInfo -> 
observerInfo.getObservedType().name().local())

Review comment:
       Hm... why is `.local()` here and not above when collecting 
`observedLifecycleEvents`?

##########
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<String> observedLifecycleEvents = beanDiscovery.getObservers()
+                .stream()
+                .map(observerInfo -> 
observerInfo.getObservedType().name().toString())
+                .filter(observedType -> 
observedType.startsWith("org.apache.camel.quarkus.core.events"))

Review comment:
       A tip for the future: My fix introducing `DotName.packagePrefix()` is 
available in Jandex 2.4.0

##########
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<String> 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<String> observedManagementEvents = beanDiscovery.getObservers()
+                .stream()
+                .filter(observerInfo -> 
observerInfo.getObservedType().name().toString()
+                        .matches("org.apache.camel(?!.quarkus).*Event$"))
+                .map(observerInfo -> 
observerInfo.getObservedType().name().local())

Review comment:
       Now I see 
`observedManagementEvents.contains(event.getClass().getSimpleName())` in 
`CamelManagementEventBridge`, but beware that `DotName.local()` might not be 
what you expect - read its JavaDoc and impl. Maybe you want 
`DotName.withoutPackagePrefix()` but hard to say whather that's the best 
option, bc. I do not know what you expect for inner classes?
   I still wonder why we cannot use FQ names here?

##########
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:
       CamelMainEventBridge is there - fine. But shouldn't/can't we also test 
that it really works by asserting that EventHandler.routes() and 
EventHandler.builders() contain the expected entries? It's perhaps tested 
elsewhere?




-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to