From 27ba48abf0a8795de52256f26afba29f2f8dfba2 Mon Sep 17 00:00:00 2001 From: Oleg Zhurakousky Date: Mon, 26 Jul 2010 02:31:29 +0000 Subject: [PATCH] INT-1257 Moved history writing logic to IntegrationObjectSupport which has a capability to cache historyWriter instead of doing a look up every time. --- .../channel/AbstractMessageChannel.java | 3 ++- .../context/IntegrationObjectSupport.java | 16 +++++++++++++++- .../gateway/GatewayProxyFactoryBean.java | 1 + .../gateway/SimpleMessagingGateway.java | 2 +- .../handler/AbstractMessageHandler.java | 2 +- .../integration/history/MessageHistory.java | 10 ---------- 6 files changed, 20 insertions(+), 14 deletions(-) diff --git a/spring-integration-core/src/main/java/org/springframework/integration/channel/AbstractMessageChannel.java b/spring-integration-core/src/main/java/org/springframework/integration/channel/AbstractMessageChannel.java index 67728973b6..6d4bf73ef8 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/channel/AbstractMessageChannel.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/channel/AbstractMessageChannel.java @@ -26,6 +26,7 @@ import org.apache.commons.logging.LogFactory; import org.springframework.core.OrderComparator; import org.springframework.core.convert.ConversionService; import org.springframework.integration.context.IntegrationObjectSupport; +import org.springframework.integration.context.NamedComponent; import org.springframework.integration.core.Message; import org.springframework.integration.core.MessageChannel; import org.springframework.integration.core.MessagingException; @@ -158,7 +159,7 @@ public abstract class AbstractMessageChannel extends IntegrationObjectSupport im * time or the sending thread is interrupted. */ public final boolean send(Message message, long timeout) { - MessageHistory.writeMessageHistory(message, this, this.getBeanFactory()); + this.writeMessageHistory(message, this); Assert.notNull(message, "message must not be null"); Assert.notNull(message.getPayload(), "message payload must not be null"); message = this.convertPayloadIfNecessary(message); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/context/IntegrationObjectSupport.java b/spring-integration-core/src/main/java/org/springframework/integration/context/IntegrationObjectSupport.java index 3cc5ddbce9..1a0bc6521f 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/context/IntegrationObjectSupport.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/context/IntegrationObjectSupport.java @@ -26,6 +26,8 @@ import org.springframework.beans.factory.InitializingBean; import org.springframework.core.convert.ConversionService; import org.springframework.integration.channel.BeanFactoryChannelResolver; import org.springframework.integration.channel.ChannelResolver; +import org.springframework.integration.core.Message; +import org.springframework.integration.history.MessageHistoryWriter; import org.springframework.scheduling.TaskScheduler; import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -46,6 +48,8 @@ public abstract class IntegrationObjectSupport implements BeanNameAware, NamedCo /** Logger that is available to subclasses */ protected final Log logger = LogFactory.getLog(getClass()); + + private volatile MessageHistoryWriter historyWriter; private volatile String beanName; @@ -101,6 +105,11 @@ public abstract class IntegrationObjectSupport implements BeanNameAware, NamedCo } throw new BeanInitializationException("failed to initialize", e); } + if (this.beanFactory != null){ + if (this.beanFactory.containsBean(MessageHistoryWriter.HISTORY_WRITER_BEAN_NAME)){ + historyWriter = this.beanFactory.getBean(MessageHistoryWriter.HISTORY_WRITER_BEAN_NAME, MessageHistoryWriter.class); + } + } } /** @@ -157,5 +166,10 @@ public abstract class IntegrationObjectSupport implements BeanNameAware, NamedCo public String toString() { return (this.beanName != null) ? this.beanName : super.toString(); } - + + protected void writeMessageHistory(Message message, NamedComponent component){ + if (historyWriter != null){ + historyWriter.writeHistory(component, message); + } + } } 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 b85566fbbe..6d7fb04bd2 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 @@ -315,6 +315,7 @@ public class GatewayProxyFactoryBean extends AbstractEndpoint implements Factory if (this.getBeanFactory() != null) { gateway.setBeanFactory(this.getBeanFactory()); } + gateway.afterPropertiesSet(); return gateway; } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/gateway/SimpleMessagingGateway.java b/spring-integration-core/src/main/java/org/springframework/integration/gateway/SimpleMessagingGateway.java index 66ca3882ae..887094520b 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/gateway/SimpleMessagingGateway.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/gateway/SimpleMessagingGateway.java @@ -81,7 +81,7 @@ public class SimpleMessagingGateway extends AbstractMessagingGateway { Message message = null; try { message = this.inboundMapper.toMessage(object); - MessageHistory.writeMessageHistory(message, this, this.getBeanFactory()); + this.writeMessageHistory(message, this); } catch (Exception e) { if (e instanceof RuntimeException) { diff --git a/spring-integration-core/src/main/java/org/springframework/integration/handler/AbstractMessageHandler.java b/spring-integration-core/src/main/java/org/springframework/integration/handler/AbstractMessageHandler.java index 2488de36a6..d8abd7d25a 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/handler/AbstractMessageHandler.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/handler/AbstractMessageHandler.java @@ -62,7 +62,7 @@ public abstract class AbstractMessageHandler extends IntegrationObjectSupport im public final void handleMessage(Message message) { Assert.notNull(message, "Message must not be null"); Assert.notNull(message.getPayload(), "Message payload must not be null"); - MessageHistory.writeMessageHistory(message, this, this.getBeanFactory()); + this.writeMessageHistory(message, this); if (this.logger.isDebugEnabled()) { this.logger.debug(this + " received message: " + message); } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/history/MessageHistory.java b/spring-integration-core/src/main/java/org/springframework/integration/history/MessageHistory.java index 190d287382..4243255267 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/history/MessageHistory.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/history/MessageHistory.java @@ -78,14 +78,4 @@ public class MessageHistory implements Iterable, Serializab public String toString() { return new ArrayList(events).toString(); } - - public static void writeMessageHistory(Message message, NamedComponent component, BeanFactory beanFactory){ - if (beanFactory != null){ - if (beanFactory.containsBean(MessageHistoryWriter.HISTORY_WRITER_BEAN_NAME)){ - MessageHistoryWriter writer = - beanFactory.getBean(MessageHistoryWriter.HISTORY_WRITER_BEAN_NAME, MessageHistoryWriter.class); - writer.writeHistory(component, message); - } - } - } }