Fixes INT-24 (resequencer) by adding a <resequencer/> namespace element.

This commit is contained in:
Marius Bogoevici
2008-06-04 02:34:14 +00:00
parent bfabc1a14b
commit 0f64b81180
7 changed files with 280 additions and 18 deletions

View File

@@ -34,6 +34,7 @@ import org.springframework.integration.channel.config.RendezvousChannelParser;
import org.springframework.integration.channel.config.ThreadLocalChannelParser;
import org.springframework.integration.config.annotation.AnnotationDrivenParser;
import org.springframework.integration.gateway.config.GatewayParser;
import org.springframework.integration.router.config.ResequencerParser;
import org.springframework.integration.router.config.RouterParser;
import org.springframework.integration.router.config.SplitterParser;
import org.springframework.util.ClassUtils;
@@ -72,6 +73,7 @@ public class IntegrationNamespaceHandler extends NamespaceHandlerSupport {
registerBeanDefinitionParser("router", new RouterParser());
registerBeanDefinitionParser("splitter", new SplitterParser());
registerBeanDefinitionParser("aggregator", new AggregatorParser());
registerBeanDefinitionParser("resequencer", new ResequencerParser());
Map<String, Class<? extends BeanDefinitionParser>> parserMappings = this.loadAdapterParserMappings();
try {
for (Map.Entry<String, Class<? extends BeanDefinitionParser>> entry : parserMappings.entrySet()) {

View File

@@ -343,6 +343,28 @@
</xsd:complexContent>
</xsd:complexType>
</xsd:element>
<xsd:element name="resequencer">
<xsd:complexType>
<xsd:annotation>
<xsd:documentation>
Defines a resequencing message handler.
</xsd:documentation>
</xsd:annotation>
<xsd:complexContent>
<xsd:extension base="beans:identifiedType">
<xsd:attribute name="default-reply-channel" type="xsd:string" use="optional"/>
<xsd:attribute name="discard-channel" type="xsd:string" use="optional"/>
<xsd:attribute name="send-timeout" type="xsd:long" use="optional"/>
<xsd:attribute name="release-partial-sequences" type="xsd:boolean" use="optional"></xsd:attribute>
<xsd:attribute name="send-partial-result-on-timeout" type="xsd:boolean" use="optional"/>
<xsd:attribute name="tracked-correlation-id-capacity" type="xsd:int" use="optional"/>
<xsd:attribute name="reaper-interval" type="xsd:long" use="optional"/>
<xsd:attribute name="timeout" type="xsd:long" use="optional"/>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
</xsd:element>
<xsd:element name="completion-strategy">
<xsd:complexType>

View File

@@ -38,14 +38,18 @@ import org.springframework.integration.message.Message;
*/
public class ResequencingMessageHandler extends AbstractMessageBarrierHandler{
private boolean releasePartialSequences;
private volatile boolean releasePartialSequences = true;
public ResequencingMessageHandler(boolean releasePartialSequences) {
this(null, releasePartialSequences);
public ResequencingMessageHandler() {
this(null);
}
public ResequencingMessageHandler(ScheduledExecutorService executor, boolean releasePartialSequences) {
public ResequencingMessageHandler(ScheduledExecutorService executor) {
super(executor);
}
public void setReleasePartialSequences(boolean releasePartialSequences) {
this.releasePartialSequences = releasePartialSequences;
}
@@ -61,4 +65,5 @@ public class ResequencingMessageHandler extends AbstractMessageBarrierHandler{
return (releasedMessages.get(releasedMessages.size() - 1).getHeader().getSequenceNumber() ==
releasedMessages.get(releasedMessages.size() - 1).getHeader().getSequenceSize());
}
}

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.router.config;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser;
import org.springframework.integration.router.ResequencingMessageHandler;
import org.springframework.util.StringUtils;
import org.w3c.dom.Element;
/**
* Parser for the &gt;resequencer&lt; tag.
* @author Marius Bogoevici
*/
public class ResequencerParser extends AbstractSimpleBeanDefinitionParser {
public static final String DEFAULT_REPLY_CHANNEL_ATTRIBUTE = "default-reply-channel";
public static final String DISCARD_CHANNEL_ATTRIBUTE = "discard-channel";
private static final String DEFAULT_REPLY_CHANNEL_PROPERTY = "defaultReplyChannel";
private static final String DISCARD_CHANNEL_PROPERTY = "discardChannel";
@Override
protected Class<?> getBeanClass(Element element) {
return ResequencingMessageHandler.class;
}
@Override
protected boolean isEligibleAttribute(String attributeName) {
// TODO Auto-generated method stub
return !DEFAULT_REPLY_CHANNEL_ATTRIBUTE.equals(attributeName)
&& !DISCARD_CHANNEL_ATTRIBUTE.equals(attributeName) && super.isEligibleAttribute(attributeName);
}
@Override
protected void postProcess(BeanDefinitionBuilder beanDefinition, Element element) {
if (StringUtils.hasText(element.getAttribute(DEFAULT_REPLY_CHANNEL_ATTRIBUTE))) {
beanDefinition.addPropertyReference(DEFAULT_REPLY_CHANNEL_PROPERTY, element
.getAttribute(DEFAULT_REPLY_CHANNEL_ATTRIBUTE));
}
if (StringUtils.hasText(element.getAttribute(DISCARD_CHANNEL_ATTRIBUTE))) {
beanDefinition.addPropertyReference(DISCARD_CHANNEL_PROPERTY, element
.getAttribute(DISCARD_CHANNEL_ATTRIBUTE));
}
}
}