use of io.quarkus.smallrye.reactivemessaging.deployment.items.InjectedEmitterBuildItem in project quarkus by quarkusio.
the class SmallRyeReactiveMessagingProcessor method build.
@BuildStep
@Record(STATIC_INIT)
public void build(SmallRyeReactiveMessagingRecorder recorder, RecorderContext recorderContext, BuildProducer<SyntheticBeanBuildItem> syntheticBeans, List<MediatorBuildItem> mediatorMethods, List<InjectedEmitterBuildItem> emitterFields, List<InjectedChannelBuildItem> channelFields, BuildProducer<GeneratedClassBuildItem> generatedClass, BuildProducer<ReflectiveClassBuildItem> reflectiveClass, ReactiveMessagingConfiguration conf) {
ClassOutput classOutput = new GeneratedClassGizmoAdaptor(generatedClass, true);
List<QuarkusMediatorConfiguration> mediatorConfigurations = new ArrayList<>(mediatorMethods.size());
List<WorkerConfiguration> workerConfigurations = new ArrayList<>();
List<EmitterConfiguration> emittersConfigurations = new ArrayList<>();
List<ChannelConfiguration> channelConfigurations = new ArrayList<>();
/*
* Go through the collected MediatorMethods and build up the corresponding MediaConfiguration
* This includes generating an invoker for each method
* The configuration will then be captured and used at static init time to push data into smallrye
*/
for (MediatorBuildItem mediatorMethod : mediatorMethods) {
MethodInfo methodInfo = mediatorMethod.getMethod();
BeanInfo bean = mediatorMethod.getBean();
if (methodInfo.hasAnnotation(BLOCKING) || methodInfo.hasAnnotation(SMALLRYE_BLOCKING) || methodInfo.hasAnnotation(TRANSACTIONAL)) {
// Just in case both annotation are used, use @Blocking value.
String poolName = Blocking.DEFAULT_WORKER_POOL;
// If the method is annotated with the SmallRye Reactive Messaging @Blocking, extract the worker pool name if any
if (methodInfo.hasAnnotation(ReactiveMessagingDotNames.BLOCKING)) {
AnnotationInstance blocking = methodInfo.annotation(ReactiveMessagingDotNames.BLOCKING);
poolName = blocking.value() == null ? Blocking.DEFAULT_WORKER_POOL : blocking.value().asString();
}
workerConfigurations.add(new WorkerConfiguration(methodInfo.declaringClass().toString(), methodInfo.name(), poolName));
}
try {
boolean isSuspendMethod = isSuspendMethod(methodInfo);
QuarkusMediatorConfiguration mediatorConfiguration = QuarkusMediatorConfigurationUtil.create(methodInfo, isSuspendMethod, bean, recorderContext, Thread.currentThread().getContextClassLoader(), conf.strict);
mediatorConfigurations.add(mediatorConfiguration);
String generatedInvokerName = generateInvoker(bean, methodInfo, isSuspendMethod, mediatorConfiguration, classOutput);
/*
* We need to register the invoker's constructor for reflection since it will be called inside smallrye.
* We could potentially lift this restriction with some extra CDI bean generation, but it's probably not worth
* it
*/
reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, generatedInvokerName));
mediatorConfiguration.setInvokerClass((Class<? extends Invoker>) recorderContext.classProxy(generatedInvokerName));
} catch (IllegalArgumentException e) {
// needed to pass the TCK
throw new DeploymentException(e);
}
}
for (InjectedEmitterBuildItem it : emitterFields) {
emittersConfigurations.add(it.getEmitterConfig());
}
for (InjectedChannelBuildItem it : channelFields) {
channelConfigurations.add(it.getChannelConfig());
}
syntheticBeans.produce(SyntheticBeanBuildItem.configure(SmallRyeReactiveMessagingContext.class).supplier(recorder.createContext(mediatorConfigurations, workerConfigurations, emittersConfigurations, channelConfigurations)).done());
}
Aggregations