INT-629 Now registering a NullChannel with bean name "nullChannel" by default when the namespace support is enabled.

This commit is contained in:
Mark Fisher
2009-06-27 15:18:42 +00:00
parent 3186fd351c
commit c95e5da209
3 changed files with 36 additions and 12 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2008 the original author or authors.
* Copyright 2002-2009 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.
@@ -21,6 +21,7 @@ import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.integration.core.Message;
import org.springframework.integration.selector.MessageSelector;
@@ -32,16 +33,19 @@ import org.springframework.integration.selector.MessageSelector;
*
* @author Mark Fisher
*/
public class NullChannel implements PollableChannel {
public class NullChannel implements PollableChannel, BeanNameAware {
private Log logger = LogFactory.getLog(this.getClass());
private final Log logger = LogFactory.getLog(this.getClass());
private volatile String beanName;
/**
* Always returns <code>null</code>.
*/
public void setBeanName(String beanName) {
this.beanName = beanName;
}
public String getName() {
return null;
return this.beanName;
}
public List<Message<?>> clear() {
@@ -54,7 +58,7 @@ public class NullChannel implements PollableChannel {
public Message<?> receive() {
if (logger.isDebugEnabled()) {
logger.debug("receive called on null-channel");
logger.debug("receive called on null channel");
}
return null;
}
@@ -65,7 +69,7 @@ public class NullChannel implements PollableChannel {
public boolean send(Message<?> message) {
if (logger.isDebugEnabled()) {
logger.debug("message sent to null-channel: " + message);
logger.debug("message sent to null channel: " + message);
}
return true;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2008 the original author or authors.
* Copyright 2002-2009 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.
@@ -33,7 +33,8 @@ import org.springframework.integration.context.IntegrationContextUtils;
/**
* A {@link BeanFactoryPostProcessor} implementation that provides default
* beans for the error handling and task scheduling if those beans have not
* already been explicitly defined within the registry.
* already been explicitly defined within the registry. It also registers a
* single null channel with the bean name "nullChannel".
*
* @author Mark Fisher
*/
@@ -45,6 +46,7 @@ class DefaultConfiguringBeanFactoryPostProcessor implements BeanFactoryPostProce
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
if (beanFactory instanceof BeanDefinitionRegistry) {
BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory;
this.registerNullChannel(registry);
this.registerErrorChannelIfNecessary(registry);
this.registerTaskSchedulerIfNecessary(registry);
}
@@ -55,6 +57,22 @@ class DefaultConfiguringBeanFactoryPostProcessor implements BeanFactoryPostProce
}
}
/**
* Register a null channel in the given BeanDefinitionRegistry. The bean name is
* defined by the constant {@link IntegrationContextUtils#NULL_CHANNEL_BEAN_NAME}.
*/
private void registerNullChannel(BeanDefinitionRegistry registry) {
if (registry.isBeanNameInUse(IntegrationContextUtils.NULL_CHANNEL_BEAN_NAME)) {
throw new IllegalStateException("The bean name '" +
IntegrationContextUtils.NULL_CHANNEL_BEAN_NAME + "' is reserved.");
}
RootBeanDefinition nullChannelDef = new RootBeanDefinition();
nullChannelDef.setBeanClassName(IntegrationNamespaceUtils.BASE_PACKAGE + ".channel.NullChannel");
BeanDefinitionHolder nullChannelHolder = new BeanDefinitionHolder(
nullChannelDef, IntegrationContextUtils.NULL_CHANNEL_BEAN_NAME);
BeanDefinitionReaderUtils.registerBeanDefinition(nullChannelHolder, registry);
}
/**
* Register an error channel in the given BeanDefinitionRegistry if not yet present.
* The bean name for which this is checking is defined by the constant

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2008 the original author or authors.
* Copyright 2002-2009 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.
@@ -36,6 +36,8 @@ public abstract class IntegrationContextUtils {
public static final String ERROR_CHANNEL_BEAN_NAME = "errorChannel";
public static final String NULL_CHANNEL_BEAN_NAME = "nullChannel";
public static final String DEFAULT_POLLER_METADATA_BEAN_NAME = "org.springframework.integration.context.defaultPollerMetadata";