Search in sources :

Example 1 with CamelBeanBuildItem

use of org.apache.camel.quarkus.core.deployment.spi.CamelBeanBuildItem in project camel-quarkus by apache.

the class MicroProfileHealthProcessor method camelHealthDiscovery.

@BuildStep(onlyIf = HealthEnabled.class)
List<CamelBeanBuildItem> camelHealthDiscovery(CombinedIndexBuildItem combinedIndex) {
    IndexView index = combinedIndex.getIndex();
    List<CamelBeanBuildItem> buildItems = new ArrayList<>();
    Collection<ClassInfo> healthChecks = index.getAllKnownImplementors(CAMEL_HEALTH_CHECK_DOTNAME);
    Collection<ClassInfo> healthCheckRepositories = index.getAllKnownImplementors(CAMEL_HEALTH_CHECK_REPOSITORY_DOTNAME);
    Config config = ConfigProvider.getConfig();
    Predicate<ClassInfo> healthCheckFilter = classInfo -> {
        String className = classInfo.name().toString();
        if (className.equals(HealthCheckRegistryRepository.class.getName())) {
            // HealthCheckRegistryRepository is created internally by Camel
            return false;
        }
        if (className.equals(ContextHealthCheck.class.getName())) {
            return config.getOptionalValue("camel.health.contextEnabled", boolean.class).orElse(true);
        }
        if (className.equals(RoutesHealthCheckRepository.class.getName())) {
            return config.getOptionalValue("camel.health.routesEnabled", boolean.class).orElse(true);
        }
        if (className.equals(ConsumersHealthCheckRepository.class.getName())) {
            return config.getOptionalValue("camel.health.consumersEnabled", boolean.class).orElse(true);
        }
        return true;
    };
    // Create CamelBeanBuildItem to bind instances of HealthCheck to the camel registry
    healthChecks.stream().filter(CamelSupport::isConcrete).filter(CamelSupport::isPublic).filter(ClassInfo::hasNoArgsConstructor).filter(healthCheckFilter).map(this::createHealthCamelBeanBuildItem).forEach(buildItems::add);
    // Create CamelBeanBuildItem to bind instances of HealthCheckRepository to the camel registry
    healthCheckRepositories.stream().filter(CamelSupport::isConcrete).filter(CamelSupport::isPublic).filter(ClassInfo::hasNoArgsConstructor).filter(healthCheckFilter).map(this::createHealthCamelBeanBuildItem).forEach(buildItems::add);
    return buildItems;
}
Also used : Record(io.quarkus.deployment.annotations.Record) CamelSupport(org.apache.camel.quarkus.core.deployment.util.CamelSupport) HealthCheckRepository(org.apache.camel.health.HealthCheckRepository) DotName(org.jboss.jandex.DotName) CamelServicePatternBuildItem(org.apache.camel.quarkus.core.deployment.spi.CamelServicePatternBuildItem) ClassInfo(org.jboss.jandex.ClassInfo) CombinedIndexBuildItem(io.quarkus.deployment.builditem.CombinedIndexBuildItem) HealthCheckRegistry(org.apache.camel.health.HealthCheckRegistry) ArrayList(java.util.ArrayList) BooleanSupplier(java.util.function.BooleanSupplier) BuildStep(io.quarkus.deployment.annotations.BuildStep) FeatureBuildItem(io.quarkus.deployment.builditem.FeatureBuildItem) CamelServiceDestination(org.apache.camel.quarkus.core.deployment.spi.CamelServiceDestination) CamelMicroProfileHealthConfig(org.apache.camel.quarkus.component.microprofile.health.runtime.CamelMicroProfileHealthConfig) HealthCheckRegistryRepository(org.apache.camel.impl.health.HealthCheckRegistryRepository) HealthCheck(org.apache.camel.health.HealthCheck) IndexView(org.jboss.jandex.IndexView) CamelMicroProfileHealthRecorder(org.apache.camel.quarkus.component.microprofile.health.runtime.CamelMicroProfileHealthRecorder) ConsumersHealthCheckRepository(org.apache.camel.impl.health.ConsumersHealthCheckRepository) CamelContextCustomizerBuildItem(org.apache.camel.quarkus.core.deployment.spi.CamelContextCustomizerBuildItem) CamelBeanBuildItem(org.apache.camel.quarkus.core.deployment.spi.CamelBeanBuildItem) Predicate(java.util.function.Predicate) Collection(java.util.Collection) ExecutionTime(io.quarkus.deployment.annotations.ExecutionTime) ContextHealthCheck(org.apache.camel.impl.health.ContextHealthCheck) Config(org.eclipse.microprofile.config.Config) HealthBuildTimeConfig(io.quarkus.smallrye.health.deployment.HealthBuildTimeConfig) List(java.util.List) RoutesHealthCheckRepository(org.apache.camel.impl.health.RoutesHealthCheckRepository) ConfigProvider(org.eclipse.microprofile.config.ConfigProvider) ObjectHelper(org.apache.camel.util.ObjectHelper) CamelBeanBuildItem(org.apache.camel.quarkus.core.deployment.spi.CamelBeanBuildItem) IndexView(org.jboss.jandex.IndexView) CamelMicroProfileHealthConfig(org.apache.camel.quarkus.component.microprofile.health.runtime.CamelMicroProfileHealthConfig) Config(org.eclipse.microprofile.config.Config) HealthBuildTimeConfig(io.quarkus.smallrye.health.deployment.HealthBuildTimeConfig) ArrayList(java.util.ArrayList) CamelSupport(org.apache.camel.quarkus.core.deployment.util.CamelSupport) ClassInfo(org.jboss.jandex.ClassInfo) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Example 2 with CamelBeanBuildItem

