MessageDispatcher now extends SubscribableSource. The 'addTarget' and 'removeTarget' methods have been replaced with 'subscribe' and 'unsubscribe' respectively.
This commit is contained in:
@@ -47,11 +47,11 @@ public abstract class AbstractDispatcher implements MessageDispatcher {
|
||||
this.messageExchangeTemplate.setSendTimeout(timeout);
|
||||
}
|
||||
|
||||
public boolean addTarget(MessageTarget target) {
|
||||
public boolean subscribe(MessageTarget target) {
|
||||
return this.targets.add(target);
|
||||
}
|
||||
|
||||
public boolean removeTarget(MessageTarget target) {
|
||||
public boolean unsubscribe(MessageTarget target) {
|
||||
return this.targets.remove(target);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,16 +16,13 @@
|
||||
|
||||
package org.springframework.integration.dispatcher;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.springframework.integration.channel.AbstractMessageChannel;
|
||||
import org.springframework.integration.handler.MessageHandler;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.SubscribableSource;
|
||||
import org.springframework.integration.message.MessageTarget;
|
||||
|
||||
/**
|
||||
* A channel that invokes the subscribed {@link MessageHandler handler(s)} in
|
||||
* A channel that invokes the subscribed {@link MessageTarget target(s)} in
|
||||
* the sender's thread (returning after at most one handles the message).
|
||||
*
|
||||
* @author Dave Syer
|
||||
@@ -35,31 +32,18 @@ public class DirectChannel extends AbstractMessageChannel implements Subscribabl
|
||||
|
||||
private final SimpleDispatcher dispatcher = new SimpleDispatcher();
|
||||
|
||||
private final AtomicInteger handlerCount = new AtomicInteger();
|
||||
|
||||
|
||||
public boolean subscribe(MessageTarget target) {
|
||||
boolean added = this.dispatcher.addTarget(target);
|
||||
if (added) {
|
||||
this.handlerCount.incrementAndGet();
|
||||
}
|
||||
return added;
|
||||
return this.dispatcher.subscribe(target);
|
||||
}
|
||||
|
||||
public boolean unsubscribe(MessageTarget target) {
|
||||
boolean removed = this.dispatcher.removeTarget(target);
|
||||
if (removed) {
|
||||
this.handlerCount.decrementAndGet();
|
||||
}
|
||||
return removed;
|
||||
return this.dispatcher.unsubscribe(target);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean doSend(Message<?> message, long timeout) {
|
||||
if (message != null && this.handlerCount.get() > 0) {
|
||||
return this.dispatcher.send(message);
|
||||
}
|
||||
return false;
|
||||
return this.dispatcher.send(message);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,25 +18,25 @@ package org.springframework.integration.dispatcher;
|
||||
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessageTarget;
|
||||
import org.springframework.integration.message.SubscribableSource;
|
||||
|
||||
/**
|
||||
* Strategy interface for dispatching messages.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public interface MessageDispatcher extends MessageTarget {
|
||||
public interface MessageDispatcher extends MessageTarget, SubscribableSource {
|
||||
|
||||
boolean send(Message<?> message);
|
||||
|
||||
/**
|
||||
* Specify the timeout for sending to a target (in milliseconds).
|
||||
* Note that this value will only be applicable for blocking targets.
|
||||
* The default value is 0.
|
||||
*/
|
||||
void setTimeout(long timeout);
|
||||
|
||||
boolean addTarget(MessageTarget target);
|
||||
boolean subscribe(MessageTarget target);
|
||||
|
||||
boolean removeTarget(MessageTarget target);
|
||||
boolean unsubscribe(MessageTarget target);
|
||||
|
||||
}
|
||||
|
||||
@@ -110,11 +110,11 @@ public class PollingDispatcher implements SchedulableTask, SubscribableSource {
|
||||
}
|
||||
|
||||
public boolean subscribe(MessageTarget target) {
|
||||
return this.dispatcher.addTarget(target);
|
||||
return this.dispatcher.subscribe(target);
|
||||
}
|
||||
|
||||
public boolean unsubscribe(MessageTarget target) {
|
||||
return this.dispatcher.removeTarget(target);
|
||||
return this.dispatcher.unsubscribe(target);
|
||||
}
|
||||
|
||||
public Schedule getSchedule() {
|
||||
|
||||
@@ -49,11 +49,11 @@ public class PublishSubscribeChannel extends AbstractMessageChannel implements S
|
||||
}
|
||||
|
||||
public boolean subscribe(MessageTarget target) {
|
||||
return this.dispatcher.addTarget(target);
|
||||
return this.dispatcher.subscribe(target);
|
||||
}
|
||||
|
||||
public boolean unsubscribe(MessageTarget target) {
|
||||
return this.dispatcher.removeTarget(target);
|
||||
return this.dispatcher.unsubscribe(target);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user