OPEN - issue INT-634: Allow queue customization

http://jira.springframework.org/browse/INT-634

Added ref attribute to <queue/> and implemented parser logic for it
This commit is contained in:
Iwein Fuld
2009-06-07 11:49:25 +00:00
parent 84481c892a
commit b49fc7c11e
6 changed files with 123 additions and 15 deletions

View File

@@ -44,6 +44,7 @@ public class PointToPointChannelParser extends AbstractChannelParser {
if ((queueElement = DomUtils.getChildElementByTagName(element, "queue")) != null) {
builder = BeanDefinitionBuilder.genericBeanDefinition(CHANNEL_PACKAGE + ".QueueChannel");
this.parseQueueCapacity(builder, queueElement);
this.parseQueueRef(builder, queueElement);
}
else if ((queueElement = DomUtils.getChildElementByTagName(element, "priority-queue")) != null) {
builder = BeanDefinitionBuilder.genericBeanDefinition(CHANNEL_PACKAGE + ".PriorityChannel");
@@ -63,6 +64,7 @@ public class PointToPointChannelParser extends AbstractChannelParser {
return builder;
}
private void parseDispatcher(String dispatcherAttribute, BeanDefinitionBuilder builder, ParserContext parserContext) {
if (dispatcherAttribute != null) {
if (dispatcherAttribute.equals("failover")) {
@@ -83,4 +85,10 @@ public class PointToPointChannelParser extends AbstractChannelParser {
}
}
private void parseQueueRef(BeanDefinitionBuilder builder, Element queueElement) {
String queueRef = queueElement.getAttribute("ref");
if (StringUtils.hasText(queueRef)){
builder.addConstructorArgReference(queueRef);
}
}
}

View File

@@ -81,9 +81,21 @@
Defines a queue for messages. If 'capacity' is
specified, it will be a
bounded queue.
A custom Queue implementation can be
injected using the 'ref' attribute.
</xsd:documentation>
</xsd:annotation>
<xsd:attribute name="capacity" type="xsd:string" />
<xsd:attribute name="ref" type="xsd:string">
<xsd:annotation>
<xsd:appinfo>
<tool:annotation kind="ref">
<tool:expected-type type="java.util.concurrent.BlockingQueue" />
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
</xsd:complexType>
<xsd:complexType name="priorityQueueType">
@@ -110,8 +122,8 @@
<xsd:element name="publish-subscribe-channel">
<xsd:annotation>
<xsd:documentation>
Defines a Publish-Subscribe channel that
broadcasts messages to its subscribers.
Defines a Publish-Subscribe channel that
broadcasts messages to its subscribers.
</xsd:documentation>
<xsd:appinfo>
<tool:annotation>
@@ -155,8 +167,9 @@
<xsd:element name="thread-local-channel">
<xsd:annotation>
<xsd:documentation>
Defines a channel that maintains its Messages
on a thread-bound queue.
Defines a channel that maintains its Messages
on a
thread-bound queue.
</xsd:documentation>
<xsd:appinfo>
<tool:annotation>
@@ -188,8 +201,10 @@
<xsd:simpleType>
<xsd:annotation>
<xsd:documentation>
Defines a dispatching strategy for the channel. The default is a round
robin load balancer. In case of a publish subscribe channel this
Defines a dispatching strategy for the channel.
The default is a round
robin load balancer. In case of a publish
subscribe channel this
attribute will be ignored.
</xsd:documentation>
</xsd:annotation>
@@ -453,12 +468,13 @@
<xsd:complexType>
<xsd:complexContent>
<xsd:extension base="inputEndpointType">
<xsd:attribute name="output-channel" type="xsd:string" use="required">
<xsd:attribute name="output-channel" type="xsd:string"
use="required">
<xsd:annotation>
<xsd:appinfo>
<tool:annotation kind="ref">
<tool:expected-type
type="org.springframework.integration.core.MessageChannel" />
type="org.springframework.integration.core.MessageChannel" />
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
@@ -807,7 +823,7 @@
<xsd:complexType>
<xsd:complexContent>
<xsd:extension base="handlerEndpointType">
<xsd:attribute name="discard-channel" type="xsd:string"/>
<xsd:attribute name="discard-channel" type="xsd:string" />
<xsd:attribute name="throw-exception-on-rejection"
type="xsd:string" default="false" />
</xsd:extension>

View File

@@ -17,8 +17,6 @@ package org.springframework.integration.aggregator;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.awt.Button;
import java.io.Serializable;
@@ -29,9 +27,11 @@ import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.springframework.integration.core.Message;
import org.springframework.integration.message.MessageBuilder;
/**
* @author Alex Peters
* @author Iwein Fuld
*
*/
public class DefaultMessageAggregatorTests {
@@ -44,14 +44,12 @@ public class DefaultMessageAggregatorTests {
}
@SuppressWarnings("unchecked")
@Test
@Test(timeout=1000)
public void aggregateMessages_withMultiplePayloads_allAsListInResultMsg() {
List<Serializable> anyPayloads = Arrays.asList("foo", "bar", 123L, new Button());
List<Message<?>> messageGroup = new ArrayList<Message<?>>(anyPayloads.size());
for (Serializable payload : anyPayloads) {
Message<Serializable> mock = mock(Message.class);
when(mock.getPayload()).thenReturn(payload);
messageGroup.add(mock);
messageGroup.add(MessageBuilder.withPayload(payload).build());
}
Message<?> result = aggregator.aggregateMessages(messageGroup);
assertThat((List<Serializable>) result.getPayload(), is(anyPayloads));

View File

@@ -48,6 +48,8 @@ import org.springframework.integration.util.ErrorHandlingTaskExecutor;
/**
* @author Mark Fisher
* @author Iwein Fuld
*
* @see ChannelWithCustomQueueParserTests
*/
public class ChannelParserTests {

View File

@@ -0,0 +1,19 @@
<?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" xmlns:beans="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration-1.0.xsd">
<channel id="customQueueChannel">
<queue ref="queue" />
</channel>
<beans:bean id="queue" class="java.util.concurrent.ArrayBlockingQueue">
<beans:constructor-arg value="2" />
</beans:bean>
</beans:beans>

View File

@@ -0,0 +1,65 @@
/*
* Copyright 2002-2008 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.channel.config;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.hamcrest.CoreMatchers.*;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* Testcases for detailed namespace support for &lt;queue/> element under
* &lt;channel/>
*
* @author Iwein Fuld
*
* @see ChannelWithCustomQueueParserTests
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
public class ChannelWithCustomQueueParserTests {
@Qualifier("customQueueChannel")
@Autowired
QueueChannel customQueueChannel;
@Test
public void parseConfig() throws Exception {
assertNotNull(customQueueChannel);
}
@Test
public void queueTypeSet() throws Exception {
DirectFieldAccessor accessor = new DirectFieldAccessor(customQueueChannel);
Object queue = accessor.getPropertyValue("queue");
assertNotNull(queue);
assertThat(queue, is(ArrayBlockingQueue.class));
assertThat(((BlockingQueue<?>)queue).remainingCapacity(), is(2));
}
}