use of org.apache.camel.quarkus.core.deployment.spi.CamelBeanBuildItem in project camel-quarkus by apache.

the class CSimpleProcessor method configureCSimpleLanguage.

@Record(ExecutionTime.STATIC_INIT)
@BuildStep
@Consume(CamelContextBuildItem.class)
CamelBeanBuildItem configureCSimpleLanguage(RecorderContext recorderContext, CSimpleLanguageRecorder recorder, List<CompiledCSimpleExpressionBuildItem> compiledCSimpleExpressions) {
    final RuntimeValue<Builder> builder = recorder.csimpleLanguageBuilder();
    for (CompiledCSimpleExpressionBuildItem expr : compiledCSimpleExpressions) {
        recorder.addExpression(builder, recorderContext.newInstance(expr.getClassName()));
    }
    final RuntimeValue<?> csimpleLanguage = recorder.buildCSimpleLanguage(builder);
    return new CamelBeanBuildItem("csimple", CSimpleLanguage.class.getName(), csimpleLanguage);
}
Also used : CSimpleLanguage(org.apache.camel.language.csimple.CSimpleLanguage) CamelBeanBuildItem(org.apache.camel.quarkus.core.deployment.spi.CamelBeanBuildItem) RouteBuilder(org.apache.camel.builder.RouteBuilder) Builder(org.apache.camel.language.csimple.CSimpleLanguage.Builder) CompiledCSimpleExpressionBuildItem(org.apache.camel.quarkus.core.deployment.spi.CompiledCSimpleExpressionBuildItem) Consume(io.quarkus.deployment.annotations.Consume) Record(io.quarkus.deployment.annotations.Record) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Example 3 with CamelBeanBuildItem

use of org.apache.camel.quarkus.core.deployment.spi.CamelBeanBuildItem in project camel-quarkus by apache.

the class CamelRegistryProcessor method bindBeansToRegistry.

