INT-1257 Moved history writing logic to IntegrationObjectSupport which has a capability to cache historyWriter instead of doing a look up every time.

This commit is contained in:
Oleg Zhurakousky
2010-07-26 02:31:29 +00:00
parent a7b107cc21
commit 27ba48abf0
6 changed files with 20 additions and 14 deletions

View File

@@ -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);

View File

@@ -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);
}
}
}

View File

@@ -315,6 +315,7 @@ public class GatewayProxyFactoryBean extends AbstractEndpoint implements Factory
if (this.getBeanFactory() != null) {
gateway.setBeanFactory(this.getBeanFactory());
}
gateway.afterPropertiesSet();
return gateway;
}

View File

@@ -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) {

View File

@@ -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);
}

View File

@@ -78,14 +78,4 @@ public class MessageHistory implements Iterable<MessageHistoryEvent>, Serializab
public String toString() {
return new ArrayList<MessageHistoryEvent>(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);
}
}
}
}