From f3d3f4ee4b5f9472ca33236c8895bdc87dcb47f4 Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Mon, 23 Sep 2013 16:09:53 +0300 Subject: [PATCH] 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 --- .../config/spring-integration-amqp-3.0.xsd | 25 +- .../xml/AbstractChannelAdapterParser.java | 18 +- .../xml/AbstractConsumerEndpointParser.java | 19 +- .../AbstractOutboundChannelAdapterParser.java | 2 - ...actPollingInboundChannelAdapterParser.java | 2 - .../integration/config/xml/ChainParser.java | 2 - .../config/xml/IntegrationNamespaceUtils.java | 2 + .../handler/MessageHandlerChain.java | 32 +- .../config/xml/spring-integration-3.0.xsd | 80 +- .../integration/config/ChainParserTests.java | 9 +- .../src/main/resources/.svnignore | 0 .../config/spring-integration-event-3.0.xsd | 32 +- .../config/spring-integration-feed-3.0.xsd | 26 +- .../FileTailInboundChannelAdapterParser.java | 2 - .../config/spring-integration-file-3.0.xsd | 84 +- .../ftp/config/spring-integration-ftp-3.0.xsd | 13 +- .../xml/spring-integration-gemfire-3.0.xsd | 15 +- .../config/spring-integration-http-3.0.xsd | 31 +- .../ip/config/IpAdapterParserUtils.java | 7 +- ...ctionEventInboundChannelAdapterParser.java | 5 +- .../TcpInboundChannelAdapterParser.java | 9 +- .../TcpOutboundChannelAdapterParser.java | 4 - .../ip/config/TcpOutboundGatewayParser.java | 9 +- .../ip/tcp/TcpSendingMessageHandler.java | 24 +- .../ip/config/spring-integration-ip-3.0.xsd | 920 ++++++++++-------- .../ip/config/ParserUnitTests-context.xml | 2 + .../ip/config/ParserUnitTests.java | 11 +- .../config/spring-integration-jdbc-3.0.xsd | 68 +- .../jms/config/spring-integration-jms-3.0.xsd | 22 +- .../jmx/config/spring-integration-jmx-3.0.xsd | 4 +- .../config/xml/spring-integration-jpa-3.0.xsd | 12 +- .../config/ImapIdleChannelAdapterParser.java | 4 +- .../config/spring-integration-mail-3.0.xsd | 41 +- .../config/spring-integration-mongodb-3.0.xsd | 14 +- .../RedisInboundChannelAdapterParser.java | 3 +- .../config/spring-integration-redis-3.0.xsd | 35 +- .../rmi/config/spring-integration-rmi-3.0.xsd | 2 +- .../config/spring-integration-sftp-3.0.xsd | 13 +- .../config/spring-integration-stream-3.0.xsd | 24 +- .../SyslogInboundChannelAdapterParser.java | 5 +- .../config/spring-integration-syslog-3.0.xsd | 203 ++-- .../config/spring-integration-twitter-3.0.xsd | 36 +- .../ws/config/spring-integration-ws-3.0.xsd | 2 +- ...stractXmppInboundChannelAdapterParser.java | 8 +- .../xmpp/config/XmppConnectionParser.java | 9 +- .../config/spring-integration-xmpp-3.0.xsd | 54 +- 46 files changed, 757 insertions(+), 1187 deletions(-) delete mode 100644 spring-integration-event/src/main/resources/.svnignore diff --git a/spring-integration-amqp/src/main/resources/org/springframework/integration/amqp/config/spring-integration-amqp-3.0.xsd b/spring-integration-amqp/src/main/resources/org/springframework/integration/amqp/config/spring-integration-amqp-3.0.xsd index f07cf095f8..794e061d23 100644 --- a/spring-integration-amqp/src/main/resources/org/springframework/integration/amqp/config/spring-integration-amqp-3.0.xsd +++ b/spring-integration-amqp/src/main/resources/org/springframework/integration/amqp/config/spring-integration-amqp-3.0.xsd @@ -366,14 +366,6 @@ - - - - Flag to indicate whether this Message Channel should start automatically. - This only applies to a message-driven channel. Default is true. - - - @@ -566,13 +558,6 @@ standard headers to also be mapped. - - - - - @@ -722,15 +707,6 @@ standard headers to also be mapped. - - - - - The lifeycle phase determining the start/stop order of the underlying listener container. - - - - @@ -815,6 +791,7 @@ standard headers to also be mapped. + diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/AbstractChannelAdapterParser.java b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/AbstractChannelAdapterParser.java index 163579330c..dd54c51aac 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/AbstractChannelAdapterParser.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/AbstractChannelAdapterParser.java @@ -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. @@ -18,8 +18,10 @@ package org.springframework.integration.config.xml; import org.w3c.dom.Element; +import org.springframework.beans.MutablePropertyValues; import org.springframework.beans.factory.BeanDefinitionStoreException; import org.springframework.beans.factory.config.BeanDefinitionHolder; +import org.springframework.beans.factory.config.TypedStringValue; import org.springframework.beans.factory.support.AbstractBeanDefinition; import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.support.BeanDefinitionReaderUtils; @@ -30,7 +32,7 @@ import org.springframework.util.StringUtils; /** * Base parser for Channel Adapters. - * + *

* Includes logic to determine {@link org.springframework.integration.MessageChannel}: * if 'channel' attribute is defined - uses its value as 'channelName'; * if 'id' attribute is defined - creates {@link DirectChannel} at runtime and uses id's value as 'channelName'; @@ -63,7 +65,17 @@ public abstract class AbstractChannelAdapterParser extends AbstractBeanDefinitio if (!StringUtils.hasText(channelName)) { channelName = this.createDirectChannel(element, parserContext); } - return doParse(element, parserContext, channelName); + AbstractBeanDefinition beanDefinition = doParse(element, parserContext, channelName); + MutablePropertyValues propertyValues = beanDefinition.getPropertyValues(); + String autoStartup = element.getAttribute(IntegrationNamespaceUtils.AUTO_STARTUP); + if (StringUtils.hasText(autoStartup)) { + propertyValues.add("autoStartup", new TypedStringValue(autoStartup)); + } + String phase = element.getAttribute(IntegrationNamespaceUtils.PHASE); + if (StringUtils.hasText(phase)) { + propertyValues.add("phase", new TypedStringValue(phase)); + } + return beanDefinition; } private String createDirectChannel(Element element, ParserContext parserContext) { diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/AbstractConsumerEndpointParser.java b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/AbstractConsumerEndpointParser.java index 805a90bb24..7c3a8c414b 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/AbstractConsumerEndpointParser.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/AbstractConsumerEndpointParser.java @@ -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. @@ -19,6 +19,8 @@ package org.springframework.integration.config.xml; import java.util.Collection; import java.util.List; +import org.w3c.dom.Element; + import org.springframework.beans.factory.BeanDefinitionStoreException; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.ConstructorArgumentValues; @@ -34,7 +36,6 @@ import org.springframework.integration.config.ConsumerEndpointFactoryBean; import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; import org.springframework.util.xml.DomUtils; -import org.w3c.dom.Element; /** * Base class parser for elements that create Message Endpoints. @@ -96,7 +97,8 @@ public abstract class AbstractConsumerEndpointParser extends AbstractBeanDefinit + elementDescription + ".", element); } return handlerBeanDefinition; - } else { + } + else { if (!hasInputChannelAttribute) { String elementDescription = IntegrationNamespaceUtils.createElementDescription(element); parserContext.getReaderContext().error("The '" + inputChannelAttributeName @@ -115,18 +117,18 @@ public abstract class AbstractConsumerEndpointParser extends AbstractBeanDefinit String inputChannelName = element.getAttribute(inputChannelAttributeName); - if (!parserContext.getRegistry().containsBeanDefinition(inputChannelName)){ - if (parserContext.getRegistry().containsBeanDefinition(ChannelInitializer.AUTO_CREATE_CHANNEL_CANDIDATES_BEAN_NAME)){ + if (!parserContext.getRegistry().containsBeanDefinition(inputChannelName)) { + if (parserContext.getRegistry().containsBeanDefinition(ChannelInitializer.AUTO_CREATE_CHANNEL_CANDIDATES_BEAN_NAME)) { BeanDefinition channelRegistry = parserContext.getRegistry(). getBeanDefinition(ChannelInitializer.AUTO_CREATE_CHANNEL_CANDIDATES_BEAN_NAME); ConstructorArgumentValues caValues = channelRegistry.getConstructorArgumentValues(); ValueHolder vh = caValues.getArgumentValue(0, Collection.class); - if (vh == null){ //although it should never happen if it does we can fix it + if (vh == null) { //although it should never happen if it does we can fix it caValues.addIndexedArgumentValue(0, new ManagedSet()); } @SuppressWarnings("unchecked") - Collection channelCandidateNames = (Collection) caValues.getArgumentValue(0, Collection.class).getValue(); + Collection channelCandidateNames = (Collection) caValues.getArgumentValue(0, Collection.class).getValue(); channelCandidateNames.add(inputChannelName); } else { @@ -144,7 +146,8 @@ public abstract class AbstractConsumerEndpointParser extends AbstractBeanDefinit } IntegrationNamespaceUtils.configurePollerMetadata(pollerElementList.get(0), builder, parserContext); } - IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "auto-startup"); + IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, IntegrationNamespaceUtils.AUTO_STARTUP); + IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, IntegrationNamespaceUtils.PHASE); AbstractBeanDefinition beanDefinition = builder.getBeanDefinition(); String beanName = this.resolveId(element, beanDefinition, parserContext); parserContext.registerBeanComponent(new BeanComponentDefinition(beanDefinition, beanName)); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/AbstractOutboundChannelAdapterParser.java b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/AbstractOutboundChannelAdapterParser.java index 5f16c3738a..614bbf922c 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/AbstractOutboundChannelAdapterParser.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/AbstractOutboundChannelAdapterParser.java @@ -71,8 +71,6 @@ public abstract class AbstractOutboundChannelAdapterParser extends AbstractChann IntegrationNamespaceUtils.configurePollerMetadata(pollerElement, builder, parserContext); } builder.addPropertyValue("inputChannelName", channelName); - IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "auto-startup"); - IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "phase"); this.configureRequestHandlerAdviceChain(element, parserContext, handlerBeanComponentDefinition.getBeanDefinition(), builder); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/AbstractPollingInboundChannelAdapterParser.java b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/AbstractPollingInboundChannelAdapterParser.java index 6e6002a55b..7a672c9297 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/AbstractPollingInboundChannelAdapterParser.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/AbstractPollingInboundChannelAdapterParser.java @@ -49,8 +49,6 @@ public abstract class AbstractPollingInboundChannelAdapterParser extends Abstrac if (pollerElement != null) { IntegrationNamespaceUtils.configurePollerMetadata(pollerElement, adapterBuilder, parserContext); } - IntegrationNamespaceUtils.setValueIfAttributeDefined(adapterBuilder, element, "auto-startup"); - IntegrationNamespaceUtils.setValueIfAttributeDefined(adapterBuilder, element, "phase"); return adapterBuilder.getBeanDefinition(); } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/ChainParser.java b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/ChainParser.java index 63788d145e..b179a94db4 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/ChainParser.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/ChainParser.java @@ -99,8 +99,6 @@ public class ChainParser extends AbstractConsumerEndpointParser { } builder.addPropertyValue("handlers", handlerList); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "send-timeout"); - IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "auto-startup"); - IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "phase"); return builder; } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/IntegrationNamespaceUtils.java b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/IntegrationNamespaceUtils.java index 160e2a3564..4d98b70048 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/IntegrationNamespaceUtils.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/IntegrationNamespaceUtils.java @@ -65,6 +65,8 @@ public abstract class IntegrationNamespaceUtils { static final String EXPRESSION_ATTRIBUTE = "expression"; public static final String HANDLER_ALIAS_SUFFIX = ".handler"; public static final String REQUEST_HANDLER_ADVICE_CHAIN = "request-handler-advice-chain"; + public static final String AUTO_STARTUP = "auto-startup"; + public static final String PHASE = "phase"; /** * Property name on ChannelInitializer used to configure the default max subscribers for diff --git a/spring-integration-core/src/main/java/org/springframework/integration/handler/MessageHandlerChain.java b/spring-integration-core/src/main/java/org/springframework/integration/handler/MessageHandlerChain.java index e52c4d393b..3d891ceb2b 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/handler/MessageHandlerChain.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/handler/MessageHandlerChain.java @@ -22,7 +22,7 @@ import java.util.concurrent.locks.ReentrantLock; import org.springframework.beans.DirectFieldAccessor; import org.springframework.beans.factory.BeanFactory; -import org.springframework.context.SmartLifecycle; +import org.springframework.context.Lifecycle; import org.springframework.integration.Message; import org.springframework.integration.MessageChannel; import org.springframework.integration.MessageHandlingException; @@ -66,7 +66,7 @@ import org.springframework.util.Assert; * @author Gary Russell * @author Artem Bilan */ -public class MessageHandlerChain extends AbstractMessageHandler implements MessageProducer, SmartLifecycle { +public class MessageHandlerChain extends AbstractMessageHandler implements MessageProducer, Lifecycle { private volatile List handlers; @@ -85,10 +85,6 @@ public class MessageHandlerChain extends AbstractMessageHandler implements Messa private final Object initializationMonitor = new Object(); - private volatile boolean autoStartup = true; - - private volatile int phase = Integer.MAX_VALUE; - private volatile boolean running; private final ReentrantLock lifecycleLock = new ReentrantLock(); @@ -176,14 +172,6 @@ public class MessageHandlerChain extends AbstractMessageHandler implements Messa * SmartLifecycle implementation (delegates to the {@link #handlers}) */ - public final boolean isAutoStartup() { - return this.autoStartup; - } - - public final int getPhase() { - return this.phase; - } - public final boolean isRunning() { this.lifecycleLock.lock(); try { @@ -237,26 +225,18 @@ public class MessageHandlerChain extends AbstractMessageHandler implements Messa } } - public void setAutoStartup(boolean autoStartup) { - this.autoStartup = autoStartup; - } - - public void setPhase(int phase) { - this.phase = phase; - } - private void doStop() { for (MessageHandler handler : this.handlers) { - if (handler instanceof SmartLifecycle) { - ((SmartLifecycle) handler).stop(); + if (handler instanceof Lifecycle) { + ((Lifecycle) handler).stop(); } } } private void doStart() { for (MessageHandler handler : this.handlers) { - if (handler instanceof SmartLifecycle) { - ((SmartLifecycle) handler).start(); + if (handler instanceof Lifecycle) { + ((Lifecycle) handler).start(); } } } diff --git a/spring-integration-core/src/main/resources/org/springframework/integration/config/xml/spring-integration-3.0.xsd b/spring-integration-core/src/main/resources/org/springframework/integration/config/xml/spring-integration-3.0.xsd index 7ea44de1ea..8d8eb42dca 100644 --- a/spring-integration-core/src/main/resources/org/springframework/integration/config/xml/spring-integration-3.0.xsd +++ b/spring-integration-core/src/main/resources/org/springframework/integration/config/xml/spring-integration-3.0.xsd @@ -877,13 +877,6 @@ - - - - Lifecycle attribute signaling if this component should be started during Application Context startup. - - - @@ -907,6 +900,7 @@ + @@ -1041,23 +1035,7 @@ - - - - Lifecycle attribute signaling if this component should be started during Application Context startup. - - - - - - - - The Lifecycle attribute determining the start/stop order - of the underlying MessageHandlerChain. - - - - + @@ -1552,16 +1530,6 @@ - - - - - The Lifecycle attribute determining the start/stop order - of the underlying MessageHandlerChain. - - - - @@ -3066,17 +3034,6 @@ --> - - - - Lifecycle attribute signaling if this component should be - started during Application Context startup. Defaults to true. - - - - - - @@ -3099,6 +3056,7 @@ ]]> +