diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/MessageHistoryParser.java b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/MessageHistoryParser.java index 80f44bd5d5..82873a59c8 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/MessageHistoryParser.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/MessageHistoryParser.java @@ -30,12 +30,12 @@ import org.springframework.beans.factory.xml.ParserContext; */ public class MessageHistoryParser extends AbstractSimpleBeanDefinitionParser { - private static final String POST_PROCESSOR_CLASSNAME = "org.springframework.integration.history.MessageHistoryBeanPostProcessor"; + private static final String CONFIGURER_CLASSNAME = "org.springframework.integration.history.MessageHistoryConfigurer"; @Override protected String getBeanClassName(Element element) { - return POST_PROCESSOR_CLASSNAME; + return CONFIGURER_CLASSNAME; } @Override @@ -44,10 +44,10 @@ public class MessageHistoryParser extends AbstractSimpleBeanDefinitionParser { } protected String resolveId(Element element, AbstractBeanDefinition definition, ParserContext parserContext) { - if (parserContext.getRegistry().containsBeanDefinition(POST_PROCESSOR_CLASSNAME)) { - throw new BeanDefinitionStoreException("At most one MessageHistoryBeanPostProcessor may be registered within a context."); + if (parserContext.getRegistry().containsBeanDefinition(CONFIGURER_CLASSNAME)) { + throw new BeanDefinitionStoreException("At most one MessageHistoryConfigurer may be registered within a context."); } - return POST_PROCESSOR_CLASSNAME; + return CONFIGURER_CLASSNAME; } } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/gateway/GatewayProxyFactoryBean.java b/spring-integration-core/src/main/java/org/springframework/integration/gateway/GatewayProxyFactoryBean.java index c3db143892..e8cbaaf703 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/gateway/GatewayProxyFactoryBean.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/gateway/GatewayProxyFactoryBean.java @@ -46,6 +46,7 @@ import org.springframework.integration.history.TrackableComponent; import org.springframework.integration.mapping.InboundMessageMapper; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; +import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; /** @@ -161,6 +162,11 @@ public class GatewayProxyFactoryBean extends AbstractEndpoint implements Trackab public void setShouldTrack(boolean shouldTrack) { this.shouldTrack = shouldTrack; + if (!CollectionUtils.isEmpty(this.gatewayMap)) { + for (SimpleMessagingGateway gateway : this.gatewayMap.values()) { + gateway.setShouldTrack(shouldTrack); + } + } } public void setTypeConverter(TypeConverter typeConverter) { diff --git a/spring-integration-core/src/main/java/org/springframework/integration/history/MessageHistoryBeanPostProcessor.java b/spring-integration-core/src/main/java/org/springframework/integration/history/MessageHistoryBeanPostProcessor.java deleted file mode 100644 index a70dac7047..0000000000 --- a/spring-integration-core/src/main/java/org/springframework/integration/history/MessageHistoryBeanPostProcessor.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2002-2010 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.history; - -import org.springframework.beans.BeansException; -import org.springframework.beans.factory.config.BeanPostProcessor; - -/** - * @author Mark Fisher - * @since 2.0 - */ -//TODO: check name against pattern (include/exclude filters?), and check type as well? -public class MessageHistoryBeanPostProcessor implements BeanPostProcessor { - - public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { - if (bean instanceof TrackableComponent) { - ((TrackableComponent) bean).setShouldTrack(true); - } - return bean; - } - - public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { - if (bean instanceof TrackableComponent) { - ((TrackableComponent) bean).setShouldTrack(true); - } - return bean; - } - -} diff --git a/spring-integration-core/src/main/java/org/springframework/integration/history/MessageHistoryConfigurer.java b/spring-integration-core/src/main/java/org/springframework/integration/history/MessageHistoryConfigurer.java new file mode 100644 index 0000000000..9d2931ae3b --- /dev/null +++ b/spring-integration-core/src/main/java/org/springframework/integration/history/MessageHistoryConfigurer.java @@ -0,0 +1,103 @@ +/* + * Copyright 2002-2010 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.history; + +import java.util.Map; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.BeanFactory; +import org.springframework.beans.factory.BeanFactoryAware; +import org.springframework.beans.factory.BeanFactoryUtils; +import org.springframework.beans.factory.ListableBeanFactory; +import org.springframework.context.SmartLifecycle; +import org.springframework.util.Assert; +import org.springframework.util.PatternMatchUtils; + +/** + * @author Mark Fisher + * @since 2.0 + */ +public class MessageHistoryConfigurer implements SmartLifecycle, BeanFactoryAware { + + private final Log logger = LogFactory.getLog(this.getClass()); + + private volatile String[] componentNamePatterns = new String[] { "*" }; + + private volatile BeanFactory beanFactory; + + private volatile boolean running; + + private volatile boolean autoStartup = true; + + private int phase = Integer.MIN_VALUE; + + + public void setComponentNamePatterns(String[] componentNamePatterns) { + Assert.notEmpty(componentNamePatterns, "componentNamePatterns must not be empty"); + this.componentNamePatterns = componentNamePatterns; + } + + public void setBeanFactory(BeanFactory beanFactory) throws BeansException { + this.beanFactory = beanFactory; + } + + + /* + * SmartLifecycle implementation + */ + + public boolean isRunning() { + return this.running; + } + + public boolean isAutoStartup() { + return this.autoStartup; + } + + public int getPhase() { + return this.phase; + } + + public void start() { + if (this.beanFactory != null && this.beanFactory instanceof ListableBeanFactory) { + Map trackableComponents = BeanFactoryUtils.beansOfTypeIncludingAncestors( + (ListableBeanFactory) this.beanFactory, TrackableComponent.class); + for (TrackableComponent component : trackableComponents.values()) { + String componentName = component.getComponentName(); + boolean shouldTrack = PatternMatchUtils.simpleMatch(this.componentNamePatterns, componentName); + component.setShouldTrack(shouldTrack); + if (shouldTrack && this.logger.isInfoEnabled()) { + this.logger.info("Enabling MessageHistory tracking for component '" + componentName + "'"); + } + } + } + this.running = true; + } + + public void stop() { + this.running = false; + } + + public void stop(Runnable callback) { + this.stop(); + callback.run(); + } + +} diff --git a/spring-integration-core/src/test/java/org/springframework/integration/history/messageHistoryWithHistoryWriter.xml b/spring-integration-core/src/test/java/org/springframework/integration/history/messageHistoryWithHistoryWriter.xml index 7b42faf2af..ac44330c3b 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/history/messageHistoryWithHistoryWriter.xml +++ b/spring-integration-core/src/test/java/org/springframework/integration/history/messageHistoryWithHistoryWriter.xml @@ -30,6 +30,6 @@ - + diff --git a/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/MessageHistoryTests-context.xml b/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/MessageHistoryTests-context.xml index c52d5b71ef..feb8a28483 100644 --- a/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/MessageHistoryTests-context.xml +++ b/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/MessageHistoryTests-context.xml @@ -40,6 +40,6 @@ - +