use of io.quarkus.arc.deployment.ObserverRegistrationPhaseBuildItem.ObserverConfiguratorBuildItem in project quarkus-operator-sdk by quarkiverse.
the class OperatorSDKProcessor method createDelayedRegistrationObservers.
/**
* This looks for all resource controllers, to find those that want a delayed registration, and
* creates one CDI observer for each, that will call operator.register on them when the event is
* fired.
*/
@BuildStep
void createDelayedRegistrationObservers(CombinedIndexBuildItem combinedIndexBuildItem, ObserverRegistrationPhaseBuildItem observerRegistrationPhase, BuildProducer<ObserverConfiguratorBuildItem> observerConfigurators) {
final var index = combinedIndexBuildItem.getIndex();
ClassUtils.getKnownReconcilers(index, log).forEach(info -> {
final var controllerClassName = info.name().toString();
final var controllerAnnotation = info.classAnnotation(CONTROLLER_CONFIGURATION);
final var name = ConfigurationUtils.getReconcilerName(controllerClassName, controllerAnnotation);
// extract the configuration from annotation and/or external configuration
final var configExtractor = new BuildTimeHybridControllerConfiguration(buildTimeConfiguration, buildTimeConfiguration.controllers.get(name), controllerAnnotation, info.classAnnotation(DELAY_REGISTRATION));
if (configExtractor.delayedRegistration()) {
ObserverConfigurator configurator = observerRegistrationPhase.getContext().configure().observedType(configExtractor.eventType()).beanClass(info.name()).notify(mc -> {
MethodDescriptor cdiMethod = MethodDescriptor.ofMethod(CDI.class, "current", CDI.class);
MethodDescriptor selectMethod = MethodDescriptor.ofMethod(CDI.class, "select", Instance.class, Class.class, Annotation[].class);
MethodDescriptor getMethod = MethodDescriptor.ofMethod(Instance.class, "get", Object.class);
AssignableResultHandle cdiVar = mc.createVariable(CDI.class);
mc.assign(cdiVar, mc.invokeStaticMethod(cdiMethod));
ResultHandle operator = getHandleFromCDI(mc, selectMethod, getMethod, cdiVar, Operator.class, null);
ResultHandle resource = getHandleFromCDI(mc, selectMethod, getMethod, cdiVar, Reconciler.class, controllerClassName);
ResultHandle config = getHandleFromCDI(mc, selectMethod, getMethod, cdiVar, QuarkusConfigurationService.class, null);
mc.invokeStaticMethod(MethodDescriptor.ofMethod(OperatorProducer.class, "applyCRDIfNeededAndRegister", void.class, Operator.class, Reconciler.class, QuarkusConfigurationService.class), operator, resource, config);
mc.returnValue(null);
});
observerConfigurators.produce(new ObserverConfiguratorBuildItem(configurator));
}
});
}
Aggregations