|
|
|
|
@@ -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;
|
|
|
|
|
|