@Record(ExecutionTime.STATIC_INIT)
@BuildStep
public void bindBeansToRegistry(CamelRecorder recorder, CamelConfig camelConfig, ApplicationArchivesBuildItem applicationArchives, ContainerBeansBuildItem containerBeans, CamelRegistryBuildItem registry, // CamelContextBuildItem placeholder ensures this build step runs after the CamelContext is created
CamelContextBuildItem camelContextBuildItem, List<CamelBeanBuildItem> registryItems, List<CamelServiceFilterBuildItem> serviceFilters, List<CamelServicePatternBuildItem> servicePatterns) {
    final ClassLoader TCCL = Thread.currentThread().getContextClassLoader();
    final PathFilter pathFilter = servicePatterns.stream().filter(patterns -> patterns.getDestination() == CamelServiceDestination.REGISTRY).collect(PathFilter.Builder::new, (builder, patterns) -> builder.patterns(patterns.isInclude(), patterns.getPatterns()), PathFilter.Builder::combine).include(camelConfig.service.registry.includePatterns).exclude(camelConfig.service.registry.excludePatterns).build();
    CamelSupport.services(applicationArchives, pathFilter).filter(si -> !containerBeans.getBeans().contains(si)).filter(si -> {
        // 
        // by default all the service found in META-INF/service/org/apache/camel are
        // bound to the registry but some of the services are then replaced or set
        // to the camel context directly by extension so it does not make sense to
        // instantiate them in this phase.
        // 
        boolean blacklisted = serviceFilters.stream().anyMatch(filter -> filter.getPredicate().test(si));
        if (blacklisted) {
            LOGGER.debug("Ignore service: {}", si);
        }
        return !blacklisted;
    }).forEach(si -> {
        LOGGER.debug("Binding bean with name: {}, type {}", si.name, si.type);
        recorder.bind(registry.getRegistry(), si.name, CamelSupport.loadClass(si.type, TCCL));
    });
    registryItems.stream().filter(item -> !containerBeans.getBeans().contains(item)).forEach(item -> {
        LOGGER.debug("Binding bean with name: {}, type {}", item.getName(), item.getType());
        if (item.getValue().isPresent()) {
            recorder.bind(registry.getRegistry(), item.getName(), CamelSupport.loadClass(item.getType(), TCCL), item.getValue().get());
        } else {
            // the instance of the service will be instantiated by the recorder, this avoid
            // creating a recorder for trivial services.
            recorder.bind(registry.getRegistry(), item.getName(), CamelSupport.loadClass(item.getType(), TCCL));
        }
    });
}
Also used : CamelRuntimeTaskBuildItem(org.apache.camel.quarkus.core.deployment.spi.CamelRuntimeTaskBuildItem) Record(io.quarkus.deployment.annotations.Record) CamelSupport(org.apache.camel.quarkus.core.deployment.util.CamelSupport) CamelContextBuildItem(org.apache.camel.quarkus.core.deployment.spi.CamelContextBuildItem) Logger(org.slf4j.Logger) ApplicationArchivesBuildItem(io.quarkus.deployment.builditem.ApplicationArchivesBuildItem) CamelBeanBuildItem(org.apache.camel.quarkus.core.deployment.spi.CamelBeanBuildItem) CamelRuntimeBeanBuildItem(org.apache.camel.quarkus.core.deployment.spi.CamelRuntimeBeanBuildItem) PathFilter(org.apache.camel.quarkus.core.deployment.util.PathFilter) ExecutionTime(io.quarkus.deployment.annotations.ExecutionTime) LoggerFactory(org.slf4j.LoggerFactory) CamelServiceFilterBuildItem(org.apache.camel.quarkus.core.deployment.spi.CamelServiceFilterBuildItem) ContainerBeansBuildItem(org.apache.camel.quarkus.core.deployment.spi.ContainerBeansBuildItem) CamelRegistryBuildItem(org.apache.camel.quarkus.core.deployment.spi.CamelRegistryBuildItem) CamelServicePatternBuildItem(org.apache.camel.quarkus.core.deployment.spi.CamelServicePatternBuildItem) BuildStep(io.quarkus.deployment.annotations.BuildStep) List(java.util.List) CamelConfig(org.apache.camel.quarkus.core.CamelConfig) CamelRecorder(org.apache.camel.quarkus.core.CamelRecorder) CamelServiceDestination(org.apache.camel.quarkus.core.deployment.spi.CamelServiceDestination) PathFilter(org.apache.camel.quarkus.core.deployment.util.PathFilter) Record(io.quarkus.deployment.annotations.Record) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Aggregations

BuildStep (io.quarkus.deployment.annotations.BuildStep)3 Record (io.quarkus.deployment.annotations.Record)3 CamelBeanBuildItem (org.apache.camel.quarkus.core.deployment.spi.CamelBeanBuildItem)3 ExecutionTime (io.quarkus.deployment.annotations.ExecutionTime)2 List (java.util.List)2 CamelServiceDestination (org.apache.camel.quarkus.core.deployment.spi.CamelServiceDestination)2 CamelServicePatternBuildItem (org.apache.camel.quarkus.core.deployment.spi.CamelServicePatternBuildItem)2 CamelSupport (org.apache.camel.quarkus.core.deployment.util.CamelSupport)2 Consume (io.quarkus.deployment.annotations.Consume)1 ApplicationArchivesBuildItem (io.quarkus.deployment.builditem.ApplicationArchivesBuildItem)1 CombinedIndexBuildItem (io.quarkus.deployment.builditem.CombinedIndexBuildItem)1 FeatureBuildItem (io.quarkus.deployment.builditem.FeatureBuildItem)1 HealthBuildTimeConfig (io.quarkus.smallrye.health.deployment.HealthBuildTimeConfig)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 BooleanSupplier (java.util.function.BooleanSupplier)1 Predicate (java.util.function.Predicate)1 RouteBuilder (org.apache.camel.builder.RouteBuilder)1 HealthCheck (org.apache.camel.health.HealthCheck)1 HealthCheckRegistry (org.apache.camel.health.HealthCheckRegistry)1