MessageEndpoint no longer extends the MessageTarget interface.
This commit is contained in:
@@ -17,13 +17,13 @@
|
||||
package org.springframework.integration.channel;
|
||||
|
||||
import org.springframework.integration.dispatcher.SimpleDispatcher;
|
||||
import org.springframework.integration.endpoint.MessageEndpoint;
|
||||
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 MessageTarget target(s)} in
|
||||
* the sender's thread (returning after at most one handles the message).
|
||||
* A channel that invokes the subscribed {@link MessageEndpoint endpoint(s)}
|
||||
* in the sender's thread (returning after at most one accepts the message).
|
||||
*
|
||||
* @author Dave Syer
|
||||
* @author Mark Fisher
|
||||
@@ -33,12 +33,12 @@ public class DirectChannel extends AbstractMessageChannel implements Subscribabl
|
||||
private final SimpleDispatcher dispatcher = new SimpleDispatcher();
|
||||
|
||||
|
||||
public boolean subscribe(MessageTarget target) {
|
||||
return this.dispatcher.subscribe(target);
|
||||
public boolean subscribe(MessageEndpoint endpoint) {
|
||||
return this.dispatcher.subscribe(endpoint);
|
||||
}
|
||||
|
||||
public boolean unsubscribe(MessageTarget target) {
|
||||
return this.dispatcher.unsubscribe(target);
|
||||
public boolean unsubscribe(MessageEndpoint endpoint) {
|
||||
return this.dispatcher.unsubscribe(endpoint);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -18,8 +18,8 @@ package org.springframework.integration.channel;
|
||||
|
||||
import org.springframework.core.task.TaskExecutor;
|
||||
import org.springframework.integration.dispatcher.BroadcastingDispatcher;
|
||||
import org.springframework.integration.endpoint.MessageEndpoint;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessageTarget;
|
||||
import org.springframework.integration.message.SubscribableSource;
|
||||
|
||||
/**
|
||||
@@ -48,12 +48,12 @@ public class PublishSubscribeChannel extends AbstractMessageChannel implements S
|
||||
this.dispatcher.setApplySequence(applySequence);
|
||||
}
|
||||
|
||||
public boolean subscribe(MessageTarget target) {
|
||||
return this.dispatcher.subscribe(target);
|
||||
public boolean subscribe(MessageEndpoint endpoint) {
|
||||
return this.dispatcher.subscribe(endpoint);
|
||||
}
|
||||
|
||||
public boolean unsubscribe(MessageTarget target) {
|
||||
return this.dispatcher.unsubscribe(target);
|
||||
public boolean unsubscribe(MessageEndpoint endpoint) {
|
||||
return this.dispatcher.unsubscribe(endpoint);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -23,8 +23,8 @@ import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.core.task.TaskExecutor;
|
||||
import org.springframework.integration.endpoint.MessageEndpoint;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessageTarget;
|
||||
|
||||
/**
|
||||
* Base class for {@link MessageDispatcher} implementations.
|
||||
@@ -35,7 +35,7 @@ public abstract class AbstractDispatcher implements MessageDispatcher {
|
||||
|
||||
protected final Log logger = LogFactory.getLog(this.getClass());
|
||||
|
||||
protected final Set<MessageTarget> targets = new CopyOnWriteArraySet<MessageTarget>();
|
||||
protected final Set<MessageEndpoint> endpoints = new CopyOnWriteArraySet<MessageEndpoint>();
|
||||
|
||||
private volatile TaskExecutor taskExecutor;
|
||||
|
||||
@@ -46,18 +46,18 @@ public abstract class AbstractDispatcher implements MessageDispatcher {
|
||||
return "dispatcher";
|
||||
}
|
||||
|
||||
public boolean subscribe(MessageTarget target) {
|
||||
return this.targets.add(target);
|
||||
public boolean subscribe(MessageEndpoint endpoint) {
|
||||
return this.endpoints.add(endpoint);
|
||||
}
|
||||
|
||||
public boolean unsubscribe(MessageTarget target) {
|
||||
return this.targets.remove(target);
|
||||
public boolean unsubscribe(MessageEndpoint endpoint) {
|
||||
return this.endpoints.remove(endpoint);
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify a {@link TaskExecutor} for invoking the target endpoints.
|
||||
* Specify a {@link TaskExecutor} for invoking the endpoints.
|
||||
* If none is provided, the invocation will occur in the thread
|
||||
* that runs this polling dispatcher.
|
||||
* that runs this polling dispatcher.
|
||||
*/
|
||||
public void setTaskExecutor(TaskExecutor taskExecutor) {
|
||||
this.taskExecutor = taskExecutor;
|
||||
@@ -68,14 +68,14 @@ public abstract class AbstractDispatcher implements MessageDispatcher {
|
||||
}
|
||||
|
||||
/**
|
||||
* A convenience method for subclasses to send a Message to a single target.
|
||||
* A convenience method for subclasses to send a Message to a single endpoint.
|
||||
*/
|
||||
protected final boolean sendMessageToTarget(Message<?> message, MessageTarget target) {
|
||||
return target.send(message);
|
||||
protected final boolean sendMessageToEndpoint(Message<?> message, MessageEndpoint endpoint) {
|
||||
return endpoint.send(message);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return this.getClass().getSimpleName() + " with targets: " + this.targets;
|
||||
return this.getClass().getSimpleName() + " with endpoints: " + this.endpoints;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,15 +17,15 @@
|
||||
package org.springframework.integration.dispatcher;
|
||||
|
||||
import org.springframework.core.task.TaskExecutor;
|
||||
import org.springframework.integration.endpoint.MessageEndpoint;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessageBuilder;
|
||||
import org.springframework.integration.message.MessageTarget;
|
||||
|
||||
/**
|
||||
* A broadcasting dispatcher implementation. It makes a best effort to
|
||||
* send the message to each of its targets. If it fails to send to any
|
||||
* one target, it will log a warn-level message but continue to send
|
||||
* to the other targets.
|
||||
* send the message to each of its endpoints. If it fails to send to any
|
||||
* one endpoints, it will log a warn-level message but continue to send
|
||||
* to the other endpoints.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
@@ -36,7 +36,7 @@ public class BroadcastingDispatcher extends AbstractDispatcher {
|
||||
|
||||
/**
|
||||
* Specify whether to apply sequence numbers to the messages
|
||||
* prior to sending to the targets. By default, sequence
|
||||
* prior to sending to the endpoints. By default, sequence
|
||||
* numbers will <em>not</em> be applied
|
||||
*/
|
||||
public void setApplySequence(boolean applySequence) {
|
||||
@@ -45,8 +45,8 @@ public class BroadcastingDispatcher extends AbstractDispatcher {
|
||||
|
||||
public boolean send(Message<?> message) {
|
||||
int sequenceNumber = 1;
|
||||
int sequenceSize = this.targets.size();
|
||||
for (final MessageTarget target : this.targets) {
|
||||
int sequenceSize = this.endpoints.size();
|
||||
for (final MessageEndpoint endpoint : this.endpoints) {
|
||||
final Message<?> messageToSend = (!this.applySequence) ? message
|
||||
: MessageBuilder.fromMessage(message)
|
||||
.setSequenceNumber(sequenceNumber++)
|
||||
@@ -56,12 +56,12 @@ public class BroadcastingDispatcher extends AbstractDispatcher {
|
||||
if (executor != null) {
|
||||
executor.execute(new Runnable() {
|
||||
public void run() {
|
||||
sendMessageToTarget(messageToSend, target);
|
||||
sendMessageToEndpoint(messageToSend, endpoint);
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
this.sendMessageToTarget(messageToSend, target);
|
||||
this.sendMessageToEndpoint(messageToSend, endpoint);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
package org.springframework.integration.dispatcher;
|
||||
|
||||
import org.springframework.integration.channel.MessageChannel;
|
||||
import org.springframework.integration.endpoint.MessageEndpoint;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessageTarget;
|
||||
import org.springframework.integration.message.SubscribableSource;
|
||||
|
||||
/**
|
||||
@@ -30,8 +30,8 @@ public interface MessageDispatcher extends MessageChannel, SubscribableSource {
|
||||
|
||||
boolean send(Message<?> message);
|
||||
|
||||
boolean subscribe(MessageTarget target);
|
||||
boolean subscribe(MessageEndpoint endpoint);
|
||||
|
||||
boolean unsubscribe(MessageTarget target);
|
||||
boolean unsubscribe(MessageEndpoint endpoint);
|
||||
|
||||
}
|
||||
|
||||
@@ -19,9 +19,9 @@ package org.springframework.integration.dispatcher;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.integration.endpoint.MessageEndpoint;
|
||||
import org.springframework.integration.message.BlockingSource;
|
||||
import org.springframework.integration.message.MessageExchangeTemplate;
|
||||
import org.springframework.integration.message.MessageTarget;
|
||||
import org.springframework.integration.message.PollableSource;
|
||||
import org.springframework.integration.message.SubscribableSource;
|
||||
import org.springframework.integration.scheduling.SchedulableTask;
|
||||
@@ -99,12 +99,12 @@ public class PollingDispatcher implements SchedulableTask, SubscribableSource {
|
||||
this.maxMessagesPerPoll = maxMessagesPerPoll;
|
||||
}
|
||||
|
||||
public boolean subscribe(MessageTarget target) {
|
||||
return this.dispatcher.subscribe(target);
|
||||
public boolean subscribe(MessageEndpoint endpoint) {
|
||||
return this.dispatcher.subscribe(endpoint);
|
||||
}
|
||||
|
||||
public boolean unsubscribe(MessageTarget target) {
|
||||
return this.dispatcher.unsubscribe(target);
|
||||
public boolean unsubscribe(MessageEndpoint endpoint) {
|
||||
return this.dispatcher.unsubscribe(endpoint);
|
||||
}
|
||||
|
||||
public Schedule getSchedule() {
|
||||
|
||||
@@ -16,19 +16,19 @@
|
||||
|
||||
package org.springframework.integration.dispatcher;
|
||||
|
||||
import org.springframework.integration.endpoint.MessageEndpoint;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessageDeliveryException;
|
||||
import org.springframework.integration.message.MessageRejectedException;
|
||||
import org.springframework.integration.message.MessageTarget;
|
||||
|
||||
/**
|
||||
* Basic implementation of {@link MessageDispatcher} that will attempt
|
||||
* to send a {@link Message} to one of its targets. As soon as <em>one</em>
|
||||
* of the targets accepts the Message, the dispatcher will return 'true'.
|
||||
* to send a {@link Message} to one of its endpoints. As soon as <em>one</em>
|
||||
* of the endpoints accepts the Message, the dispatcher will return 'true'.
|
||||
* <p>
|
||||
* If the dispatcher has no targets, a {@link MessageDeliveryException}
|
||||
* will be thrown. If all targets reject the Message, the dispatcher will
|
||||
* throw a MessageRejectedException. If all targets return 'false'
|
||||
* If the dispatcher has no endpoints, a {@link MessageDeliveryException}
|
||||
* will be thrown. If all endpoints reject the Message, the dispatcher will
|
||||
* throw a MessageRejectedException. If all endpoints return 'false'
|
||||
* (e.g. due to a timeout), the dispatcher will return 'false'.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
@@ -36,30 +36,30 @@ import org.springframework.integration.message.MessageTarget;
|
||||
public class SimpleDispatcher extends AbstractDispatcher {
|
||||
|
||||
public boolean send(Message<?> message) {
|
||||
if (this.targets.size() == 0) {
|
||||
throw new MessageDeliveryException(message, "Dispatcher has no targets.");
|
||||
if (this.endpoints.size() == 0) {
|
||||
throw new MessageDeliveryException(message, "Dispatcher has no subscribers.");
|
||||
}
|
||||
int count = 0;
|
||||
int rejectedExceptionCount = 0;
|
||||
for (MessageTarget target : this.targets) {
|
||||
for (MessageEndpoint endpoint : this.endpoints) {
|
||||
count++;
|
||||
try {
|
||||
if (this.sendMessageToTarget(message, target)) {
|
||||
if (this.sendMessageToEndpoint(message, endpoint)) {
|
||||
return true;
|
||||
}
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Failed to send message to target, continuing with other targets if available.");
|
||||
logger.debug("Failed to send message to endpoint, continuing with other endpoints if available.");
|
||||
}
|
||||
}
|
||||
catch (MessageRejectedException e) {
|
||||
rejectedExceptionCount++;
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Target '" + target + "' rejected Message, continuing with other targets if available.", e);
|
||||
logger.debug("Endpoint '" + endpoint + "' rejected Message, continuing with other endpoints if available.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (rejectedExceptionCount == count) {
|
||||
throw new MessageRejectedException(message, "All of dispatcher's targets rejected Message.");
|
||||
throw new MessageRejectedException(message, "All of dispatcher's endpoints rejected Message.");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -16,18 +16,20 @@
|
||||
|
||||
package org.springframework.integration.endpoint;
|
||||
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessageSource;
|
||||
import org.springframework.integration.message.MessageTarget;
|
||||
|
||||
/**
|
||||
* Base interface for message endpoints.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public interface MessageEndpoint extends MessageTarget {
|
||||
public interface MessageEndpoint {
|
||||
|
||||
String getName();
|
||||
|
||||
MessageSource<?> getSource();
|
||||
|
||||
boolean send(Message<?> message);
|
||||
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.springframework.integration.message;
|
||||
|
||||
import org.springframework.integration.endpoint.MessageEndpoint;
|
||||
|
||||
/**
|
||||
* Interface for any source of messages that accepts subscribers.
|
||||
*
|
||||
@@ -24,13 +26,13 @@ package org.springframework.integration.message;
|
||||
public interface SubscribableSource extends MessageSource {
|
||||
|
||||
/**
|
||||
* Register a {@link MessageTarget} as a subscriber to this source.
|
||||
* Register a {@link MessageEndpoint} as a subscriber to this source.
|
||||
*/
|
||||
boolean subscribe(MessageTarget target);
|
||||
boolean subscribe(MessageEndpoint endpoint);
|
||||
|
||||
/**
|
||||
* Remove a {@link MessageTarget} from the subscribers of this source.
|
||||
* Remove a {@link MessageEndpoint} from the subscribers of this source.
|
||||
*/
|
||||
boolean unsubscribe(MessageTarget target);
|
||||
boolean unsubscribe(MessageEndpoint endpoint);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user