DefaultMessageEndpoint constructor now requires a MessageHandler. The endpoint no longer invokes Lifecycle methods on the MessageHandler.
This commit is contained in:
@@ -105,8 +105,8 @@ public class ChannelAdapterParser implements BeanDefinitionParser {
|
||||
subscriptionDef.getConstructorArgumentValues().addGenericArgumentValue(new RuntimeBeanReference(channel));
|
||||
String subscriptionBeanName = parserContext.getReaderContext().generateBeanName(subscriptionDef);
|
||||
parserContext.registerBeanComponent(new BeanComponentDefinition(subscriptionDef, subscriptionBeanName));
|
||||
endpointDef.getConstructorArgumentValues().addGenericArgumentValue(new RuntimeBeanReference(beanName));
|
||||
endpointDef.getPropertyValues().addPropertyValue("subscription", new RuntimeBeanReference(subscriptionBeanName));
|
||||
endpointDef.getPropertyValues().addPropertyValue("handler", new RuntimeBeanReference(beanName));
|
||||
String endpointBeanName = parserContext.getReaderContext().generateBeanName(endpointDef);
|
||||
parserContext.registerBeanComponent(new BeanComponentDefinition(endpointDef, endpointBeanName));
|
||||
}
|
||||
|
||||
@@ -73,8 +73,6 @@ public class EndpointParser implements BeanDefinitionParser {
|
||||
|
||||
private static final String HANDLER_METHOD_ATTRIBUTE = "handler-method";
|
||||
|
||||
private static final String HANDLER_PROPERTY = "handler";
|
||||
|
||||
private static final String ERROR_HANDLER_ATTRIBUTE = "error-handler";
|
||||
|
||||
private static final String ERROR_HANDLER_PROPERTY = "errorHandler";
|
||||
@@ -149,8 +147,7 @@ public class EndpointParser implements BeanDefinitionParser {
|
||||
}
|
||||
if (childHandlerRefs.size() > 0) {
|
||||
if (childHandlerRefs.size() == 1) {
|
||||
endpointDef.getPropertyValues().addPropertyValue(
|
||||
HANDLER_PROPERTY, new RuntimeBeanReference(childHandlerRefs.get(0)));
|
||||
endpointDef.getConstructorArgumentValues().addGenericArgumentValue(new RuntimeBeanReference(childHandlerRefs.get(0)));
|
||||
}
|
||||
else {
|
||||
RootBeanDefinition handlerChainDef = new RootBeanDefinition(MessageHandlerChain.class);
|
||||
@@ -161,7 +158,7 @@ public class EndpointParser implements BeanDefinitionParser {
|
||||
handlerChainDef.getPropertyValues().addPropertyValue(HANDLERS_PROPERTY, handlerList);
|
||||
String chainBeanName = parserContext.getReaderContext().generateBeanName(handlerChainDef);
|
||||
parserContext.registerBeanComponent(new BeanComponentDefinition(handlerChainDef, chainBeanName));
|
||||
endpointDef.getPropertyValues().addPropertyValue(HANDLER_PROPERTY, new RuntimeBeanReference(chainBeanName));
|
||||
endpointDef.getConstructorArgumentValues().addGenericArgumentValue(new RuntimeBeanReference(chainBeanName));
|
||||
}
|
||||
}
|
||||
String handlerRef = element.getAttribute(HANDLER_REF_ATTRIBUTE);
|
||||
@@ -173,10 +170,10 @@ public class EndpointParser implements BeanDefinitionParser {
|
||||
String handlerMethod = element.getAttribute(HANDLER_METHOD_ATTRIBUTE);
|
||||
if (StringUtils.hasText(handlerMethod)) {
|
||||
String adapterBeanName = this.parseHandlerAdapter(handlerRef, handlerMethod, parserContext);
|
||||
endpointDef.getPropertyValues().addPropertyValue(HANDLER_PROPERTY, new RuntimeBeanReference(adapterBeanName));
|
||||
endpointDef.getConstructorArgumentValues().addGenericArgumentValue(new RuntimeBeanReference(adapterBeanName));
|
||||
}
|
||||
else {
|
||||
endpointDef.getPropertyValues().addPropertyValue(HANDLER_PROPERTY, new RuntimeBeanReference(handlerRef));
|
||||
endpointDef.getConstructorArgumentValues().addGenericArgumentValue(new RuntimeBeanReference(handlerRef));
|
||||
}
|
||||
}
|
||||
String errorHandlerRef = element.getAttribute(ERROR_HANDLER_ATTRIBUTE);
|
||||
|
||||
@@ -30,8 +30,6 @@ import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.beans.factory.BeanNameAware;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.context.Lifecycle;
|
||||
import org.springframework.integration.ConfigurationException;
|
||||
import org.springframework.integration.channel.ChannelRegistry;
|
||||
import org.springframework.integration.channel.ChannelRegistryAware;
|
||||
import org.springframework.integration.channel.MessageChannel;
|
||||
@@ -84,10 +82,8 @@ public class DefaultMessageEndpoint implements MessageEndpoint, ChannelRegistryA
|
||||
private volatile boolean running;
|
||||
|
||||
|
||||
public DefaultMessageEndpoint() {
|
||||
}
|
||||
|
||||
public DefaultMessageEndpoint(MessageHandler handler) {
|
||||
Assert.notNull(handler, "handler must not be null");
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
@@ -185,9 +181,6 @@ public class DefaultMessageEndpoint implements MessageEndpoint, ChannelRegistryA
|
||||
}
|
||||
|
||||
public void afterPropertiesSet() {
|
||||
if (this.handler == null) {
|
||||
return;
|
||||
}
|
||||
if (this.handler instanceof ChannelRegistryAware) {
|
||||
((ChannelRegistryAware) this.handler).setChannelRegistry(this.channelRegistry);
|
||||
}
|
||||
@@ -221,9 +214,6 @@ public class DefaultMessageEndpoint implements MessageEndpoint, ChannelRegistryA
|
||||
if (!initialized) {
|
||||
this.afterPropertiesSet();
|
||||
}
|
||||
if (this.handler instanceof Lifecycle) {
|
||||
((Lifecycle) handler).start();
|
||||
}
|
||||
this.running = true;
|
||||
}
|
||||
|
||||
@@ -231,16 +221,10 @@ public class DefaultMessageEndpoint implements MessageEndpoint, ChannelRegistryA
|
||||
if (!this.isRunning()) {
|
||||
return;
|
||||
}
|
||||
if (this.handler instanceof Lifecycle) {
|
||||
((Lifecycle) handler).stop();
|
||||
}
|
||||
this.running = false;
|
||||
}
|
||||
|
||||
public final Message<?> handle(Message<?> message) {
|
||||
if (this.handler == null) {
|
||||
throw new ConfigurationException("endpoint has no 'handler'");
|
||||
}
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("endpoint '" + this + "' handling message: " + message);
|
||||
}
|
||||
@@ -312,8 +296,8 @@ public class DefaultMessageEndpoint implements MessageEndpoint, ChannelRegistryA
|
||||
logger.debug("endpoint '" + DefaultMessageEndpoint.this + "' replying to channel '" + replyChannel + "' with message: " + replyMessage);
|
||||
}
|
||||
if (!replyChannel.send(replyMessage, replyTimeout)) {
|
||||
errorHandler.handle(new MessageDeliveryException(replyMessage,
|
||||
"unable to send reply message within alloted timeout of " + replyTimeout + " milliseconds"));
|
||||
throw new MessageDeliveryException(replyMessage,
|
||||
"unable to send reply message within alloted timeout of " + replyTimeout + " milliseconds");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user