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:
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -315,6 +315,7 @@ public class GatewayProxyFactoryBean extends AbstractEndpoint implements Factory
|
||||
if (this.getBeanFactory() != null) {
|
||||
gateway.setBeanFactory(this.getBeanFactory());
|
||||
}
|
||||
gateway.afterPropertiesSet();
|
||||
return gateway;
|
||||
}
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user