Removed MessageBusAware and MessageBusAwareBeanPostProcessor.

This commit is contained in:
Mark Fisher
2008-10-31 23:30:02 +00:00
parent 14d892e044
commit dae343a07f
7 changed files with 6 additions and 162 deletions

View File

@@ -1,28 +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.bus;
/**
* Interface to be implemented by classes which need access to the {@link MessageBus}.
*
* @author Marius Bogoevici
*/
public interface MessageBusAware {
public void setMessageBus(MessageBus messageBus);
}

View File

@@ -1,56 +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.bus;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.util.Assert;
/**
* A bean post processor which injects all {@link MessageBusAware} beans with a
* reference to the {@link MessageBus}.
*
* @author Marius Bogoevici
* @author Mark Fisher
*/
public class MessageBusAwareBeanPostProcessor implements BeanPostProcessor {
private final MessageBus messageBus;
public MessageBusAwareBeanPostProcessor(MessageBus messageBus) {
Assert.notNull(messageBus, "'messageBus' must not be null");
this.messageBus = messageBus;
}
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
return postProcessIfNecessary(bean);
}
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
return postProcessIfNecessary(bean);
}
private Object postProcessIfNecessary(Object bean) {
if (bean instanceof MessageBusAware) {
((MessageBusAware) bean).setMessageBus(this.messageBus);
}
return bean;
}
}

View File

@@ -24,7 +24,6 @@ import org.w3c.dom.Element;
import org.springframework.beans.factory.BeanDefinitionStoreException;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanDefinitionHolder;
import org.springframework.beans.factory.parsing.BeanComponentDefinition;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
@@ -36,7 +35,6 @@ import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.core.task.TaskExecutor;
import org.springframework.integration.bus.ApplicationContextMessageBus;
import org.springframework.integration.bus.MessageBus;
import org.springframework.integration.bus.MessageBusAwareBeanPostProcessor;
import org.springframework.integration.channel.MessagePublishingErrorHandler;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.integration.config.annotation.MessagingAnnotationPostProcessor;
@@ -58,9 +56,6 @@ public class MessageBusParser extends AbstractSimpleBeanDefinitionParser {
public static final String TASK_SCHEDULER_BEAN_NAME = "taskScheduler";
public static final String MESSAGE_BUS_AWARE_POST_PROCESSOR_BEAN_NAME =
"internal.MessageBusAwareBeanPostProcessor";
private static final String MESSAGING_ANNOTATION_POST_PROCESSOR_BEAN_NAME =
"internal.MessagingAnnotationPostProcessor";
@@ -150,24 +145,16 @@ public class MessageBusParser extends AbstractSimpleBeanDefinitionParser {
* Adds extra post-processors to the context, to inject the objects configured by the MessageBus
*/
private void addPostProcessors(Element element, ParserContext parserContext) {
this.registerMessageBusAwarePostProcessor(parserContext);
if ("true".equals(element.getAttribute("enable-annotations").toLowerCase())) {
this.registerMessagingAnnotationPostProcessor(parserContext);
}
}
private void registerMessageBusAwarePostProcessor(ParserContext parserContext) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(MessageBusAwareBeanPostProcessor.class);
builder.addConstructorArgReference(MessageBusParser.MESSAGE_BUS_BEAN_NAME);
builder.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
parserContext.getRegistry().registerBeanDefinition(MESSAGE_BUS_AWARE_POST_PROCESSOR_BEAN_NAME, builder.getBeanDefinition());
}
private void registerMessagingAnnotationPostProcessor(ParserContext parserContext) {
BeanDefinition bd = new RootBeanDefinition(MessagingAnnotationPostProcessor.class);
BeanComponentDefinition bcd = new BeanComponentDefinition(
bd, MESSAGING_ANNOTATION_POST_PROCESSOR_BEAN_NAME);
parserContext.registerBeanComponent(bcd);
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(MessagingAnnotationPostProcessor.class);
builder.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
parserContext.getRegistry().registerBeanDefinition(
MESSAGING_ANNOTATION_POST_PROCESSOR_BEAN_NAME, builder.getBeanDefinition());
}
}

View File

@@ -297,13 +297,6 @@ public class ApplicationContextMessageBusTests {
messageBus.resolveChannelName("noSuchChannel");
}
@Test
public void messageBusAware() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("messageBusTests.xml", this.getClass());
TestMessageBusAwareImpl messageBusAwareBean = (TestMessageBusAwareImpl) context.getBean("messageBusAwareBean");
assertTrue(messageBusAwareBean.getMessageBus() == context.getBean("bus"));
}
private static class FailingSource implements MessageSource<Object> {

View File

@@ -1,33 +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.bus;
/**
* @author Marius Bogoevici
*/
public class TestMessageBusAwareImpl implements MessageBusAware {
private MessageBus messageBus;
public void setMessageBus(MessageBus messageBus) {
this.messageBus = messageBus;
}
public MessageBus getMessageBus() {
return messageBus;
}
}

View File

@@ -29,10 +29,4 @@
<bean id="handler" class="org.springframework.integration.message.TestHandlers" factory-method="echoHandler"/>
<bean class="org.springframework.integration.bus.MessageBusAwareBeanPostProcessor">
<constructor-arg ref="bus"/>
</bean>
<bean id= "messageBusAwareBean" class="org.springframework.integration.bus.TestMessageBusAwareImpl"/>
</beans>

View File

@@ -33,7 +33,6 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.task.SyncTaskExecutor;
import org.springframework.integration.bus.ApplicationContextMessageBus;
import org.springframework.integration.bus.MessageBus;
import org.springframework.integration.bus.TestMessageBusAwareImpl;
import org.springframework.integration.bus.MessageBusEventTests.TestMessageBusListener;
import org.springframework.integration.config.xml.MessageBusParser;
import org.springframework.integration.core.MessageChannel;
@@ -85,12 +84,8 @@ public class MessageBusParserTests {
}
catch (BeanCreationException e) {
exceptionThrown = true;
// an exception is thrown when creating the post-processor, which
// tries to get a reference to the message bus
assertEquals(BeanCreationException.class, e.getCause().getClass());
assertEquals(e.getBeanName(), MessageBusParser.MESSAGE_BUS_AWARE_POST_PROCESSOR_BEAN_NAME);
assertEquals(IllegalStateException.class, (e.getCause()).getCause().getClass());
assertEquals(((BeanCreationException) e.getCause()).getBeanName(), MessageBusParser.MESSAGE_BUS_BEAN_NAME);
assertEquals(IllegalStateException.class, e.getCause().getClass());
assertEquals(e.getBeanName(), MessageBusParser.MESSAGE_BUS_BEAN_NAME);
}
assertTrue(exceptionThrown);
}
@@ -104,14 +99,6 @@ public class MessageBusParserTests {
bus.stop();
}
@Test
public void testMessageBusAwareAutomaticallyAddedByNamespace() {
ApplicationContext context = new ClassPathXmlApplicationContext(
"messageBusWithMessageBusAware.xml", this.getClass());
TestMessageBusAwareImpl messageBusAware = (TestMessageBusAwareImpl) context.getBean("messageBusAwareBean");
assertTrue(messageBusAware.getMessageBus() == context.getBean(MessageBusParser.MESSAGE_BUS_BEAN_NAME));
}
@Test
public void testMulticasterIsSyncByDefault() {
ApplicationContext context = new ClassPathXmlApplicationContext(