Removed ChannelRegistry. It has been replaced by the ChannelResolver strategy.

This commit is contained in:
Mark Fisher
2008-10-13 02:40:15 +00:00
parent 8419b48dcd
commit f99911cf89
13 changed files with 63 additions and 76 deletions

View File

@@ -19,7 +19,6 @@ 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;
@@ -37,7 +36,7 @@ public class DefaultErrorChannel extends RendezvousChannel {
public DefaultErrorChannel() {
this.addInterceptor(new ErrorLoggingInterceptor());
this.setBeanName(ChannelRegistry.ERROR_CHANNEL_NAME);
this.setBeanName(DefaultMessageBus.ERROR_CHANNEL_BEAN_NAME);
}

View File

@@ -35,7 +35,6 @@ import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.Lifecycle;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.integration.channel.ChannelRegistry;
import org.springframework.integration.channel.MessageChannel;
import org.springframework.integration.channel.MessagePublishingErrorHandler;
import org.springframework.integration.endpoint.MessageEndpoint;
@@ -54,6 +53,9 @@ import org.springframework.util.Assert;
*/
public class DefaultMessageBus implements MessageBus, ApplicationContextAware, ApplicationListener, DisposableBean {
public static final String ERROR_CHANNEL_BEAN_NAME = "errorChannel";
private final Log logger = LogFactory.getLog(this.getClass());
private final Set<MessageEndpoint> endpoints = new CopyOnWriteArraySet<MessageEndpoint>();
@@ -233,7 +235,7 @@ public class DefaultMessageBus implements MessageBus, ApplicationContextAware, A
}
if (this.taskScheduler instanceof SimpleTaskScheduler) {
((SimpleTaskScheduler) this.taskScheduler).setErrorHandler(
new MessagePublishingErrorHandler(this.lookupChannel(ChannelRegistry.ERROR_CHANNEL_NAME)));
new MessagePublishingErrorHandler(this.lookupChannel(ERROR_CHANNEL_BEAN_NAME)));
}
this.taskScheduler.start();
}

View File

