This commit is contained in:
Mark Fisher
2010-07-27 13:22:25 +00:00
parent c20d8729db
commit 53132b2376

View File

@@ -26,19 +26,31 @@ import org.springframework.integration.context.NamedComponent;
import org.springframework.integration.core.Message;
import org.springframework.integration.core.MessageChannel;
import org.springframework.integration.message.MessageHandler;
import org.springframework.util.Assert;
/**
* This components is responsible for maintaining the history of {@link MessageChannel}s and
* {@link MessageHandler}s
* There can only be ine instance of this class per ApplicationContext hierarchy
* otherwise the Exception will be thrown.
* This component is responsible for maintaining the history of {@link MessageChannel}s and
* {@link MessageHandler}s. There can only be one instance of this class per ApplicationContext
* hierarchy otherwise an Exception will be thrown.
*
* @author Oleg Zhurakousky
* @since 2.0
*/
public class MessageHistoryWriter implements BeanFactoryAware, InitializingBean{
private BeanFactory beanFactory;
private volatile BeanFactory beanFactory;
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
this.beanFactory = beanFactory;
}
public void afterPropertiesSet() throws Exception {
Assert.notNull(this.beanFactory, "BeanFactory is required");
if (BeanFactoryUtils.beansOfTypeIncludingAncestors((ListableBeanFactory) this.beanFactory, MessageHistoryWriter.class).size() > 1) {
throw new IllegalArgumentException("more than one MessageHistoryWriter exists in the context");
}
}
public void writeHistory(NamedComponent component, Message<?> message) {
if (message != null) {
@@ -46,14 +58,4 @@ public class MessageHistoryWriter implements BeanFactoryAware, InitializingBean{
}
}
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
this.beanFactory = beanFactory;
}
public void afterPropertiesSet() throws Exception {
if (BeanFactoryUtils.beansOfTypeIncludingAncestors((ListableBeanFactory)this.beanFactory, MessageHistoryWriter.class).size() > 1){
throw new IllegalArgumentException("Attempt to register more then one MessageHistoryWriter");
}
}
}