MessageFilter is now an endpoint.
This commit is contained in:
@@ -29,7 +29,6 @@ import java.util.concurrent.TimeUnit;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.integration.channel.BlockingChannel;
|
||||
import org.springframework.integration.channel.MessageChannel;
|
||||
import org.springframework.integration.endpoint.AbstractInOutEndpoint;
|
||||
@@ -61,7 +60,7 @@ import org.springframework.util.ObjectUtils;
|
||||
* @author Mark Fisher
|
||||
* @author Marius Bogoevici
|
||||
*/
|
||||
public abstract class AbstractMessageBarrierEndpoint extends AbstractInOutEndpoint implements InitializingBean {
|
||||
public abstract class AbstractMessageBarrierEndpoint extends AbstractInOutEndpoint {
|
||||
|
||||
public final static long DEFAULT_SEND_TIMEOUT = 1000;
|
||||
|
||||
@@ -151,7 +150,8 @@ public abstract class AbstractMessageBarrierEndpoint extends AbstractInOutEndpoi
|
||||
/**
|
||||
* Initialize this endpoint.
|
||||
*/
|
||||
public void afterPropertiesSet() {
|
||||
@Override
|
||||
protected void initialize() {
|
||||
this.trackedCorrelationIds = new ArrayBlockingQueue<Object>(this.trackedCorrelationIdCapacity);
|
||||
this.executor.scheduleWithFixedDelay(new ReaperTask(),
|
||||
this.reaperInterval, this.reaperInterval, TimeUnit.MILLISECONDS);
|
||||
|
||||
@@ -20,6 +20,8 @@ import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.beans.factory.BeanNameAware;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.integration.ConfigurationException;
|
||||
import org.springframework.integration.channel.ChannelRegistry;
|
||||
import org.springframework.integration.channel.ChannelRegistryAware;
|
||||
import org.springframework.integration.message.Message;
|
||||
@@ -27,6 +29,7 @@ import org.springframework.integration.message.MessageExchangeTemplate;
|
||||
import org.springframework.integration.message.MessageHandlingException;
|
||||
import org.springframework.integration.message.MessageSource;
|
||||
import org.springframework.integration.message.MessagingException;
|
||||
import org.springframework.integration.message.SubscribableSource;
|
||||
import org.springframework.integration.util.ErrorHandler;
|
||||
|
||||
/**
|
||||
@@ -34,7 +37,7 @@ import org.springframework.integration.util.ErrorHandler;
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public abstract class AbstractEndpoint implements MessageEndpoint, ChannelRegistryAware, BeanNameAware {
|
||||
public abstract class AbstractEndpoint implements MessageEndpoint, ChannelRegistryAware, BeanNameAware, InitializingBean {
|
||||
|
||||
protected final Log logger = LogFactory.getLog(this.getClass());
|
||||
|
||||
@@ -90,6 +93,27 @@ public abstract class AbstractEndpoint implements MessageEndpoint, ChannelRegist
|
||||
this.errorHandler = errorHandler;
|
||||
}
|
||||
|
||||
public final void afterPropertiesSet() {
|
||||
if (this.source != null && (this.source instanceof SubscribableSource)) {
|
||||
((SubscribableSource) this.source).subscribe(this);
|
||||
}
|
||||
try {
|
||||
this.initialize();
|
||||
}
|
||||
catch (Exception e) {
|
||||
if (e instanceof RuntimeException) {
|
||||
throw (RuntimeException) e;
|
||||
}
|
||||
throw new ConfigurationException("failed to initialize endpoint '" + this.getName() + "'", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Subclasses may override this method for custom initialization requirements.
|
||||
*/
|
||||
protected void initialize() throws Exception {
|
||||
}
|
||||
|
||||
public final boolean send(Message<?> message) {
|
||||
if (message == null || message.getPayload() == null) {
|
||||
throw new IllegalArgumentException("Message and its payload must not be null");
|
||||
|
||||
@@ -91,7 +91,14 @@ public abstract class AbstractInOutEndpoint extends AbstractEndpoint {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
Message<?> reply = buildReplyMessage(result, message.getHeaders());
|
||||
Message<?> reply = null;
|
||||
if (result instanceof Message && result.equals(message)) {
|
||||
// we simply pass along an unaltered request Message
|
||||
reply = (Message<?>) result;
|
||||
}
|
||||
else {
|
||||
reply = buildReplyMessage(result, message.getHeaders());
|
||||
}
|
||||
MessageChannel replyChannel = this.resolveReplyChannel(message);
|
||||
if (reply instanceof CompositeMessage && this.shouldSplitComposite()) {
|
||||
boolean sentAtLeastOne = false;
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.springframework.util.Assert;
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class ServiceActivatorEndpoint extends AbstractInOutEndpoint implements InitializingBean {
|
||||
public class ServiceActivatorEndpoint extends AbstractInOutEndpoint {
|
||||
|
||||
public static final String DEFAULT_LISTENER_METHOD = "handle";
|
||||
|
||||
@@ -48,7 +48,8 @@ public class ServiceActivatorEndpoint extends AbstractInOutEndpoint implements I
|
||||
}
|
||||
|
||||
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
@Override
|
||||
protected void initialize() throws Exception {
|
||||
if (this.invoker instanceof InitializingBean) {
|
||||
((InitializingBean) this.invoker).afterPropertiesSet();
|
||||
}
|
||||
|
||||
@@ -206,6 +206,7 @@ public class SimpleMessagingGateway extends MessagingGatewaySupport implements M
|
||||
ReplyMessageCorrelator correlator = new ReplyMessageCorrelator(this.replyMapCapacity);
|
||||
correlator.setBeanName("internal.correlator." + this);
|
||||
correlator.setSource(this.replyChannel);
|
||||
correlator.afterPropertiesSet();
|
||||
this.endpointRegistry.registerEndpoint(correlator);
|
||||
this.replyMessageCorrelator = correlator;
|
||||
}
|
||||
|
||||
@@ -16,25 +16,30 @@
|
||||
|
||||
package org.springframework.integration.handler;
|
||||
|
||||
import org.springframework.integration.endpoint.AbstractInOutEndpoint;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.selector.MessageSelector;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Handler for deciding whether to pass a message. Implements
|
||||
* {@link MessageHandler} and simply delegates to a {@link MessageSelector}.
|
||||
* Message Endpoint that decides whether to pass a message along to its
|
||||
* output channel. Delegates to a {@link MessageSelector}.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class MessageFilter implements MessageHandler {
|
||||
public class MessageFilter extends AbstractInOutEndpoint {
|
||||
|
||||
private MessageSelector selector;
|
||||
|
||||
|
||||
public MessageFilter(MessageSelector selector) {
|
||||
Assert.notNull(selector, "selector must not be null");
|
||||
this.selector = selector;
|
||||
}
|
||||
|
||||
public Message<?> handle(Message<?> message) {
|
||||
|
||||
@Override
|
||||
protected Message<?> handle(Message<?> message) {
|
||||
if (this.selector.accept(message)) {
|
||||
return message;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user