INT-2998: Channel Adapters' Lifecycle Refactoring

* Add XSD attributeGroup `smartLifeCycleAttributeGroup`
* Use it for all adapters tags
* Refactoring `AbstractChannelAdapterParser` hierarchy
* Refactoring some `MessageHandler`'s that should not have `autoStartup` & `phase`.
    It is the responsibility of `AbstrctEndpoint`
* Polishing some tests according new logic

JIRA: https://jira.springsource.org/browse/INT-2998

INT-2998: Polishing

Polishing

 - Reformat schemas where indentation changed
 - Add SLC to the UDP inbound adapter
This commit is contained in:
Artem Bilan
2013-09-23 16:09:53 +03:00
committed by Gary Russell
parent e8ecbac7fd
commit f3d3f4ee4b
46 changed files with 757 additions and 1187 deletions

View File

@@ -16,12 +16,13 @@
package org.springframework.integration.ip.config;
import org.w3c.dom.Element;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.integration.config.xml.IntegrationNamespaceUtils;
import org.springframework.util.StringUtils;
import org.w3c.dom.Element;
/**
* Utility methods and constants for IP adapter parsers.
@@ -103,10 +104,6 @@ public abstract class IpAdapterParserUtils {
public static final String LOOKUP_HOST = "lookup-host";
public static final String AUTO_STARTUP = "auto-startup";
public static final String PHASE = "phase";
public static final String APPLY_SEQUENCE = "apply-sequence";
public static final String CLIENT_MODE = "client-mode";

View File

@@ -16,13 +16,14 @@
package org.springframework.integration.ip.config;
import org.w3c.dom.Element;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.integration.config.xml.AbstractChannelAdapterParser;
import org.springframework.integration.config.xml.IntegrationNamespaceUtils;
import org.springframework.integration.ip.tcp.connection.TcpConnectionEventListeningMessageProducer;
import org.w3c.dom.Element;
/**
* @author Gary Russell
@@ -37,8 +38,6 @@ public class TcpConnectionEventInboundChannelAdapterParser extends AbstractChann
adapterBuilder.addPropertyReference("outputChannel", channelName);
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(adapterBuilder, element, "error-channel", "errorChannel");
IntegrationNamespaceUtils.setValueIfAttributeDefined(adapterBuilder, element, "event-types");
IntegrationNamespaceUtils.setValueIfAttributeDefined(adapterBuilder, element, "auto-startup");
IntegrationNamespaceUtils.setValueIfAttributeDefined(adapterBuilder, element, "phase");
return adapterBuilder.getBeanDefinition();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2013 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.
@@ -16,13 +16,14 @@
package org.springframework.integration.ip.config;
import org.w3c.dom.Element;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.integration.config.xml.AbstractChannelAdapterParser;
import org.springframework.integration.config.xml.IntegrationNamespaceUtils;
import org.springframework.integration.ip.tcp.TcpReceivingChannelAdapter;
import org.w3c.dom.Element;
/**
* Channel Adapter that receives TCP stream frames and maps them to Messages.
@@ -40,10 +41,6 @@ public class TcpInboundChannelAdapterParser extends AbstractChannelAdapterParser
builder.addPropertyReference("outputChannel", channelName);
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder,
element, "error-channel", "errorChannel");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element,
IpAdapterParserUtils.AUTO_STARTUP);
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element,
IpAdapterParserUtils.PHASE);
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element,
IpAdapterParserUtils.CLIENT_MODE);
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element,

View File

@@ -36,10 +36,6 @@ public class TcpOutboundChannelAdapterParser extends AbstractOutboundChannelAdap
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(TcpSendingMessageHandler.class);
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element,
IpAdapterParserUtils.TCP_CONNECTION_FACTORY);
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element,
IpAdapterParserUtils.AUTO_STARTUP);
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element,
IpAdapterParserUtils.PHASE);
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element,
IpAdapterParserUtils.CLIENT_MODE);
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element,

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2013 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.
@@ -16,11 +16,12 @@
package org.springframework.integration.ip.config;
import org.w3c.dom.Element;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.integration.config.xml.AbstractConsumerEndpointParser;
import org.springframework.integration.config.xml.IntegrationNamespaceUtils;
import org.w3c.dom.Element;
/**
* Parser for the <outbound-gateway> element of the integration 'jms' namespace.
@@ -52,9 +53,9 @@ public class TcpOutboundGatewayParser extends AbstractConsumerEndpointParser {
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element,
IpAdapterParserUtils.REPLY_TIMEOUT, "sendTimeout");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element,
IpAdapterParserUtils.AUTO_STARTUP);
IntegrationNamespaceUtils.AUTO_STARTUP);
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element,
IpAdapterParserUtils.PHASE);
IntegrationNamespaceUtils.PHASE);
return builder;
}

View File

@@ -20,7 +20,7 @@ import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ScheduledFuture;
import org.springframework.context.SmartLifecycle;
import org.springframework.context.Lifecycle;
import org.springframework.integration.Message;
import org.springframework.integration.MessageHandlingException;
import org.springframework.integration.handler.AbstractMessageHandler;
@@ -45,7 +45,7 @@ import org.springframework.util.Assert;
*
*/
public class TcpSendingMessageHandler extends AbstractMessageHandler implements
TcpSender, SmartLifecycle, ClientModeCapable {
TcpSender, Lifecycle, ClientModeCapable {
private volatile AbstractConnectionFactory clientConnectionFactory;
@@ -53,10 +53,6 @@ public class TcpSendingMessageHandler extends AbstractMessageHandler implements
private Map<String, TcpConnection> connections = new ConcurrentHashMap<String, TcpConnection>();
private volatile boolean autoStartup = true;
private volatile int phase;
private volatile boolean isClientMode;
private volatile long retryInterval = 60000;
@@ -245,14 +241,6 @@ public class TcpSendingMessageHandler extends AbstractMessageHandler implements
return this.active;
}
public int getPhase() {
return this.phase;
}
public boolean isAutoStartup() {
return this.autoStartup;
}
public void stop(Runnable callback) {
synchronized (this.lifecycleMonitor) {
if (this.active) {
@@ -271,14 +259,6 @@ public class TcpSendingMessageHandler extends AbstractMessageHandler implements
}
}
public void setAutoStartup(boolean autoStartup) {
this.autoStartup = autoStartup;
}
public void setPhase(int phase) {
this.phase = phase;
}
/**
* @return the clientConnectionFactory
*/

View File

@@ -37,6 +37,8 @@
task-executor="externalTE"
error-channel="errorChannel"
lookup-host="false"
auto-startup="false"
phase="1234"
/>
<ip:udp-inbound-channel-adapter id="testInUdpMulticast"

View File

@@ -46,6 +46,7 @@ import org.springframework.integration.channel.DirectChannel;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.integration.core.MessageHandler;
import org.springframework.integration.core.MessagingTemplate;
import org.springframework.integration.endpoint.AbstractEndpoint;
import org.springframework.integration.endpoint.EventDrivenConsumer;
import org.springframework.integration.handler.advice.AbstractRequestHandlerAdvice;
import org.springframework.integration.ip.tcp.TcpInboundGateway;
@@ -111,6 +112,10 @@ public class ParserUnitTests {
@Qualifier(value="testOutUdpiMulticast.handler")
MulticastSendingMessageHandler udpOutMulticast;
@Autowired
@Qualifier(value="testOutTcpNio")
AbstractEndpoint tcpOutEndpoint;
@Autowired
@Qualifier(value="testOutTcpNio.handler")
TcpSendingMessageHandler tcpOut;
@@ -288,6 +293,8 @@ public class ParserUnitTests {
DatagramPacketMessageMapper mapper = (DatagramPacketMessageMapper) dfa.getPropertyValue("mapper");
DirectFieldAccessor mapperAccessor = new DirectFieldAccessor(mapper);
assertFalse((Boolean)mapperAccessor.getPropertyValue("lookupHost"));
assertFalse(TestUtils.getPropertyValue(udpIn, "autoStartup", Boolean.class));
assertEquals(1234, dfa.getPropertyValue("phase"));
}
@Test
@@ -431,8 +438,8 @@ public class ParserUnitTests {
assertEquals("ip:tcp-outbound-channel-adapter", tcpOut.getComponentType());
assertFalse(cfC1.isLookupHost());
assertEquals(35, dfa.getPropertyValue("order"));
assertFalse(tcpOut.isAutoStartup());
assertEquals(125, tcpOut.getPhase());
assertFalse(tcpOutEndpoint.isAutoStartup());
assertEquals(125, tcpOutEndpoint.getPhase());
assertFalse((Boolean) TestUtils.getPropertyValue(
TestUtils.getPropertyValue(cfC1, "mapper"), "applySequence"));
}