MethodInvokingSource and MethodInvokingTarget both accept a 'method' parameter, so that when the actual Method is known (e.g. annotation-driven post-processing), it can be set directly. The 'methodName' is still supported, because it is necessary for XML-based configuration (INT-334).
This commit is contained in:
@@ -45,7 +45,7 @@ public class PollableAnnotationPostProcessor extends AbstractAnnotationMethodPos
|
||||
protected MessageSource<?> processMethod(Object bean, Method method, Annotation annotation) {
|
||||
MethodInvokingSource source = new MethodInvokingSource();
|
||||
source.setObject(bean);
|
||||
source.setMethodName(method.getName());
|
||||
source.setMethod(method);
|
||||
ChannelAdapter channelAdapterAnnotation = AnnotationUtils.findAnnotation(bean.getClass(), ChannelAdapter.class);
|
||||
if (channelAdapterAnnotation != null) {
|
||||
String channelName = channelAdapterAnnotation.value();
|
||||
|
||||
@@ -44,7 +44,7 @@ public class TargetAnnotationPostProcessor extends AbstractAnnotationMethodPostP
|
||||
protected MessageTarget processMethod(Object bean, Method method, Annotation annotation) {
|
||||
MethodInvokingTarget target = new MethodInvokingTarget();
|
||||
target.setObject(bean);
|
||||
target.setMethodName(method.getName());
|
||||
target.setMethod(method);
|
||||
ChannelAdapter channelAdapterAnnotation = AnnotationUtils.findAnnotation(bean.getClass(), ChannelAdapter.class);
|
||||
if (channelAdapterAnnotation != null) {
|
||||
String channelName = channelAdapterAnnotation.value();
|
||||
|
||||
@@ -21,6 +21,8 @@ import java.lang.reflect.Method;
|
||||
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.integration.ConfigurationException;
|
||||
import org.springframework.integration.util.DefaultMethodInvoker;
|
||||
import org.springframework.integration.util.MethodInvoker;
|
||||
import org.springframework.integration.util.MethodValidator;
|
||||
import org.springframework.integration.util.NameResolvingMethodInvoker;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -33,11 +35,13 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
public class MethodInvokingSource implements PollableSource<Object>, InitializingBean {
|
||||
|
||||
private Object object;
|
||||
private volatile Object object;
|
||||
|
||||
private String methodName;
|
||||
private volatile Method method;
|
||||
|
||||
private NameResolvingMethodInvoker invoker;
|
||||
private volatile String methodName;
|
||||
|
||||
private volatile MethodInvoker invoker;
|
||||
|
||||
|
||||
public void setObject(Object object) {
|
||||
@@ -45,14 +49,29 @@ public class MethodInvokingSource implements PollableSource<Object>, Initializin
|
||||
this.object = object;
|
||||
}
|
||||
|
||||
public void setMethod(Method method) {
|
||||
Assert.notNull(method, "'method' must not be null");
|
||||
this.method = method;
|
||||
this.methodName = method.getName();
|
||||
}
|
||||
|
||||
public void setMethodName(String methodName) {
|
||||
Assert.notNull(methodName, "'methodName' must not be null");
|
||||
this.methodName = methodName;
|
||||
}
|
||||
|
||||
public void afterPropertiesSet() {
|
||||
this.invoker = new NameResolvingMethodInvoker(this.object, this.methodName);
|
||||
this.invoker.setMethodValidator(new MessageReceivingMethodValidator());
|
||||
if (this.method != null) {
|
||||
this.invoker = new DefaultMethodInvoker(this.object, this.method);
|
||||
}
|
||||
else if (this.methodName != null) {
|
||||
NameResolvingMethodInvoker nrmi = new NameResolvingMethodInvoker(this.object, this.methodName);
|
||||
nrmi.setMethodValidator(new MessageReceivingMethodValidator());
|
||||
this.invoker = nrmi;
|
||||
}
|
||||
else {
|
||||
throw new ConfigurationException("either 'method' or 'methodName' is required");
|
||||
}
|
||||
}
|
||||
|
||||
public Message<Object> receive() {
|
||||
|
||||
Reference in New Issue
Block a user