@@ -17,7 +17,6 @@
package org.springframework.integration.bus;
import org.springframework.context.Lifecycle;
import org.springframework.integration.channel.ChannelRegistry;
import org.springframework.integration.endpoint.MessageEndpoint;
/**
@@ -25,7 +24,7 @@ import org.springframework.integration.endpoint.MessageEndpoint;
*
* @author Mark Fisher
*/
public interface MessageBus extends ChannelRegistry, Lifecycle {
public interface MessageBus extends Lifecycle {
void registerEndpoint(MessageEndpoint endpoint);

View File

@@ -1,30 +0,0 @@
/*
* 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.channel;
/**
* A strategy interface for registration and lookup of message channels by name.
*
* @author Mark Fisher
*/
public interface ChannelRegistry {
static final String ERROR_CHANNEL_NAME = "errorChannel";
MessageChannel lookupChannel(String channelName);
}

View File

@@ -22,12 +22,13 @@ import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.integration.annotation.ChannelAdapter;
import org.springframework.integration.annotation.Poller;
import org.springframework.integration.channel.ChannelRegistry;
import org.springframework.integration.channel.BeanFactoryChannelResolver;
import org.springframework.integration.channel.ChannelResolutionException;
import org.springframework.integration.channel.ChannelResolver;
import org.springframework.integration.channel.DirectChannel;
import org.springframework.integration.channel.MessageChannel;
import org.springframework.integration.channel.PollableChannel;
import org.springframework.integration.channel.SubscribableChannel;
import org.springframework.integration.config.xml.MessageBusParser;
import org.springframework.integration.endpoint.MessageEndpoint;
import org.springframework.integration.endpoint.PollingConsumerEndpoint;
import org.springframework.integration.endpoint.SourcePollingChannelAdapter;
@@ -48,28 +49,20 @@ public class ChannelAdapterAnnotationPostProcessor implements MethodAnnotationPo
private final ConfigurableBeanFactory beanFactory;
private final ChannelRegistry channelRegistry;
private final ChannelResolver channelResolver;
public ChannelAdapterAnnotationPostProcessor(ConfigurableBeanFactory beanFactory) {
Assert.notNull(beanFactory, "BeanFactory must not be null");
this.beanFactory = beanFactory;
this.channelRegistry = (ChannelRegistry)
this.beanFactory.getBean(MessageBusParser.MESSAGE_BUS_BEAN_NAME);
this.channelResolver = new BeanFactoryChannelResolver(this.beanFactory);
}
public Object postProcess(Object bean, String beanName, Method method, ChannelAdapter annotation) {
Assert.notNull(this.beanFactory, "BeanFactory must not be null");
MessageEndpoint endpoint = null;
String channelName = annotation.value();
MessageChannel channel = this.channelRegistry.lookupChannel(channelName);
if (channel == null) {
DirectChannel directChannel = new DirectChannel();
directChannel.setBeanName(channelName);
this.beanFactory.registerSingleton(channelName, directChannel);
channel = directChannel;
}
MessageChannel channel = this.resolveOrCreateChannel(annotation.value());
Poller pollerAnnotation = AnnotationUtils.findAnnotation(method, Poller.class);
if (method.getParameterTypes().length == 0 && hasReturnValue(method)) {
MethodInvokingSource source = new MethodInvokingSource();
@@ -94,6 +87,18 @@ public class ChannelAdapterAnnotationPostProcessor implements MethodAnnotationPo
return bean;
}
private MessageChannel resolveOrCreateChannel(String channelName) {
try {
return this.channelResolver.resolveChannelName(channelName);
}
catch (ChannelResolutionException e) {
DirectChannel directChannel = new DirectChannel();
directChannel.setBeanName(channelName);
this.beanFactory.registerSingleton(channelName, directChannel);
return directChannel;
}
}
private SourcePollingChannelAdapter createInboundChannelAdapter(MethodInvokingSource source, MessageChannel channel, Poller pollerAnnotation) {
Assert.notNull(pollerAnnotation, "The @Poller annotation is required (at method-level) "
+ "when using the @ChannelAdapter annotation with a no-arg method.");

View File

@@ -41,7 +41,6 @@ import org.springframework.core.task.TaskExecutor;
import org.springframework.integration.bus.DefaultMessageBus;
import org.springframework.integration.bus.MessageBus;
import org.springframework.integration.bus.MessageBusAwareBeanPostProcessor;
import org.springframework.integration.channel.ChannelRegistry;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.integration.config.annotation.MessagingAnnotationPostProcessor;
import org.springframework.integration.config.annotation.PublisherAnnotationPostProcessor;
@@ -101,10 +100,10 @@ public class MessageBusParser extends AbstractSimpleBeanDefinitionParser {
super.doParse(element, parserContext, builder);
String taskSchedulerRef = element.getAttribute(TASK_SCHEDULER_ATTRIBUTE);
TaskExecutor taskExecutor= null;
if (!parserContext.getRegistry().containsBeanDefinition(ChannelRegistry.ERROR_CHANNEL_NAME)) {
if (!parserContext.getRegistry().containsBeanDefinition(DefaultMessageBus.ERROR_CHANNEL_BEAN_NAME)) {
RootBeanDefinition errorChannelDef = new RootBeanDefinition(QueueChannel.class);
BeanDefinitionHolder errorChannelHolder = new BeanDefinitionHolder(
errorChannelDef, ChannelRegistry.ERROR_CHANNEL_NAME);
errorChannelDef, DefaultMessageBus.ERROR_CHANNEL_BEAN_NAME);
BeanDefinitionReaderUtils.registerBeanDefinition(errorChannelHolder, parserContext.getRegistry());
}
if (StringUtils.hasText(taskSchedulerRef)) {

View File

@@ -34,6 +34,8 @@ import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.integration.annotation.Gateway;
import org.springframework.integration.bus.MessageBus;
import org.springframework.integration.channel.BeanFactoryChannelResolver;
import org.springframework.integration.channel.ChannelResolver;
import org.springframework.integration.channel.MessageChannel;
import org.springframework.integration.channel.PollableChannel;
import org.springframework.integration.config.xml.MessageBusParser;
@@ -72,6 +74,8 @@ public class GatewayProxyFactoryBean implements FactoryBean, MethodInterceptor,
private volatile MessageBus messageBus;
private ChannelResolver channelResolver;
private volatile boolean initialized;
private final Object initializationMonitor = new Object();
@@ -137,6 +141,7 @@ public class GatewayProxyFactoryBean implements FactoryBean, MethodInterceptor,
public void setBeanFactory(BeanFactory beanFactory) {
this.messageBus = (MessageBus) beanFactory.getBean(MessageBusParser.MESSAGE_BUS_BEAN_NAME);
this.channelResolver = new BeanFactoryChannelResolver(beanFactory);
}
public void afterPropertiesSet() throws Exception {
@@ -225,12 +230,12 @@ public class GatewayProxyFactoryBean implements FactoryBean, MethodInterceptor,
Assert.state(this.messageBus != null, "MessageBus is required for channel resolution");
String requestChannelName = gatewayAnnotation.requestChannel();
if (StringUtils.hasText(requestChannelName)) {
requestChannel = this.messageBus.lookupChannel(requestChannelName);
requestChannel = this.channelResolver.resolveChannelName(requestChannelName);
Assert.notNull(requestChannel, "failed to resolve request channel '" + requestChannelName + "'");
}
String replyChannelName = gatewayAnnotation.replyChannel();
if (StringUtils.hasText(replyChannelName)) {
replyChannel = this.messageBus.lookupChannel(replyChannelName);
replyChannel = this.channelResolver.resolveChannelName(replyChannelName);
Assert.notNull(replyChannel, "failed to resolve reply channel '" + replyChannelName + "'");
}
requestTimeout = gatewayAnnotation.requestTimeout();