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

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


Reply via email to