Added support for 'apply-sequence' on <publish-subscribe-channel/>. The BroadcastingDispatcher has the 'applySequence' property (INT-321).

This commit is contained in:
Mark Fisher
2008-07-30 16:02:47 +00:00
parent 59a4696d81
commit b9bb70b634
8 changed files with 193 additions and 9 deletions

View File

@@ -41,6 +41,7 @@ public class PublishSubscribeChannelParser extends AbstractChannelParser {
if (StringUtils.hasText(taskExecutorRef)) {
builder.addConstructorArgReference(taskExecutorRef);
}
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "apply-sequence");
}
}

View File

@@ -73,6 +73,7 @@
<xsd:complexContent>
<xsd:extension base="channelType">
<xsd:attribute name="task-executor" type="xsd:string"/>
<xsd:attribute name="apply-sequence" type="xsd:string"/>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>

View File

@@ -18,6 +18,7 @@ package org.springframework.integration.dispatcher;
import org.springframework.core.task.TaskExecutor;
import org.springframework.integration.message.Message;
import org.springframework.integration.message.MessageBuilder;
import org.springframework.integration.message.MessageTarget;
/**
@@ -30,18 +31,37 @@ import org.springframework.integration.message.MessageTarget;
*/
public class BroadcastingDispatcher extends AbstractDispatcher {
public boolean send(final Message<?> message) {
private volatile boolean applySequence;
/**
* Specify whether to apply sequence numbers to the messages
* prior to sending to the targets. By default, sequence
* numbers will <em>not</em> be applied
*/
public void setApplySequence(boolean applySequence) {
this.applySequence = applySequence;
}
public boolean send(Message<?> message) {
int sequenceNumber = 1;
int sequenceSize = this.targets.size();
for (final MessageTarget target : this.targets) {
final Message<?> messageToSend = (!this.applySequence) ? message
: MessageBuilder.fromMessage(message)
.setSequenceNumber(sequenceNumber++)
.setSequenceSize(sequenceSize)
.build();
TaskExecutor executor = this.getTaskExecutor();
if (executor != null) {
executor.execute(new Runnable() {
public void run() {
sendMessageToTarget(message, target);
sendMessageToTarget(messageToSend, target);
}
});
}
else {
this.sendMessageToTarget(message, target);
this.sendMessageToTarget(messageToSend, target);
}
}
return true;

View File

@@ -33,9 +33,6 @@ public class PublishSubscribeChannel extends AbstractMessageChannel implements S
private final BroadcastingDispatcher dispatcher = new BroadcastingDispatcher();
public PublishSubscribeChannel() {
}
/**
* Create a PublishSubscribeChannel that will use a {@link TaskExecutor}
* to publish its Messages.
@@ -46,6 +43,13 @@ public class PublishSubscribeChannel extends AbstractMessageChannel implements S
}
}
public PublishSubscribeChannel() {
}
public void setApplySequence(boolean applySequence) {
this.dispatcher.setApplySequence(applySequence);
}
public boolean subscribe(MessageTarget target) {
return this.dispatcher.addTarget(target);