INT-3512: Add <advice-chain> to the Aggregator
JIRA: https://jira.spring.io/browse/INT-3512 INT-3512: Fix typos INT-3512: add `expire-` prefix to the advice sub-elements INT-3512: Mark `AggregatorWithCustomReleaseStrategyTests` as `LONG_RUNNING_TEST` Doc Polishing
This commit is contained in:
committed by
Gary Russell
parent
113716effd
commit
d5f1bb6516
@@ -24,9 +24,11 @@ import java.util.UUID;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
|
||||
import org.aopalliance.aop.Advice;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.aop.framework.ProxyFactory;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.BeanFactoryAware;
|
||||
@@ -116,6 +118,10 @@ public abstract class AbstractCorrelatingMessageHandler extends AbstractMessageP
|
||||
|
||||
private volatile Expression groupTimeoutExpression;
|
||||
|
||||
private volatile List<Advice> forceReleaseAdviceChain;
|
||||
|
||||
private MessageGroupProcessor forceReleaseProcessor = new ForceReleaseMessageGroupProcessor();
|
||||
|
||||
private EvaluationContext evaluationContext;
|
||||
|
||||
private volatile ApplicationEventPublisher applicationEventPublisher;
|
||||
@@ -157,7 +163,7 @@ public abstract class AbstractCorrelatingMessageHandler extends AbstractMessageP
|
||||
store.registerMessageGroupExpiryCallback(new MessageGroupCallback() {
|
||||
@Override
|
||||
public void execute(MessageGroupStore messageGroupStore, MessageGroup group) {
|
||||
forceComplete(group);
|
||||
forceReleaseProcessor.processMessageGroup(group);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -177,6 +183,11 @@ public abstract class AbstractCorrelatingMessageHandler extends AbstractMessageP
|
||||
this.groupTimeoutExpression = groupTimeoutExpression;
|
||||
}
|
||||
|
||||
public void setForceReleaseAdviceChain(List<Advice> forceReleaseAdviceChain) {
|
||||
Assert.notNull(forceReleaseAdviceChain, "forceReleaseAdviceChain must not be null");
|
||||
this.forceReleaseAdviceChain = forceReleaseAdviceChain;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setIntegrationEvaluationContext(EvaluationContext evaluationContext) {
|
||||
this.evaluationContext = evaluationContext;
|
||||
@@ -226,6 +237,20 @@ public abstract class AbstractCorrelatingMessageHandler extends AbstractMessageP
|
||||
* (checked in the setter).
|
||||
*/
|
||||
this.lockRegistrySet = true;
|
||||
this.forceReleaseProcessor = createGroupTimeoutProcessor();
|
||||
}
|
||||
|
||||
private MessageGroupProcessor createGroupTimeoutProcessor() {
|
||||
MessageGroupProcessor processor = new ForceReleaseMessageGroupProcessor();
|
||||
|
||||
if (this.groupTimeoutExpression != null && !CollectionUtils.isEmpty(this.forceReleaseAdviceChain)) {
|
||||
ProxyFactory proxyFactory = new ProxyFactory(processor);
|
||||
for (Advice advice : this.forceReleaseAdviceChain) {
|
||||
proxyFactory.addAdvice(advice);
|
||||
}
|
||||
return (MessageGroupProcessor) proxyFactory.getProxy(getApplicationContext().getClassLoader());
|
||||
}
|
||||
return processor;
|
||||
}
|
||||
|
||||
public void setDiscardChannel(MessageChannel discardChannel) {
|
||||
@@ -409,7 +434,7 @@ public abstract class AbstractCorrelatingMessageHandler extends AbstractMessageP
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
AbstractCorrelatingMessageHandler.this.forceComplete(messageGroup);
|
||||
forceReleaseProcessor.processMessageGroup(messageGroup);
|
||||
}
|
||||
catch (MessageDeliveryException e) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
@@ -427,7 +452,7 @@ public abstract class AbstractCorrelatingMessageHandler extends AbstractMessageP
|
||||
this.expireGroupScheduledFutures.put(UUIDConverter.getUUID(messageGroup.getGroupId()), scheduledFuture);
|
||||
}
|
||||
else {
|
||||
forceComplete(messageGroup);
|
||||
this.forceReleaseProcessor.processMessageGroup(messageGroup);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -735,4 +760,14 @@ public abstract class AbstractCorrelatingMessageHandler extends AbstractMessageP
|
||||
|
||||
}
|
||||
|
||||
private class ForceReleaseMessageGroupProcessor implements MessageGroupProcessor {
|
||||
|
||||
@Override
|
||||
public Object processMessageGroup(MessageGroup group) {
|
||||
forceComplete(group);
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.integration.aggregator.AbstractCorrelatingMessageHandler;
|
||||
import org.springframework.integration.config.IntegrationConfigUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.util.xml.DomUtils;
|
||||
|
||||
/**
|
||||
* Base class for parsers that create an instance of {@link AbstractCorrelatingMessageHandler}
|
||||
@@ -58,7 +59,8 @@ public abstract class AbstractCorrelatingMessageHandlerParser extends AbstractCo
|
||||
|
||||
private static final String SEND_PARTIAL_RESULT_ON_EXPIRY_ATTRIBUTE = "send-partial-result-on-expiry";
|
||||
|
||||
protected void doParse(BeanDefinitionBuilder builder, Element element, BeanMetadataElement processor, ParserContext parserContext){
|
||||
protected void doParse(BeanDefinitionBuilder builder, Element element, BeanMetadataElement processor,
|
||||
ParserContext parserContext) {
|
||||
this.injectPropertyWithAdapter(CORRELATION_STRATEGY_REF_ATTRIBUTE, CORRELATION_STRATEGY_METHOD_ATTRIBUTE,
|
||||
CORRELATION_STRATEGY_EXPRESSION_ATTRIBUTE, CORRELATION_STRATEGY_PROPERTY, "CorrelationStrategy",
|
||||
element, builder, processor, parserContext);
|
||||
@@ -72,12 +74,19 @@ public abstract class AbstractCorrelatingMessageHandlerParser extends AbstractCo
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "lock-registry");
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, SEND_TIMEOUT_ATTRIBUTE);
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, SEND_PARTIAL_RESULT_ON_EXPIRY_ATTRIBUTE);
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "empty-group-min-timeout", "minimumTimeoutForEmptyGroups");
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "empty-group-min-timeout",
|
||||
"minimumTimeoutForEmptyGroups");
|
||||
|
||||
BeanDefinition expressionDef =
|
||||
IntegrationNamespaceUtils.createExpressionDefinitionFromValueOrExpression("group-timeout", "group-timeout-expression",
|
||||
parserContext, element, false);
|
||||
IntegrationNamespaceUtils.createExpressionDefinitionFromValueOrExpression("group-timeout",
|
||||
"group-timeout-expression", parserContext, element, false);
|
||||
builder.addPropertyValue("groupTimeoutExpression", expressionDef);
|
||||
|
||||
Element txElement = DomUtils.getChildElementByTagName(element, "expire-transactional");
|
||||
Element adviceChainElement = DomUtils.getChildElementByTagName(element, "expire-advice-chain");
|
||||
|
||||
IntegrationNamespaceUtils.configureAndSetAdviceChainIfPresent(adviceChainElement, txElement,
|
||||
builder.getRawBeanDefinition(), parserContext, "forceReleaseAdviceChain");
|
||||
}
|
||||
|
||||
protected void injectPropertyWithAdapter(String beanRefAttribute, String methodRefAttribute,
|
||||
@@ -92,8 +101,8 @@ public abstract class AbstractCorrelatingMessageHandlerParser extends AbstractCo
|
||||
final boolean hasExpression = StringUtils.hasText(expression);
|
||||
|
||||
if (hasBeanRef && hasExpression) {
|
||||
parserContext.getReaderContext().error("Exactly one of the '" + beanRefAttribute + "' or '" + expressionAttribute +
|
||||
"' attribute is allowed.", element);
|
||||
parserContext.getReaderContext().error("Exactly one of the '" + beanRefAttribute + "' or '"
|
||||
+ expressionAttribute + "' attribute is allowed.", element);
|
||||
}
|
||||
|
||||
BeanMetadataElement adapter = null;
|
||||
@@ -126,4 +135,5 @@ public abstract class AbstractCorrelatingMessageHandlerParser extends AbstractCo
|
||||
}
|
||||
return builder.getBeanDefinition();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -46,7 +46,6 @@ import org.springframework.messaging.MessagingException;
|
||||
import org.springframework.scheduling.TaskScheduler;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
/**
|
||||
@@ -237,7 +236,7 @@ public class DelayHandler extends AbstractReplyProducingMessageHandler implement
|
||||
for (Advice advice : delayedAdviceChain) {
|
||||
proxyFactory.addAdvice(advice);
|
||||
}
|
||||
return (MessageHandler) proxyFactory.getProxy(ClassUtils.getDefaultClassLoader());
|
||||
return (MessageHandler) proxyFactory.getProxy(getApplicationContext().getClassLoader());
|
||||
}
|
||||
return releaseHandler;
|
||||
}
|
||||
|
||||
@@ -3435,6 +3435,15 @@
|
||||
<xsd:complexType name="correlating-message-handler-type">
|
||||
<xsd:complexContent>
|
||||
<xsd:extension base="innerEndpointDefinitionAware">
|
||||
<xsd:choice>
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
'transactional' or 'advice-chain' are applied only to 'forceComplete' operation.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:element name="expire-transactional" type="transactionalType" minOccurs="0" maxOccurs="1" />
|
||||
<xsd:element name="expire-advice-chain" type="adviceChainType" minOccurs="0" maxOccurs="1" />
|
||||
</xsd:choice>
|
||||
<xsd:attribute name="correlation-strategy" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:appinfo>
|
||||
|
||||
@@ -21,7 +21,12 @@ import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assume;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TestWatcher;
|
||||
import org.junit.runner.Description;
|
||||
import org.junit.runners.model.Statement;
|
||||
|
||||
import org.springframework.context.support.AbstractApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
@@ -37,6 +42,40 @@ import org.springframework.messaging.MessageChannel;
|
||||
*/
|
||||
public class AggregatorWithCustomReleaseStrategyTests {
|
||||
|
||||
@Rule
|
||||
public TestWatcher longTests = new TestWatcher() {
|
||||
|
||||
private static final String RUN_LONG_PROP = "RUN_LONG_INTEGRATION_TESTS";
|
||||
|
||||
private boolean shouldRun;
|
||||
|
||||
{
|
||||
for(String value: new String[]{System.getenv(RUN_LONG_PROP), System.getProperty(RUN_LONG_PROP)}) {
|
||||
if ("true".equalsIgnoreCase(value)) {
|
||||
this.shouldRun = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Statement apply(Statement base, Description description) {
|
||||
if (!this.shouldRun) {
|
||||
return new Statement() {
|
||||
|
||||
@Override
|
||||
public void evaluate() throws Throwable {
|
||||
Assume.assumeTrue(false);
|
||||
}
|
||||
};
|
||||
}
|
||||
else {
|
||||
return super.apply(base, description);
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
private static ExecutorService executor = Executors.newCachedThreadPool();
|
||||
|
||||
@AfterClass
|
||||
|
||||
Reference in New Issue
Block a user