use of org.springframework.cloud.stream.annotation.Output in project spring-cloud-function by spring-cloud.
the class BeanFactoryEnabledBindings method init.
private void init() {
if (initialized.compareAndSet(false, true)) {
String[] names = beanFactory.getBeanNamesForAnnotation(EnableBinding.class);
for (String bean : names) {
Class<?> type = beanFactory.getType(bean);
MultiValueMap<String, Object> attrs = AnnotatedElementUtils.getAllAnnotationAttributes(type, EnableBinding.class.getName());
List<Object> list = attrs.get("value");
if (list != null) {
for (Object object : list) {
Class<?>[] bindings = (Class<?>[]) object;
for (Class<?> binding : bindings) {
List<String> inputs = new ArrayList<>();
List<String> outputs = new ArrayList<>();
ReflectionUtils.doWithMethods(binding, method -> {
Input input = AnnotationUtils.findAnnotation(method, Input.class);
Output output = AnnotationUtils.findAnnotation(method, Output.class);
if (input != null) {
String name = BindingBeanDefinitionRegistryUtils.getBindingTargetName(input, method);
inputs.add(BeanFactoryEnabledBindings.this.binding.getBindingDestination(name));
}
if (output != null) {
String name = BindingBeanDefinitionRegistryUtils.getBindingTargetName(output, method);
outputs.add(BeanFactoryEnabledBindings.this.binding.getBindingDestination(name));
}
});
BeanFactoryEnabledBindings.this.outputs.addAll(outputs);
BeanFactoryEnabledBindings.this.inputs.addAll(inputs);
if (inputs.size() == 1 && outputs.size() == 1) {
BeanFactoryEnabledBindings.this.outputsToInputs.put(outputs.get(0), inputs.get(0));
}
}
}
}
}
}
}
use of org.springframework.cloud.stream.annotation.Output in project spring-cloud-stream by spring-cloud.
the class StreamListenerMethodUtils method getOutboundBindingTargetName.
protected static String getOutboundBindingTargetName(Method method) {
SendTo sendTo = AnnotationUtils.findAnnotation(method, SendTo.class);
if (sendTo != null) {
Assert.isTrue(!ObjectUtils.isEmpty(sendTo.value()), StreamListenerErrorMessages.ATLEAST_ONE_OUTPUT);
Assert.isTrue(sendTo.value().length == 1, StreamListenerErrorMessages.SEND_TO_MULTIPLE_DESTINATIONS);
Assert.hasText(sendTo.value()[0], StreamListenerErrorMessages.SEND_TO_EMPTY_DESTINATION);
return sendTo.value()[0];
}
Output output = AnnotationUtils.findAnnotation(method, Output.class);
if (output != null) {
Assert.isTrue(StringUtils.hasText(output.value()), StreamListenerErrorMessages.ATLEAST_ONE_OUTPUT);
return output.value();
}
return null;
}
use of org.springframework.cloud.stream.annotation.Output in project spring-cloud-stream by spring-cloud.
the class BindingBeanDefinitionRegistryUtils method registerBindingTargetBeanDefinitions.
public static void registerBindingTargetBeanDefinitions(Class<?> type, final String bindingTargetInterfaceBeanName, final BeanDefinitionRegistry registry) {
ReflectionUtils.doWithMethods(type, method -> {
Input input = AnnotationUtils.findAnnotation(method, Input.class);
if (input != null) {
String name = getBindingTargetName(input, method);
registerInputBindingTargetBeanDefinition(input.value(), name, bindingTargetInterfaceBeanName, method.getName(), registry);
}
Output output = AnnotationUtils.findAnnotation(method, Output.class);
if (output != null) {
String name = getBindingTargetName(output, method);
registerOutputBindingTargetBeanDefinition(output.value(), name, bindingTargetInterfaceBeanName, method.getName(), registry);
}
});
}
use of org.springframework.cloud.stream.annotation.Output in project spring-cloud-stream by spring-cloud.
the class StreamAnnotationCommonMethodUtils method getOutboundBindingTargetName.
public static String getOutboundBindingTargetName(Method method) {
SendTo sendTo = AnnotationUtils.findAnnotation(method, SendTo.class);
if (sendTo != null) {
Assert.isTrue(!ObjectUtils.isEmpty(sendTo.value()), StreamAnnotationErrorMessages.ATLEAST_ONE_OUTPUT);
Assert.isTrue(sendTo.value().length == 1, StreamAnnotationErrorMessages.SEND_TO_MULTIPLE_DESTINATIONS);
Assert.hasText(sendTo.value()[0], StreamAnnotationErrorMessages.SEND_TO_EMPTY_DESTINATION);
return sendTo.value()[0];
}
Output output = AnnotationUtils.findAnnotation(method, Output.class);
if (output != null) {
Assert.isTrue(StringUtils.hasText(output.value()), StreamAnnotationErrorMessages.ATLEAST_ONE_OUTPUT);
return output.value();
}
return null;
}
use of org.springframework.cloud.stream.annotation.Output in project spring-cloud-stream by spring-cloud.
the class BindableProxyFactory method invoke.
@Override
public synchronized Object invoke(MethodInvocation invocation) throws Throwable {
Method method = invocation.getMethod();
// try to use cached target
Object boundTarget = targetCache.get(method);
if (boundTarget != null) {
return boundTarget;
}
Input input = AnnotationUtils.findAnnotation(method, Input.class);
if (input != null) {
String name = BindingBeanDefinitionRegistryUtils.getBindingTargetName(input, method);
boundTarget = this.inputHolders.get(name).getBoundTarget();
targetCache.put(method, boundTarget);
return boundTarget;
} else {
Output output = AnnotationUtils.findAnnotation(method, Output.class);
if (output != null) {
String name = BindingBeanDefinitionRegistryUtils.getBindingTargetName(output, method);
boundTarget = this.outputHolders.get(name).getBoundTarget();
targetCache.put(method, boundTarget);
return boundTarget;
}
}
return null;
}
Aggregations