Merge pull request #258 from olegz/INT-2319-v2

This commit is contained in:
Mark Fisher
2011-12-20 14:11:29 -05:00
4 changed files with 30 additions and 24 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2009 the original author or authors.
* Copyright 2002-2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,11 +18,19 @@ package org.springframework.integration.config.xml;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.w3c.dom.Element;
import org.springframework.beans.factory.config.TypedStringValue;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.integration.channel.DirectChannel;
import org.springframework.integration.channel.ExecutorChannel;
import org.springframework.integration.channel.PriorityChannel;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.integration.channel.RendezvousChannel;
import org.springframework.integration.store.MessageGroupQueue;
import org.springframework.util.StringUtils;
import org.springframework.util.xml.DomUtils;
import org.w3c.dom.Element;
/**
* Parser for the <channel> element.
@@ -33,12 +41,6 @@ import org.w3c.dom.Element;
*/
public class PointToPointChannelParser extends AbstractChannelParser {
private static final String CHANNEL_PACKAGE = IntegrationNamespaceUtils.BASE_PACKAGE + ".channel";
//private static final String DISPATCHER_PACKAGE = IntegrationNamespaceUtils.BASE_PACKAGE + ".dispatcher";
private static final String STORE_PACKAGE = IntegrationNamespaceUtils.BASE_PACKAGE + ".store";
private final Log logger = LogFactory.getLog(this.getClass());
@Override
@@ -48,7 +50,7 @@ public class PointToPointChannelParser extends AbstractChannelParser {
// configure a queue-based channel if any queue sub-element is defined
if ((queueElement = DomUtils.getChildElementByTagName(element, "queue")) != null) {
builder = BeanDefinitionBuilder.genericBeanDefinition(CHANNEL_PACKAGE + ".QueueChannel");
builder = BeanDefinitionBuilder.genericBeanDefinition(QueueChannel.class);
boolean hasStoreRef = this.parseStoreRef(builder, queueElement, element.getAttribute(ID_ATTRIBUTE));
boolean hasQueueRef = this.parseQueueRef(builder, queueElement);
if (!hasStoreRef) {
@@ -66,7 +68,7 @@ public class PointToPointChannelParser extends AbstractChannelParser {
}
}
else if ((queueElement = DomUtils.getChildElementByTagName(element, "priority-queue")) != null) {
builder = BeanDefinitionBuilder.genericBeanDefinition(CHANNEL_PACKAGE + ".PriorityChannel");
builder = BeanDefinitionBuilder.genericBeanDefinition(PriorityChannel.class);
this.parseQueueCapacity(builder, queueElement);
String comparatorRef = queueElement.getAttribute("comparator");
if (StringUtils.hasText(comparatorRef)) {
@@ -74,7 +76,7 @@ public class PointToPointChannelParser extends AbstractChannelParser {
}
}
else if ((queueElement = DomUtils.getChildElementByTagName(element, "rendezvous-queue")) != null) {
builder = BeanDefinitionBuilder.genericBeanDefinition(CHANNEL_PACKAGE + ".RendezvousChannel");
builder = BeanDefinitionBuilder.genericBeanDefinition(RendezvousChannel.class);
}
Element dispatcherElement = DomUtils.getChildElementByTagName(element, "dispatcher");
@@ -110,7 +112,7 @@ public class PointToPointChannelParser extends AbstractChannelParser {
if (hasDispatcherAttribute) {
// this attribute is deprecated, but if set, we need to create a DirectChannel
// without any LoadBalancerStrategy and the failover flag set to true (default).
builder = BeanDefinitionBuilder.genericBeanDefinition(CHANNEL_PACKAGE + ".DirectChannel");
builder = BeanDefinitionBuilder.genericBeanDefinition(DirectChannel.class);
if ("failover".equals(dispatcherAttribute)) {
// round-robin dispatcher is used by default, the "failover" value simply disables it
builder.addConstructorArgValue(null);
@@ -118,17 +120,17 @@ public class PointToPointChannelParser extends AbstractChannelParser {
}
else if (dispatcherElement == null) {
// configure the default DirectChannel with a RoundRobinLoadBalancingStrategy
builder = BeanDefinitionBuilder.genericBeanDefinition(CHANNEL_PACKAGE + ".DirectChannel");
builder = BeanDefinitionBuilder.genericBeanDefinition(DirectChannel.class);
}
else {
// configure either an ExecutorChannel or DirectChannel based on existence of 'task-executor'
String taskExecutor = dispatcherElement.getAttribute("task-executor");
if (StringUtils.hasText(taskExecutor)) {
builder = BeanDefinitionBuilder.genericBeanDefinition(CHANNEL_PACKAGE + ".ExecutorChannel");
builder = BeanDefinitionBuilder.genericBeanDefinition(ExecutorChannel.class);
builder.addConstructorArgReference(taskExecutor);
}
else {
builder = BeanDefinitionBuilder.genericBeanDefinition(CHANNEL_PACKAGE + ".DirectChannel");
builder = BeanDefinitionBuilder.genericBeanDefinition(DirectChannel.class);
}
// unless the 'load-balancer' attribute is explicitly set to 'none',
// configure the default RoundRobinLoadBalancingStrategy
@@ -163,9 +165,9 @@ public class PointToPointChannelParser extends AbstractChannelParser {
String storeRef = queueElement.getAttribute("message-store");
if (StringUtils.hasText(storeRef)) {
BeanDefinitionBuilder queueBuilder = BeanDefinitionBuilder
.genericBeanDefinition(STORE_PACKAGE + ".MessageGroupQueue");
.genericBeanDefinition(MessageGroupQueue.class);
queueBuilder.addConstructorArgReference(storeRef);
queueBuilder.addConstructorArgValue(STORE_PACKAGE + ":" + channel);
queueBuilder.addConstructorArgValue(new TypedStringValue(storeRef).getValue() + ":" + channel);
parseQueueCapacity(queueBuilder, queueElement);
builder.addConstructorArgValue(queueBuilder.getBeanDefinition());
return true;

View File

@@ -1,13 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/integration" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<beans:beans xmlns="http://www.springframework.org/schema/integration"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration.xsd">
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:property-placeholder location="classpath:org/springframework/integration/config/ms.properties"/>
<channel id="output">
<queue capacity="5" message-store="messageStore" />
<queue capacity="5" message-store="${ms}" />
</channel>
<channel id="input" />

View File

@@ -64,7 +64,7 @@ public class ChannelWithMessageStoreParserTests {
handler.getLatch().await(100, TimeUnit.MILLISECONDS);
assertEquals("The message payload is not correct", "123", handler.getMessageString());
// The group id for buffered messages is the channel name
assertEquals(1, messageGroupStore.getMessageGroup(BASE_PACKAGE+".store:output").size());
assertEquals(1, messageGroupStore.getMessageGroup("messageStore:output").size());
Message<?> result = output.receive(100);
assertEquals("hello", result.getPayload());