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;
}
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);
}
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));
}
});
}
Aggregations