Removed the name parameter from channelRegistry.registerChannel() since the MessageChannel interface already defines getName(). Removed the setName() method from the MessageChannel interface. Removed the 'error-channel' attribute from the <message-bus/> element and the setErrorChannel() method from MessageBus. The "errorChannel" name is now sufficient for configuration.
This commit is contained in:
@@ -19,6 +19,7 @@ package org.springframework.integration.bus;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.integration.channel.ChannelRegistry;
|
||||
import org.springframework.integration.channel.MessageChannel;
|
||||
import org.springframework.integration.channel.RendezvousChannel;
|
||||
import org.springframework.integration.channel.interceptor.ChannelInterceptorAdapter;
|
||||
@@ -36,6 +37,7 @@ public class DefaultErrorChannel extends RendezvousChannel {
|
||||
|
||||
public DefaultErrorChannel() {
|
||||
this.addInterceptor(new ErrorLoggingInterceptor());
|
||||
this.setBeanName(ChannelRegistry.ERROR_CHANNEL_NAME);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -173,7 +173,7 @@ public class DefaultMessageBus implements MessageBus, ApplicationContextAware, A
|
||||
String channelName = entry.getKey();
|
||||
MessageChannel previousChannel = this.lookupChannel(channelName);
|
||||
if (previousChannel == null) {
|
||||
this.registerChannel(channelName, entry.getValue());
|
||||
this.registerChannel(entry.getValue());
|
||||
}
|
||||
else if (!previousChannel.equals(entry.getValue())) {
|
||||
throw new ConfigurationException("A different channel instance has already "
|
||||
@@ -213,7 +213,7 @@ public class DefaultMessageBus implements MessageBus, ApplicationContextAware, A
|
||||
this.taskScheduler = new ProviderTaskScheduler(new SimpleScheduleServiceProvider(executor));
|
||||
}
|
||||
if (this.getErrorChannel() == null) {
|
||||
this.setErrorChannel(new DefaultErrorChannel());
|
||||
this.registerChannel(new DefaultErrorChannel());
|
||||
}
|
||||
this.initialized = true;
|
||||
this.initializing = false;
|
||||
@@ -224,30 +224,22 @@ public class DefaultMessageBus implements MessageBus, ApplicationContextAware, A
|
||||
return this.lookupChannel(ERROR_CHANNEL_NAME);
|
||||
}
|
||||
|
||||
public void setErrorChannel(MessageChannel errorChannel) {
|
||||
this.registerChannel(ERROR_CHANNEL_NAME, errorChannel);
|
||||
}
|
||||
|
||||
public MessageChannel lookupChannel(String channelName) {
|
||||
MessageChannel channel = this.channelRegistry.lookupChannel(channelName);
|
||||
if (channel == null && this.applicationContext != null && this.applicationContext.containsBean(channelName)) {
|
||||
Object bean = this.applicationContext.getBean(channelName);
|
||||
if (bean instanceof MessageChannel) {
|
||||
channel = (MessageChannel) bean;
|
||||
this.registerChannel(channelName, channel);
|
||||
this.registerChannel(channel);
|
||||
}
|
||||
}
|
||||
return channel;
|
||||
}
|
||||
|
||||
public void registerChannel(String name, MessageChannel channel) {
|
||||
if (!this.initialized) {
|
||||
this.initialize();
|
||||
}
|
||||
channel.setName(name);
|
||||
this.channelRegistry.registerChannel(name, channel);
|
||||
public void registerChannel(MessageChannel channel) {
|
||||
this.channelRegistry.registerChannel(channel);
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("registered channel '" + name + "'");
|
||||
logger.info("registered channel '" + channel.getName() + "'");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -354,7 +346,7 @@ public class DefaultMessageBus implements MessageBus, ApplicationContextAware, A
|
||||
logger.info("auto-creating channel '" + channelName + "'");
|
||||
}
|
||||
channel = channelFactory.getChannel(channelName, null);
|
||||
this.registerChannel(channelName, channel);
|
||||
this.registerChannel(channel);
|
||||
}
|
||||
return channel;
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ public class AbstractChannelAdapter extends AbstractMessageChannel {
|
||||
|
||||
public AbstractChannelAdapter(String name, MessageTarget target) {
|
||||
Assert.notNull(name, "name must not be null");
|
||||
this.setName(name);
|
||||
this.setBeanName(name);
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
|
||||
@@ -44,9 +44,10 @@ public abstract class AbstractMessageChannel implements MessageChannel, BeanName
|
||||
|
||||
|
||||
/**
|
||||
* Set the name of this channel.
|
||||
* Set the name of this channel. This will be invoked automatically whenever
|
||||
* the channel is configured explicitly with a bean definition.
|
||||
*/
|
||||
public void setName(String name) {
|
||||
public void setBeanName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@@ -57,15 +58,6 @@ public abstract class AbstractMessageChannel implements MessageChannel, BeanName
|
||||
return this.name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the name of this channel to its bean name. This will be invoked
|
||||
* automatically whenever the channel is configured explicitly with a bean
|
||||
* definition.
|
||||
*/
|
||||
public void setBeanName(String beanName) {
|
||||
this.setName(beanName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the list of channel interceptors. This will clear any existing
|
||||
* interceptors.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -26,7 +26,7 @@ public interface ChannelRegistry {
|
||||
static final String ERROR_CHANNEL_NAME = "errorChannel";
|
||||
|
||||
|
||||
void registerChannel(String name, MessageChannel channel);
|
||||
void registerChannel(MessageChannel channel);
|
||||
|
||||
MessageChannel unregisterChannel(String name);
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -35,10 +35,10 @@ public class DefaultChannelRegistry implements ChannelRegistry {
|
||||
return this.channels.get(channelName);
|
||||
}
|
||||
|
||||
public void registerChannel(String name, MessageChannel channel) {
|
||||
Assert.notNull(name, "'name' must not be null");
|
||||
public void registerChannel(MessageChannel channel) {
|
||||
Assert.notNull(channel, "'channel' must not be null");
|
||||
this.channels.put(name, channel);
|
||||
Assert.notNull(channel.getName(), "channel name must not be null");
|
||||
this.channels.put(channel.getName(), channel);
|
||||
}
|
||||
|
||||
public MessageChannel unregisterChannel(String name) {
|
||||
|
||||
@@ -31,9 +31,4 @@ public interface MessageChannel extends MessageSource, BlockingTarget {
|
||||
*/
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* Set the name of this channel.
|
||||
*/
|
||||
void setName(String name);
|
||||
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ public abstract class AbstractChannelFactory implements ChannelFactory {
|
||||
channel.setInterceptors(interceptors);
|
||||
}
|
||||
if (name != null && channel.getName() == null) {
|
||||
channel.setName(name);
|
||||
channel.setBeanName(name);
|
||||
}
|
||||
return channel;
|
||||
}
|
||||
|
||||
@@ -28,15 +28,13 @@ import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.support.ManagedList;
|
||||
import org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.core.Conventions;
|
||||
import org.springframework.integration.ConfigurationException;
|
||||
import org.springframework.integration.bus.DefaultMessageBus;
|
||||
import org.springframework.integration.bus.MessageBus;
|
||||
import org.springframework.integration.bus.MessageBusAwareBeanPostProcessor;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Parser for the <em>message-bus</em> element of the integration namespace.
|
||||
* Parser for the <message-bus> element of the integration namespace.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
* @author Marius Bogoevici
|
||||
@@ -47,8 +45,6 @@ public class MessageBusParser extends AbstractSimpleBeanDefinitionParser {
|
||||
|
||||
public static final String MESSAGE_BUS_AWARE_POST_PROCESSOR_BEAN_NAME = "internal.MessageBusAwareBeanPostProcessor";
|
||||
|
||||
private static final String ERROR_CHANNEL_ATTRIBUTE = "error-channel";
|
||||
|
||||
private static final String CHANNEL_FACTORY_ATTRIBUTE = "channel-factory";
|
||||
|
||||
private static final String INTERCEPTOR_ELEMENT = "interceptor";
|
||||
@@ -75,28 +71,18 @@ public class MessageBusParser extends AbstractSimpleBeanDefinitionParser {
|
||||
|
||||
@Override
|
||||
protected boolean isEligibleAttribute(String attributeName) {
|
||||
return !ERROR_CHANNEL_ATTRIBUTE.equals(attributeName) &&
|
||||
!CHANNEL_FACTORY_ATTRIBUTE.equals(attributeName) &&
|
||||
return !CHANNEL_FACTORY_ATTRIBUTE.equals(attributeName) &&
|
||||
super.isEligibleAttribute(attributeName);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void postProcess(BeanDefinitionBuilder beanDefinition, Element element) {
|
||||
String errorChannelRef = element.getAttribute(ERROR_CHANNEL_ATTRIBUTE);
|
||||
if (StringUtils.hasText(errorChannelRef)) {
|
||||
beanDefinition.addPropertyReference(Conventions.attributeNameToPropertyName(
|
||||
ERROR_CHANNEL_ATTRIBUTE), errorChannelRef);
|
||||
}
|
||||
String channelFactoryRef = element.getAttribute(CHANNEL_FACTORY_ATTRIBUTE);
|
||||
if (StringUtils.hasText(channelFactoryRef)) {
|
||||
beanDefinition.addPropertyReference(Conventions.attributeNameToPropertyName(
|
||||
CHANNEL_FACTORY_ATTRIBUTE), channelFactoryRef);
|
||||
}
|
||||
this.processChildElements(beanDefinition, element);
|
||||
protected void postProcess(BeanDefinitionBuilder builder, Element element) {
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, CHANNEL_FACTORY_ATTRIBUTE);
|
||||
this.processChildElements(builder, element);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void processChildElements(BeanDefinitionBuilder beanDefinition, Element element) {
|
||||
private void processChildElements(BeanDefinitionBuilder builder, Element element) {
|
||||
NodeList childNodes = element.getChildNodes();
|
||||
ManagedList interceptors = new ManagedList();
|
||||
for (int i = 0; i < childNodes.getLength(); i++) {
|
||||
@@ -109,7 +95,7 @@ public class MessageBusParser extends AbstractSimpleBeanDefinitionParser {
|
||||
}
|
||||
}
|
||||
if (interceptors.size() > 0) {
|
||||
beanDefinition.addPropertyValue(INTERCEPTORS_PROPERTY, interceptors);
|
||||
builder.addPropertyValue(INTERCEPTORS_PROPERTY, interceptors);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ public class PollableAnnotationPostProcessor extends AbstractAnnotationMethodPos
|
||||
if (channelAdapterAnnotation != null) {
|
||||
String channelName = channelAdapterAnnotation.value();
|
||||
PollableChannelAdapter adapter = new PollableChannelAdapter(channelName, source, null);
|
||||
this.getMessageBus().registerChannel(channelName, adapter);
|
||||
this.getMessageBus().registerChannel(adapter);
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ public class TargetAnnotationPostProcessor extends AbstractAnnotationMethodPostP
|
||||
if (channelAdapterAnnotation != null) {
|
||||
String channelName = channelAdapterAnnotation.value();
|
||||
PollableChannelAdapter adapter = new PollableChannelAdapter(channelName, null, target);
|
||||
this.getMessageBus().registerChannel(channelName, adapter);
|
||||
this.getMessageBus().registerChannel(adapter);
|
||||
}
|
||||
return target;
|
||||
}
|
||||
|
||||
@@ -34,7 +34,6 @@
|
||||
<xsd:attribute name="auto-startup" type="xsd:boolean"/>
|
||||
<xsd:attribute name="auto-create-channels" type="xsd:boolean"/>
|
||||
<xsd:attribute name="channel-factory" type="xsd:string"/>
|
||||
<xsd:attribute name="error-channel" type="xsd:string"/>
|
||||
<xsd:attribute name="dispatcher-pool-size" type="xsd:int"/>
|
||||
<xsd:attribute name="configure-async-event-multicaster" type="xsd:boolean"/>
|
||||
</xsd:complexType>
|
||||
|
||||
Reference in New Issue
Block a user