ChannelFactory now accepts the channel name (INT-280).

This commit is contained in:
Mark Fisher
2008-07-05 22:59:25 +00:00
parent 9b787a0d5a
commit 5d25b93461
6 changed files with 60 additions and 11 deletions

View File

@@ -19,6 +19,7 @@ package org.springframework.integration.bus;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
@@ -37,8 +38,11 @@ import org.springframework.util.Assert;
* an ApplicationContext.
*
* @author Marius Bogoevici
* @author Mark Fisher
*/
public class DefaultChannelFactoryBean implements ApplicationContextAware, FactoryBean {
public class DefaultChannelFactoryBean implements ApplicationContextAware, FactoryBean, BeanNameAware {
private volatile String beanName;
private volatile ChannelFactory channelFactory;
@@ -52,6 +56,10 @@ public class DefaultChannelFactoryBean implements ApplicationContextAware, Facto
}
public void setBeanName(String beanName) {
this.beanName = beanName;
}
@SuppressWarnings("unchecked")
public void setApplicationContext(ApplicationContext applicationContext){
Map map = applicationContext.getBeansOfType(MessageBus.class);
@@ -70,7 +78,7 @@ public class DefaultChannelFactoryBean implements ApplicationContextAware, Facto
public Object getObject() throws Exception {
Assert.notNull(channelFactory, "ChannelFactory not set on this instance. Is this used within an ApplicationContext?");
return channelFactory.getChannel(dispatcherPolicy, interceptors);
return channelFactory.getChannel(this.beanName, dispatcherPolicy, interceptors);
}
public Class<?> getObjectType() {

View File

@@ -368,7 +368,7 @@ public class MessageBus implements ChannelRegistry, EndpointRegistry,
if (this.logger.isInfoEnabled()) {
logger.info("auto-creating channel '" + channelName + "'");
}
channel = channelFactory.getChannel(null, null);
channel = channelFactory.getChannel(channelName, null, null);
this.registerChannel(channelName, channel);
}
return channel;

View File

@@ -35,11 +35,14 @@ public abstract class AbstractChannelFactory implements ChannelFactory {
super();
}
public final MessageChannel getChannel(DispatcherPolicy dispatcherPolicy, List<ChannelInterceptor> interceptors) {
public final MessageChannel getChannel(String name, DispatcherPolicy dispatcherPolicy, List<ChannelInterceptor> interceptors) {
AbstractMessageChannel channel = createChannelInternal(dispatcherPolicy);
if (null != interceptors) {
channel.setInterceptors(interceptors);
}
if (name != null && channel.getName() == null) {
channel.setName(name);
}
return channel;
}

View File

@@ -24,14 +24,14 @@ import org.springframework.integration.channel.MessageChannel;
/**
* Interface for a channel factory.
*
* @author Marius Bogoevici
*/
public interface ChannelFactory {
/**
* Creates a channel, based on the provided dispatcher policy, and with the given interceptors.
* @return
* Creates a channel based on the provided name, dispatcher policy, and interceptors.
*/
MessageChannel getChannel(DispatcherPolicy dispatcherPolicy, List<ChannelInterceptor> interceptors);
MessageChannel getChannel(String name, DispatcherPolicy dispatcherPolicy, List<ChannelInterceptor> interceptors);
}