renamed ChannelResolver to ChannelMapping
This commit is contained in:
@@ -23,7 +23,7 @@ import org.aopalliance.intercept.MethodInvocation;
|
||||
|
||||
import org.springframework.aop.support.AopUtils;
|
||||
import org.springframework.core.annotation.AnnotationUtils;
|
||||
import org.springframework.integration.channel.ChannelResolver;
|
||||
import org.springframework.integration.channel.ChannelMapping;
|
||||
import org.springframework.integration.channel.MessageChannel;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@@ -39,17 +39,17 @@ public class AnnotationAwareMessagePublishingInterceptor extends MessagePublishi
|
||||
|
||||
private String channelAttributeName;
|
||||
|
||||
private ChannelResolver channelResolver;
|
||||
private ChannelMapping channelMapping;
|
||||
|
||||
|
||||
public AnnotationAwareMessagePublishingInterceptor(Class<? extends Annotation> publisherAnnotationType,
|
||||
String channelAttributeName, ChannelResolver channelResolver) {
|
||||
String channelAttributeName, ChannelMapping channelMapping) {
|
||||
Assert.notNull(publisherAnnotationType, "publisherAnnotationType must not be null");
|
||||
Assert.notNull(channelAttributeName, "channelAttributeName must not be null");
|
||||
Assert.notNull(channelResolver, "channelResolver must not be null");
|
||||
Assert.notNull(channelMapping, "channelMapping must not be null");
|
||||
this.publisherAnnotationType = publisherAnnotationType;
|
||||
this.channelAttributeName = channelAttributeName;
|
||||
this.channelResolver = channelResolver;
|
||||
this.channelMapping = channelMapping;
|
||||
}
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ public class AnnotationAwareMessagePublishingInterceptor extends MessagePublishi
|
||||
if (annotation != null) {
|
||||
String channelName = (String) AnnotationUtils.getValue(annotation, this.channelAttributeName);
|
||||
if (channelName != null) {
|
||||
MessageChannel channel = this.channelResolver.resolve(channelName);
|
||||
MessageChannel channel = this.channelMapping.getChannel(channelName);
|
||||
if (channel != null) {
|
||||
return channel;
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ import org.springframework.aop.Pointcut;
|
||||
import org.springframework.aop.support.AbstractPointcutAdvisor;
|
||||
import org.springframework.aop.support.annotation.AnnotationMatchingPointcut;
|
||||
import org.springframework.integration.annotation.Publisher;
|
||||
import org.springframework.integration.channel.ChannelResolver;
|
||||
import org.springframework.integration.channel.ChannelMapping;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@@ -43,18 +43,18 @@ public class PublisherAnnotationAdvisor extends AbstractPointcutAdvisor {
|
||||
private AnnotationMatchingPointcut pointcut;
|
||||
|
||||
|
||||
public PublisherAnnotationAdvisor(ChannelResolver channelResolver) {
|
||||
this(Publisher.class, "channel", channelResolver);
|
||||
public PublisherAnnotationAdvisor(ChannelMapping channelMapping) {
|
||||
this(Publisher.class, "channel", channelMapping);
|
||||
}
|
||||
|
||||
public PublisherAnnotationAdvisor(Class<? extends Annotation> publisherAnnotationType, String channelNameAttribute,
|
||||
ChannelResolver channelResolver) {
|
||||
ChannelMapping channelMapping) {
|
||||
Assert.notNull(publisherAnnotationType, "publisherAnnotationType must not be null");
|
||||
Assert.notNull(channelNameAttribute, "channelNameAttribute must not be null");
|
||||
Assert.notNull(channelResolver, "channelResolver must not be null");
|
||||
Assert.notNull(channelMapping, "channelMapping must not be null");
|
||||
this.pointcut = AnnotationMatchingPointcut.forMethodAnnotation(publisherAnnotationType);
|
||||
this.advice = new AnnotationAwareMessagePublishingInterceptor(publisherAnnotationType, channelNameAttribute,
|
||||
channelResolver);
|
||||
channelMapping);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.BeanClassLoaderAware;
|
||||
import org.springframework.beans.factory.config.BeanPostProcessor;
|
||||
import org.springframework.integration.annotation.Publisher;
|
||||
import org.springframework.integration.channel.ChannelResolver;
|
||||
import org.springframework.integration.channel.ChannelMapping;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@@ -41,7 +41,7 @@ public class PublisherAnnotationPostProcessor implements BeanPostProcessor, Bean
|
||||
|
||||
private String channelNameAttribute = "channel";
|
||||
|
||||
private ChannelResolver channelResolver;
|
||||
private ChannelMapping channelMapping;
|
||||
|
||||
private Advisor advisor;
|
||||
|
||||
@@ -62,17 +62,17 @@ public class PublisherAnnotationPostProcessor implements BeanPostProcessor, Bean
|
||||
this.channelNameAttribute = channelNameAttribute;
|
||||
}
|
||||
|
||||
public void setChannelResolver(ChannelResolver channelResolver) {
|
||||
Assert.notNull(channelResolver, "channelResolver must not be null");
|
||||
this.channelResolver = channelResolver;
|
||||
public void setChannelMapping(ChannelMapping channelMapping) {
|
||||
Assert.notNull(channelMapping, "channelMapping must not be null");
|
||||
this.channelMapping = channelMapping;
|
||||
}
|
||||
|
||||
private void createAdvisor() {
|
||||
if (this.channelResolver == null) {
|
||||
throw new IllegalStateException("channelResolver is required");
|
||||
if (this.channelMapping == null) {
|
||||
throw new IllegalStateException("channelMapping is required");
|
||||
}
|
||||
this.advisor = new PublisherAnnotationAdvisor(this.publisherAnnotationType, this.channelNameAttribute,
|
||||
this.channelResolver);
|
||||
this.channelMapping);
|
||||
}
|
||||
|
||||
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
|
||||
|
||||
@@ -31,7 +31,7 @@ import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.context.Lifecycle;
|
||||
import org.springframework.integration.MessagingException;
|
||||
import org.springframework.integration.channel.ChannelResolver;
|
||||
import org.springframework.integration.channel.ChannelMapping;
|
||||
import org.springframework.integration.channel.MessageChannel;
|
||||
import org.springframework.integration.channel.PointToPointChannel;
|
||||
import org.springframework.integration.endpoint.MessageEndpoint;
|
||||
@@ -44,7 +44,7 @@ import org.springframework.util.Assert;
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class MessageBus implements ChannelResolver, ApplicationContextAware, Lifecycle {
|
||||
public class MessageBus implements ChannelMapping, ApplicationContextAware, Lifecycle {
|
||||
|
||||
private Log logger = LogFactory.getLog(this.getClass());
|
||||
|
||||
@@ -113,7 +113,7 @@ public class MessageBus implements ChannelResolver, ApplicationContextAware, Lif
|
||||
this.dispatcherExecutor = new ScheduledThreadPoolExecutor(this.dispatcherTasks.size() > 0 ? this.dispatcherTasks.size() : 1);
|
||||
}
|
||||
|
||||
public MessageChannel resolve(String channelName) {
|
||||
public MessageChannel getChannel(String channelName) {
|
||||
return this.channels.get(channelName);
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ public class MessageBus implements ChannelResolver, ApplicationContextAware, Lif
|
||||
|
||||
public void registerEndpoint(String name, MessageEndpoint endpoint) {
|
||||
this.endpoints.put(name, endpoint);
|
||||
endpoint.setChannelResolver(this);
|
||||
endpoint.setChannelMapping(this);
|
||||
}
|
||||
|
||||
public void activateSubscription(Subscription subscription) {
|
||||
|
||||
@@ -21,8 +21,8 @@ package org.springframework.integration.channel;
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public interface ChannelResolver {
|
||||
public interface ChannelMapping {
|
||||
|
||||
MessageChannel resolve(String channelName);
|
||||
MessageChannel getChannel(String channelName);
|
||||
|
||||
}
|
||||
@@ -19,7 +19,7 @@ package org.springframework.integration.endpoint;
|
||||
import org.springframework.integration.MessageHandlingException;
|
||||
import org.springframework.integration.MessagingConfigurationException;
|
||||
import org.springframework.integration.bus.ConsumerPolicy;
|
||||
import org.springframework.integration.channel.ChannelResolver;
|
||||
import org.springframework.integration.channel.ChannelMapping;
|
||||
import org.springframework.integration.channel.MessageChannel;
|
||||
import org.springframework.integration.handler.MessageHandler;
|
||||
import org.springframework.integration.message.Message;
|
||||
@@ -45,7 +45,7 @@ public class GenericMessageEndpoint implements MessageEndpoint {
|
||||
|
||||
private MessageHandler handler;
|
||||
|
||||
private ChannelResolver channelResolver;
|
||||
private ChannelMapping channelMapping;
|
||||
|
||||
private ConsumerPolicy consumerPolicy;
|
||||
|
||||
@@ -87,10 +87,10 @@ public class GenericMessageEndpoint implements MessageEndpoint {
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the channel resolver to use for resolving channels by name.
|
||||
* Set the channel mapping to use for looking up channels by name.
|
||||
*/
|
||||
public void setChannelResolver(ChannelResolver channelResolver) {
|
||||
this.channelResolver = channelResolver;
|
||||
public void setChannelMapping(ChannelMapping channelMapping) {
|
||||
this.channelMapping = channelMapping;
|
||||
}
|
||||
|
||||
|
||||
@@ -100,7 +100,7 @@ public class GenericMessageEndpoint implements MessageEndpoint {
|
||||
throw new MessagingConfigurationException(
|
||||
"endpoint must have either a 'handler' or 'defaultOutputChannelName'");
|
||||
}
|
||||
MessageChannel replyChannel = this.channelResolver.resolve(this.defaultOutputChannelName);
|
||||
MessageChannel replyChannel = this.channelMapping.getChannel(this.defaultOutputChannelName);
|
||||
replyChannel.send(message);
|
||||
return;
|
||||
}
|
||||
@@ -117,14 +117,14 @@ public class GenericMessageEndpoint implements MessageEndpoint {
|
||||
}
|
||||
|
||||
private MessageChannel resolveReplyChannel(Message message) {
|
||||
if (this.channelResolver == null) {
|
||||
if (this.channelMapping == null) {
|
||||
return null;
|
||||
}
|
||||
String replyChannelName = message.getHeader().getReplyChannelName();
|
||||
if (replyChannelName != null && replyChannelName.trim().length() > 0) {
|
||||
return this.channelResolver.resolve(replyChannelName);
|
||||
return this.channelMapping.getChannel(replyChannelName);
|
||||
}
|
||||
return this.channelResolver.resolve(this.defaultOutputChannelName);
|
||||
return this.channelMapping.getChannel(this.defaultOutputChannelName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.springframework.integration.endpoint;
|
||||
|
||||
import org.springframework.integration.channel.ChannelResolver;
|
||||
import org.springframework.integration.channel.ChannelMapping;
|
||||
import org.springframework.integration.message.Message;
|
||||
|
||||
/**
|
||||
@@ -30,7 +30,7 @@ public interface MessageEndpoint {
|
||||
|
||||
void setDefaultOutputChannelName(String defaultOutputChannelName);
|
||||
|
||||
void setChannelResolver(ChannelResolver channelResolver);
|
||||
void setChannelMapping(ChannelMapping channelMapping);
|
||||
|
||||
void messageReceived(Message message);
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ import org.junit.Test;
|
||||
|
||||
import org.springframework.aop.framework.ProxyFactory;
|
||||
import org.springframework.integration.annotation.Publisher;
|
||||
import org.springframework.integration.channel.ChannelResolver;
|
||||
import org.springframework.integration.channel.ChannelMapping;
|
||||
import org.springframework.integration.channel.MessageChannel;
|
||||
import org.springframework.integration.channel.PointToPointChannel;
|
||||
import org.springframework.integration.message.Message;
|
||||
@@ -37,15 +37,15 @@ public class PublisherAnnotationAdvisorTests {
|
||||
@Test
|
||||
public void testPublisherAnnotation() {
|
||||
final MessageChannel channel = new PointToPointChannel();
|
||||
ChannelResolver channelResolver = new ChannelResolver() {
|
||||
public MessageChannel resolve(String channelName) {
|
||||
ChannelMapping channelMapping = new ChannelMapping() {
|
||||
public MessageChannel getChannel(String channelName) {
|
||||
if (channelName.equals("testChannel")) {
|
||||
return channel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
};
|
||||
PublisherAnnotationAdvisor advisor = new PublisherAnnotationAdvisor(channelResolver);
|
||||
PublisherAnnotationAdvisor advisor = new PublisherAnnotationAdvisor(channelMapping);
|
||||
TestService proxy = (TestService) this.createProxy(new TestServiceImpl("hello world"), advisor);
|
||||
proxy.publisherTest();
|
||||
Message message = channel.receive(0);
|
||||
@@ -56,15 +56,15 @@ public class PublisherAnnotationAdvisorTests {
|
||||
@Test
|
||||
public void testNoPublisherAnnotation() {
|
||||
final MessageChannel channel = new PointToPointChannel();
|
||||
ChannelResolver channelResolver = new ChannelResolver() {
|
||||
public MessageChannel resolve(String channelName) {
|
||||
ChannelMapping channelMapping = new ChannelMapping() {
|
||||
public MessageChannel getChannel(String channelName) {
|
||||
if (channelName.equals("testChannel")) {
|
||||
return channel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
};
|
||||
PublisherAnnotationAdvisor advisor = new PublisherAnnotationAdvisor(channelResolver);
|
||||
PublisherAnnotationAdvisor advisor = new PublisherAnnotationAdvisor(channelMapping);
|
||||
TestService proxy = (TestService) this.createProxy(new TestServiceImpl("hello world"), advisor);
|
||||
proxy.noPublisherTest();
|
||||
Message message = channel.receive(0);
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
<bean id="testBean" class="org.springframework.integration.aop.PublisherAnnotationTestBean"/>
|
||||
|
||||
<bean class="org.springframework.integration.aop.PublisherAnnotationPostProcessor">
|
||||
<property name="channelResolver" ref="messageBus"/>
|
||||
<property name="channelMapping" ref="messageBus"/>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
|
||||
@@ -24,7 +24,6 @@ import org.junit.Test;
|
||||
import org.springframework.integration.bus.ConsumerPolicy;
|
||||
import org.springframework.integration.bus.MessageBus;
|
||||
import org.springframework.integration.bus.Subscription;
|
||||
import org.springframework.integration.channel.ChannelResolver;
|
||||
import org.springframework.integration.channel.MessageChannel;
|
||||
import org.springframework.integration.channel.PointToPointChannel;
|
||||
import org.springframework.integration.handler.MessageHandler;
|
||||
@@ -77,18 +76,9 @@ public class GenericMessageEndpointTests {
|
||||
return new DocumentMessage("123", "hello " + message.getPayload());
|
||||
}
|
||||
};
|
||||
ChannelResolver channelResolver = new ChannelResolver() {
|
||||
public MessageChannel resolve(String channelName) {
|
||||
if (channelName.equals("replyChannel")) {
|
||||
return replyChannel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
};
|
||||
GenericMessageEndpoint endpoint = new GenericMessageEndpoint();
|
||||
endpoint.setInputChannelName("testChannel");
|
||||
endpoint.setHandler(handler);
|
||||
endpoint.setChannelResolver(channelResolver);
|
||||
MessageBus bus = new MessageBus();
|
||||
bus.registerChannel("testChannel", channel);
|
||||
bus.registerEndpoint("testEndpoint", endpoint);
|
||||
|
||||
Reference in New Issue
Block a user