Fix some ChannelName Late Resolution

Polishing
This commit is contained in:
Artem Bilan
2014-09-17 15:21:16 +03:00
parent 87745d43a1
commit db05476acf
4 changed files with 49 additions and 18 deletions

View File

@@ -24,7 +24,7 @@ compileTestJava {
}
ext {
activeMqVersion = '5.9.0'
activeMqVersion = '5.10.0'
apacheSshdVersion = '0.10.1'
embedMongoVersion = '1.46.0'
ftpServerVersion = '1.0.6'

View File

@@ -34,7 +34,7 @@ def customizePom(pom, gradleProject) {
url = linkHomepage
organization {
name = 'SpringIO'
url = 'https://spring.io'
url = 'http://spring.io'
}
licenses {
license {
@@ -59,19 +59,19 @@ def customizePom(pom, gradleProject) {
developer {
id = 'markfisher'
name = 'Mark Fisher'
email = 'mfisher@gopivotal.com'
email = 'mfisher@pivotal.io'
roles = ["project founder and lead emeritus"]
}
developer {
id = 'garyrussell'
name = 'Gary Russell'
email = 'grussell@gopivotal.com'
email = 'grussell@pivotal.io'
roles = ["project lead"]
}
developer {
id = 'abilan'
name = 'Artem Bilan'
email = 'abilan@gopivotal.com'
email = 'abilan@pivotal.io'
roles = ["project lead"]
}
}

View File

@@ -23,6 +23,7 @@ import java.util.Map;
import org.springframework.beans.BeansException;
import org.springframework.integration.core.MessageSelector;
import org.springframework.integration.dsl.support.MessageChannelReference;
import org.springframework.integration.filter.ExpressionEvaluatingSelector;
import org.springframework.integration.router.RecipientListRouter;
import org.springframework.messaging.MessageChannel;
@@ -69,21 +70,45 @@ class DslRecipientListRouter extends RecipientListRouter {
List<Recipient> recipients = new ArrayList<Recipient>(this.selectorRecipientMap.size());
for (Map.Entry<String, MessageSelector> entry : selectorRecipientMap.entrySet()) {
recipients.add(new Recipient(this.resolveChannelName(entry.getKey()), entry.getValue()));
recipients.add(new DslRecipient(new MessageChannelReference(entry.getKey()), entry.getValue()));
}
this.setRecipients(recipients);
super.onInit();
}
private MessageChannel resolveChannelName(String channelName) {
try {
return this.getBeanFactory().getBean(channelName, MessageChannel.class);
class DslRecipient extends Recipient {
private volatile MessageChannel channel;
DslRecipient(MessageChannelReference channel, MessageSelector selector) {
super(channel, selector);
}
catch (BeansException e) {
throw new DestinationResolutionException("Failed to look up MessageChannel with name '"
+ channelName + "' in the BeanFactory.");
@Override
public MessageChannel getChannel() {
if (this.channel == null) {
synchronized (this) {
if (this.channel == null) {
this.channel = resolveChannelName((MessageChannelReference) super.getChannel());
}
}
}
return this.channel;
}
private MessageChannel resolveChannelName(MessageChannelReference channelReference) {
String channelName = channelReference.getName();
try {
return DslRecipientListRouter.this.getBeanFactory().getBean(channelName, MessageChannel.class);
}
catch (BeansException e) {
throw new DestinationResolutionException("Failed to look up MessageChannel with name '"
+ channelName + "' in the BeanFactory.");
}
}
}
}

View File

@@ -79,7 +79,18 @@ class GatewayMessageHandler extends AbstractReplyProducingMessageHandler {
}
@Override
protected void doInit() {
protected Object handleRequestMessage(Message<?> requestMessage) {
if (this.exchanger == null) {
synchronized (this) {
if (this.exchanger == null) {
initialize();
}
}
}
return this.exchanger.exchange(requestMessage);
}
private void initialize() {
BeanFactory beanFactory = getBeanFactory();
if (StringUtils.hasText(this.requestChannel)) {
@@ -108,9 +119,4 @@ class GatewayMessageHandler extends AbstractReplyProducingMessageHandler {
}
}
@Override
protected Object handleRequestMessage(Message<?> requestMessage) {
return exchanger.exchange(requestMessage);
}
}