Search in sources :

Example 1 with BeanDiscoveryFinishedBuildItem

use of io.quarkus.arc.deployment.BeanDiscoveryFinishedBuildItem 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);
    }
}
Also used : Record(io.quarkus.deployment.annotations.Record) CamelSupport(org.apache.camel.quarkus.core.deployment.util.CamelSupport) CamelContextBuildItem(org.apache.camel.quarkus.core.deployment.spi.CamelContextBuildItem) CamelComponentNameResolverBuildItem(org.apache.camel.quarkus.core.deployment.spi.CamelComponentNameResolverBuildItem) CamelTypeConverterRegistryBuildItem(org.apache.camel.quarkus.core.deployment.spi.CamelTypeConverterRegistryBuildItem) CamelRegistryBuildItem(org.apache.camel.quarkus.core.deployment.spi.CamelRegistryBuildItem) IsDevelopment(io.quarkus.deployment.IsDevelopment) BuildProducer(io.quarkus.deployment.annotations.BuildProducer) BooleanSupplier(java.util.function.BooleanSupplier) HashSet(java.util.HashSet) BuildStep(io.quarkus.deployment.annotations.BuildStep) BeanDiscoveryFinishedBuildItem(io.quarkus.arc.deployment.BeanDiscoveryFinishedBuildItem) CamelModelJAXBContextFactoryBuildItem(org.apache.camel.quarkus.core.deployment.spi.CamelModelJAXBContextFactoryBuildItem) ModelJAXBContextFactory(org.apache.camel.spi.ModelJAXBContextFactory) RuntimeValue(io.quarkus.runtime.RuntimeValue) CamelContextRecorder(org.apache.camel.quarkus.core.CamelContextRecorder) TypeConverterRegistry(org.apache.camel.spi.TypeConverterRegistry) CamelContext(org.apache.camel.CamelContext) CamelContextCustomizerBuildItem(org.apache.camel.quarkus.core.deployment.spi.CamelContextCustomizerBuildItem) CamelFactoryFinderResolverBuildItem(org.apache.camel.quarkus.core.deployment.spi.CamelFactoryFinderResolverBuildItem) CamelModelToXMLDumperBuildItem(org.apache.camel.quarkus.core.deployment.spi.CamelModelToXMLDumperBuildItem) ExecutionTime(io.quarkus.deployment.annotations.ExecutionTime) Set(java.util.Set) Collectors(java.util.stream.Collectors) List(java.util.List) CamelConfig(org.apache.camel.quarkus.core.CamelConfig) BeanContainerBuildItem(io.quarkus.arc.deployment.BeanContainerBuildItem) Pattern(java.util.regex.Pattern) Pattern(java.util.regex.Pattern) Record(io.quarkus.deployment.annotations.Record) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Aggregations

BeanContainerBuildItem (io.quarkus.arc.deployment.BeanContainerBuildItem)1 BeanDiscoveryFinishedBuildItem (io.quarkus.arc.deployment.BeanDiscoveryFinishedBuildItem)1 IsDevelopment (io.quarkus.deployment.IsDevelopment)1 BuildProducer (io.quarkus.deployment.annotations.BuildProducer)1 BuildStep (io.quarkus.deployment.annotations.BuildStep)1 ExecutionTime (io.quarkus.deployment.annotations.ExecutionTime)1 Record (io.quarkus.deployment.annotations.Record)1 RuntimeValue (io.quarkus.runtime.RuntimeValue)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 BooleanSupplier (java.util.function.BooleanSupplier)1 Pattern (java.util.regex.Pattern)1 Collectors (java.util.stream.Collectors)1 CamelContext (org.apache.camel.CamelContext)1 CamelConfig (org.apache.camel.quarkus.core.CamelConfig)1 CamelContextRecorder (org.apache.camel.quarkus.core.CamelContextRecorder)1 CamelComponentNameResolverBuildItem (org.apache.camel.quarkus.core.deployment.spi.CamelComponentNameResolverBuildItem)1 CamelContextBuildItem (org.apache.camel.quarkus.core.deployment.spi.CamelContextBuildItem)1 CamelContextCustomizerBuildItem (org.apache.camel.quarkus.core.deployment.spi.CamelContextCustomizerBuildItem)1