List of usage examples for org.springframework.core ResolvableType forMethodParameter
public static ResolvableType forMethodParameter(MethodParameter methodParameter, @Nullable Type targetType)
From source file:org.mule.module.extension.internal.util.IntrospectionUtils.java
/** * Returns an array of {@link DataType}/* ww w. j a v a2 s .co m*/ * representing each of the given {@link java.lang.reflect.Method}'s argument * types. * * @param method a not {@code null} {@link java.lang.reflect.Method} * @return an array of {@link DataType} matching * the method's arguments. If the method doesn't take any, then the array will be empty * @throws java.lang.IllegalArgumentException is method is {@code null} */ public static DataType[] getMethodArgumentTypes(Method method) { checkArgument(method != null, "Can't introspect a null method"); Class<?>[] parameters = method.getParameterTypes(); if (ArrayUtils.isEmpty(parameters)) { return new DataType[] {}; } DataType[] types = new DataType[parameters.length]; for (int i = 0; i < parameters.length; i++) { ResolvableType type = ResolvableType.forMethodParameter(method, i); types[i] = toDataType(type); } return types; }
From source file:org.springframework.context.event.ApplicationListenerMethodAdapter.java
private List<ResolvableType> resolveDeclaredEventTypes(Method method, @Nullable EventListener ann) { int count = method.getParameterCount(); if (count > 1) { throw new IllegalStateException( "Maximum one parameter is allowed for event listener method: " + method); }/*w w w .j a v a 2 s .co m*/ if (ann != null && ann.classes().length > 0) { List<ResolvableType> types = new ArrayList<>(ann.classes().length); for (Class<?> eventType : ann.classes()) { types.add(ResolvableType.forClass(eventType)); } return types; } else { if (count == 0) { throw new IllegalStateException( "Event parameter is mandatory for event listener method: " + method); } return Collections.singletonList(ResolvableType.forMethodParameter(method, 0)); } }
From source file:org.springframework.xd.reactor.BroadcasterMessageHandler.java
/** * Construct a new BroadcasterMessageHandler given the reactor based Processor to delegate * processing to./*from w w w . j ava2s.co m*/ * * @param processor The stream based reactor processor */ @SuppressWarnings({ "unchecked", "rawtypes" }) public BroadcasterMessageHandler(Processor processor) { Assert.notNull(processor, "processor cannot be null."); this.reactorProcessor = processor; Environment.initializeIfEmpty(); // This by default uses SynchronousDispatcher Method method = ReflectionUtils.findMethod(this.reactorProcessor.getClass(), "process", Stream.class); this.inputType = ResolvableType.forMethodParameter(method, 0).getNested(2); //Stream with a SynchronousDispatcher as this handler is called by Message Listener managed threads this.stream = SerializedBroadcaster.create(); //user defined stream processing Stream<?> outputStream = processor.process(stream); //Simple log error handling outputStream.when(Throwable.class, new Consumer<Throwable>() { @Override public void accept(Throwable throwable) { logger.error(throwable); } }); this.control = outputStream.consume(new Consumer<Object>() { @Override public void accept(Object outputObject) { if (ClassUtils.isAssignable(Message.class, outputObject.getClass())) { getOutputChannel().send((Message) outputObject); } else { getOutputChannel().send(MessageBuilder.withPayload(outputObject).build()); } } }); if (logger.isDebugEnabled()) { logger.debug(control.debug()); } }
From source file:org.springframework.xd.reactor.MultipleBroadcasterMessageHandler.java
/** * Construct a new SynchronousDispatcherMessageHandler given the reactor based Processor to delegate * processing to.// ww w .j av a2s. co m * * @param processor The stream based reactor processor */ @SuppressWarnings({ "unchecked", "rawtypes" }) public MultipleBroadcasterMessageHandler(Processor processor, String partitionExpression) { Assert.notNull(processor, "processor cannot be null."); Assert.notNull(partitionExpression, "Partition expression can not be null"); this.processor = processor; this.partitionExpression = spelExpressionParser.parseExpression(partitionExpression); environment = Environment.initializeIfEmpty(); // This by default uses SynchronousDispatcher Method method = ReflectionUtils.findMethod(this.processor.getClass(), "process", Stream.class); this.inputType = ResolvableType.forMethodParameter(method, 0).getNested(2); }
From source file:org.springframework.xd.reactor.SynchronousDispatcherMessageHandler.java
/** * Construct a new SynchronousDispatcherMessageHandler given the reactor based Processor to delegate * processing to.// w w w . j a v a 2 s . com * * @param processor The stream based reactor processor */ @SuppressWarnings({ "unchecked", "rawtypes" }) public SynchronousDispatcherMessageHandler(Processor processor) { Assert.notNull(processor, "processor cannot be null."); this.reactorProcessor = processor; Environment.initializeIfEmpty(); // This by default uses SynchronousDispatcher Method method = ReflectionUtils.findMethod(this.reactorProcessor.getClass(), "process", Stream.class); this.inputType = ResolvableType.forMethodParameter(method, 0).getNested(2); //Stream with a SynchronousDispatcher as this handler is called by Message Listener managed threads this.stream = Streams.broadcast(); //user defined stream processing Stream<?> outputStream = processor.process(stream); //Simple log error handling outputStream.when(Throwable.class, new Consumer<Throwable>() { @Override public void accept(Throwable throwable) { logger.error(throwable); } }); this.consume = outputStream.consume(new Consumer<Object>() { @Override public void accept(Object outputObject) { if (ClassUtils.isAssignable(Message.class, outputObject.getClass())) { getOutputChannel().send((Message) outputObject); } else { //TODO handle copy of header values when possible getOutputChannel().send(MessageBuilder.withPayload(outputObject).build()); } //TODO handle Void } }); if (logger.isDebugEnabled()) { logger.debug(consume.debug()); } }
From source file:org.springframework.xd.rxjava.MultipleSubjectMessageHandler.java
@SuppressWarnings({ "unchecked", "rawtypes" })
public MultipleSubjectMessageHandler(Processor processor, String partitionExpression) {
Assert.notNull(processor, "processor cannot be null.");
Assert.notNull(partitionExpression, "Partition expression can not be null");
this.processor = processor;
this.partitionExpression = spelExpressionParser.parseExpression(partitionExpression);
Method method = ReflectionUtils.findMethod(this.processor.getClass(), "process", Observable.class);
this.inputType = ResolvableType.forMethodParameter(method, 0).getNested(2);
}
From source file:org.springframework.xd.rxjava.SubjectMessageHandler.java
@SuppressWarnings({ "unchecked", "rawtypes" })
public SubjectMessageHandler(Processor processor) {
Assert.notNull(processor, "processor cannot be null.");
this.processor = processor;
Method method = ReflectionUtils.findMethod(this.processor.getClass(), "process", Observable.class);
this.inputType = ResolvableType.forMethodParameter(method, 0).getNested(2);
subject = new SerializedSubject(PublishSubject.create());
Observable<?> outputStream = processor.process(subject);
subscription = outputStream.subscribe(new Action1<Object>() {
@Override//from www .j av a 2 s . c o m
public void call(Object outputObject) {
if (ClassUtils.isAssignable(Message.class, outputObject.getClass())) {
getOutputChannel().send((Message) outputObject);
} else {
getOutputChannel().send(MessageBuilder.withPayload(outputObject).build());
}
}
}, new Action1<Throwable>() {
@Override
public void call(Throwable throwable) {
logger.error(throwable);
}
}, new Action0() {
@Override
public void call() {
logger.error("Subscription close for [" + subscription + "]");
}
});
}