use of org.apache.camel.quarkus.core.CamelContextRecorder in project camel-quarkus by apache.
the class CamelContextProcessor method registerCamelEventBridges.
/**
* 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));
// For management events the event class simple name is collected as users can
// observe events on either the Camel event interface or the concrete event class, and
// these are located in different packages
final Pattern pattern = Pattern.compile("org.apache.camel(?!.quarkus).*Event$");
Set<String> observedManagementEvents = beanDiscovery.getObservers().stream().map(observerInfo -> observerInfo.getObservedType().name().toString()).filter(className -> pattern.matcher(className).matches()).map(className -> CamelSupport.loadClass(className, Thread.currentThread().getContextClassLoader())).map(observedEventClass -> observedEventClass.getSimpleName()).collect(Collectors.collectingAndThen(Collectors.toUnmodifiableSet(), HashSet::new));
if (!observedLifecycleEvents.isEmpty()) {
recorder.registerLifecycleEventBridge(context.getCamelContext(), observedLifecycleEvents);
}
if (!observedManagementEvents.isEmpty()) {
recorder.registerManagementEventBridge(context.getCamelContext(), observedManagementEvents);
}
}
Aggregations