ChannelFactory now accepts the channel name (INT-280).
This commit is contained in:
@@ -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() {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user