added NamedComponent interface, continuing simplification of MessageHistory
This commit is contained in:
@@ -56,13 +56,6 @@ public abstract class AbstractMessageChannel extends IntegrationObjectSupport im
|
||||
private final ChannelInterceptorList interceptors = new ChannelInterceptorList();
|
||||
|
||||
|
||||
/**
|
||||
* Return the name of this channel.
|
||||
*/
|
||||
public String getName() {
|
||||
return this.getBeanName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getComponentType() {
|
||||
return "channel";
|
||||
@@ -169,7 +162,7 @@ public abstract class AbstractMessageChannel extends IntegrationObjectSupport im
|
||||
Assert.notNull(message, "message must not be null");
|
||||
Assert.notNull(message.getPayload(), "message payload must not be null");
|
||||
message = this.convertPayloadIfNecessary(message);
|
||||
message.getHeaders().getHistory().addEvent(this.getBeanName(), this.getComponentType());
|
||||
message.getHeaders().getHistory().addEvent(this);
|
||||
message = this.interceptors.preSend(message, this);
|
||||
if (message == null) {
|
||||
return false;
|
||||
@@ -188,7 +181,7 @@ public abstract class AbstractMessageChannel extends IntegrationObjectSupport im
|
||||
throw (MessagingException) e;
|
||||
}
|
||||
throw new MessageDeliveryException(message,
|
||||
"failed to send Message to channel '" + this.getName() + "'", e);
|
||||
"failed to send Message to channel '" + this.getComponentName() + "'", e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -209,7 +202,7 @@ public abstract class AbstractMessageChannel extends IntegrationObjectSupport im
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new MessageDeliveryException(message, "Channel '" + this.getName() +
|
||||
throw new MessageDeliveryException(message, "Channel '" + this.getComponentName() +
|
||||
"' expected one of the following datataypes [" +
|
||||
StringUtils.arrayToCommaDelimitedString(this.datatypes) +
|
||||
"], but received [" + message.getPayload().getClass() + "]");
|
||||
|
||||
@@ -24,7 +24,6 @@ import org.springframework.beans.factory.BeanFactoryAware;
|
||||
import org.springframework.beans.factory.BeanInitializationException;
|
||||
import org.springframework.beans.factory.BeanNameAware;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.NamedBean;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.integration.channel.BeanFactoryChannelResolver;
|
||||
import org.springframework.integration.channel.ChannelResolver;
|
||||
@@ -42,7 +41,7 @@ import org.springframework.util.Assert;
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public abstract class IntegrationObjectSupport implements BeanNameAware, NamedBean, BeanFactoryAware, InitializingBean {
|
||||
public abstract class IntegrationObjectSupport implements BeanNameAware, NamedComponent, BeanFactoryAware, InitializingBean {
|
||||
|
||||
/** Logger that is available to subclasses */
|
||||
protected final Log logger = LogFactory.getLog(getClass());
|
||||
@@ -62,7 +61,8 @@ public abstract class IntegrationObjectSupport implements BeanNameAware, NamedBe
|
||||
this.beanName = beanName;
|
||||
}
|
||||
|
||||
public final String getBeanName() {
|
||||
|
||||
public final String getComponentName() {
|
||||
return this.beanName;
|
||||
}
|
||||
|
||||
@@ -129,7 +129,7 @@ public abstract class IntegrationObjectSupport implements BeanNameAware, NamedBe
|
||||
this.conversionService = IntegrationContextUtils.getConversionService(this.beanFactory);
|
||||
if (this.conversionService == null && logger.isDebugEnabled()) {
|
||||
logger.debug("Unable to attempt conversion of Message payload types. Component '" +
|
||||
this.getBeanName() + "' has no explicit ConversionService reference, " +
|
||||
this.getComponentName() + "' has no explicit ConversionService reference, " +
|
||||
"and there is no 'integrationConversionService' bean within the context.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* 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.context;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
* @since 2.0
|
||||
*/
|
||||
public interface NamedComponent {
|
||||
|
||||
String getComponentName();
|
||||
|
||||
String getComponentType();
|
||||
|
||||
}
|
||||
@@ -50,7 +50,7 @@ public class EventDrivenConsumer extends AbstractEndpoint {
|
||||
protected void doStart() {
|
||||
synchronized (this.initializationMonitor) {
|
||||
if (this.handlerInvocationChain == null) {
|
||||
this.handlerInvocationChain = new HandlerInvocationChain(this.handler, this.getBeanName());
|
||||
this.handlerInvocationChain = new HandlerInvocationChain(this.handler, this.getComponentName());
|
||||
}
|
||||
}
|
||||
this.inputChannel.subscribe(this.handlerInvocationChain);
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.springframework.integration.endpoint;
|
||||
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.integration.context.IntegrationObjectSupport;
|
||||
import org.springframework.integration.context.NamedComponent;
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.message.MessageHandler;
|
||||
|
||||
@@ -33,16 +34,15 @@ class HandlerInvocationChain implements MessageHandler, Ordered {
|
||||
|
||||
private final MessageHandler handler;
|
||||
|
||||
private final String endpointName;
|
||||
|
||||
private final String handlerType;
|
||||
private final EndpointNamedComponent namedComponent;
|
||||
|
||||
|
||||
public HandlerInvocationChain(MessageHandler handler, String endpointName) {
|
||||
this.handler = handler;
|
||||
this.endpointName = endpointName;
|
||||
this.handlerType = (handler instanceof IntegrationObjectSupport) ?
|
||||
String handlerType = (handler instanceof IntegrationObjectSupport) ?
|
||||
((IntegrationObjectSupport) this.handler).getComponentType() : null;
|
||||
this.namedComponent = (endpointName != null) ?
|
||||
new EndpointNamedComponent(endpointName, handlerType) : null;
|
||||
}
|
||||
|
||||
|
||||
@@ -52,10 +52,31 @@ class HandlerInvocationChain implements MessageHandler, Ordered {
|
||||
}
|
||||
|
||||
public void handleMessage(Message<?> message) {
|
||||
if (message != null && this.endpointName != null) {
|
||||
message.getHeaders().getHistory().addEvent(this.endpointName, this.handlerType);
|
||||
if (message != null && this.namedComponent != null) {
|
||||
message.getHeaders().getHistory().addEvent(this.namedComponent);
|
||||
}
|
||||
this.handler.handleMessage(message);
|
||||
}
|
||||
|
||||
|
||||
private static class EndpointNamedComponent implements NamedComponent {
|
||||
|
||||
private final String componentName;
|
||||
|
||||
private final String componentType;
|
||||
|
||||
private EndpointNamedComponent(String componentName, String componentType) {
|
||||
this.componentName = componentName;
|
||||
this.componentType = componentType;
|
||||
}
|
||||
|
||||
public String getComponentName() {
|
||||
return this.componentName;
|
||||
}
|
||||
|
||||
public String getComponentType() {
|
||||
return this.componentType;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ public abstract class MessageProducerSupport extends AbstractEndpoint implements
|
||||
|
||||
protected boolean sendMessage(Message<?> message) {
|
||||
if (message != null) {
|
||||
message.getHeaders().getHistory().addEvent(this.getBeanName(), this.getComponentType());
|
||||
message.getHeaders().getHistory().addEvent(this);
|
||||
}
|
||||
return this.channelTemplate.send(message, this.outputChannel);
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ public class PollingConsumer extends AbstractPollingEndpoint {
|
||||
protected void onInit() {
|
||||
synchronized (this.initializationMonitor) {
|
||||
if (!this.initialized) {
|
||||
this.handlerInvocationChain = new HandlerInvocationChain(this.handler, this.getBeanName());
|
||||
this.handlerInvocationChain = new HandlerInvocationChain(this.handler, this.getComponentName());
|
||||
}
|
||||
this.initialized = true;
|
||||
}
|
||||
|
||||
@@ -253,10 +253,11 @@ public class GatewayProxyFactoryBean extends AbstractEndpoint implements Factory
|
||||
|
||||
private SimpleMessagingGateway createGatewayForMethod(Method method) {
|
||||
SimpleMessagingGateway gateway = new SimpleMessagingGateway(
|
||||
new ArgumentArrayMessageMapper(method, this.getBeanName()), new SimpleMessageMapper());
|
||||
new ArgumentArrayMessageMapper(method), new SimpleMessageMapper());
|
||||
if (this.getTaskScheduler() != null) {
|
||||
gateway.setTaskScheduler(this.getTaskScheduler());
|
||||
}
|
||||
gateway.setBeanName(this.getComponentName());
|
||||
Gateway gatewayAnnotation = method.getAnnotation(Gateway.class);
|
||||
MessageChannel requestChannel = this.defaultRequestChannel;
|
||||
MessageChannel replyChannel = this.defaultReplyChannel;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* 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.
|
||||
@@ -70,7 +70,11 @@ public class SimpleMessagingGateway extends AbstractMessagingGateway {
|
||||
@Override
|
||||
protected Message<?> toMessage(Object object) {
|
||||
try {
|
||||
return this.inboundMapper.toMessage(object);
|
||||
Message<?> message = this.inboundMapper.toMessage(object);
|
||||
if (message != null) {
|
||||
message.getHeaders().getHistory().addEvent(this);
|
||||
}
|
||||
return message;
|
||||
}
|
||||
catch (Exception e) {
|
||||
if (e instanceof RuntimeException) {
|
||||
|
||||
@@ -122,15 +122,11 @@ public class ArgumentArrayMessageMapper implements InboundMessageMapper<Object[]
|
||||
|
||||
private final List<MethodParameter> parameterList;
|
||||
|
||||
private final String gatewayName;
|
||||
|
||||
|
||||
public ArgumentArrayMessageMapper(Method method, String gatewayName) {
|
||||
public ArgumentArrayMessageMapper(Method method) {
|
||||
Assert.notNull(method, "method must not be null");
|
||||
Assert.notNull(gatewayName, "gatewayName must not be null");
|
||||
this.method = method;
|
||||
this.parameterList = this.getMethodParameterList(method);
|
||||
this.gatewayName = gatewayName;
|
||||
}
|
||||
|
||||
public Message<?> toMessage(Object[] arguments) {
|
||||
@@ -140,11 +136,7 @@ public class ArgumentArrayMessageMapper implements InboundMessageMapper<Object[]
|
||||
throw new IllegalArgumentException(prefix + " parameters provided for method [" + method +
|
||||
"], expected " + this.parameterList.size() + " but received " + arguments.length + ".");
|
||||
}
|
||||
Message<?> message = this.mapArgumentsToMessage(arguments);
|
||||
if (message != null) {
|
||||
message.getHeaders().getHistory().addEvent(this.gatewayName, "gateway");
|
||||
}
|
||||
return message;
|
||||
return this.mapArgumentsToMessage(arguments);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
@@ -22,6 +22,7 @@ import java.util.Iterator;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
|
||||
import org.springframework.integration.context.NamedComponent;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
@@ -40,7 +41,9 @@ public class MessageHistory implements Iterable<MessageHistoryEvent>, Serializab
|
||||
/**
|
||||
* Add a new event with the provided component metadata.
|
||||
*/
|
||||
public MessageHistoryEvent addEvent(String name, String type) {
|
||||
public MessageHistoryEvent addEvent(NamedComponent component) {
|
||||
String name = component.getComponentName();
|
||||
String type = component.getComponentType();
|
||||
if (name != null && !StringUtils.startsWithIgnoreCase(name, "org.springframework")) {
|
||||
MessageHistoryEvent event = new MessageHistoryEvent(name, type);
|
||||
this.events.add(event);
|
||||
|
||||
Reference in New Issue
Block a user