diff --git a/build.gradle b/build.gradle index e09f675bd..3d5b11b11 100644 --- a/build.gradle +++ b/build.gradle @@ -107,7 +107,7 @@ ext { springAmqpVersion = '1.3.0.RC1' springBatchAdminMgrVersion = '1.3.0.M1' springBatchVersion = '3.0.0.M3' - springBootVersion = '1.0.0.RC5' + springBootVersion = '1.0.0.BUILD-SNAPSHOT' springCloudVersion = '0.9.2' springDataCommonsVersion = '1.6.2.RELEASE' springDataGemfireVersion = '1.3.2.RELEASE' @@ -120,7 +120,7 @@ ext { springIntegrationVersion = '4.0.0.BUILD-SNAPSHOT' springPluginVersion = '0.8.0.RELEASE' springShellVersion = '1.1.0.BUILD-SNAPSHOT' - springVersion = '4.0.2.RELEASE' + springVersion = '4.0.3.RELEASE' tomcatJdbcPoolVersion = '7.0.42' tomcatVersion = '7.0.35' uuidVersion = '3.2' diff --git a/spring-xd-module/src/main/java/org/springframework/xd/module/core/SimpleModule.java b/spring-xd-module/src/main/java/org/springframework/xd/module/core/SimpleModule.java index 80d0797ab..807dbe60e 100644 --- a/spring-xd-module/src/main/java/org/springframework/xd/module/core/SimpleModule.java +++ b/spring-xd-module/src/main/java/org/springframework/xd/module/core/SimpleModule.java @@ -29,7 +29,6 @@ import org.springframework.beans.factory.DisposableBean; import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; -import org.springframework.boot.builder.ParentContextApplicationContextInitializer.ParentContextAvailableEvent; import org.springframework.boot.builder.ParentContextCloserApplicationListener; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.context.ContextIdApplicationContextInitializer; @@ -48,7 +47,6 @@ import org.springframework.validation.BindException; import org.springframework.xd.module.DeploymentMetadata; import org.springframework.xd.module.ModuleDefinition; -import org.springframework.xd.module.ModuleType; import org.springframework.xd.module.options.ModuleOptions; import org.springframework.xd.module.options.PassthruModuleOptionsMetadata; @@ -64,6 +62,49 @@ */ public class SimpleModule extends AbstractModule { + /** + * Dedicated sublcass of {@link ParentContextCloserApplicationListener} used to create its own version of + * ContextCloserListener that is aware of module order. Special care is taken so that no strong references to the + * module context are retained (this is a *static* inner class). + * + * @author Eric Bottard + */ + private static final class ModuleParentContextCloserApplicationListener extends + ParentContextCloserApplicationListener { + + private final int index; + + public ModuleParentContextCloserApplicationListener(int index) { + this.index = index; + } + + @Override + protected ContextCloserListener createContextCloserListener(ConfigurableApplicationContext child) { + return new ModuleContextCloserListener(child, index); + } + + /** + * Module context closer listener that sets the order based on the module deployment index. + */ + final static class ModuleContextCloserListener extends ContextCloserListener implements Ordered { + + private int index; + + public ModuleContextCloserListener(ConfigurableApplicationContext moduleContext, int index) { + super(moduleContext); + this.index = index; + } + + @Override + public int getOrder() { + // Make sure producer modules get closed before the consumer modules (sink/processor) + // by setting them the highest precedence. Smaller values come first. + return index; + } + + } + } + private final Log logger = LogFactory.getLog(this.getClass()); private ConfigurableApplicationContext context; @@ -197,45 +238,7 @@ public void initialize() { if (this.listeners.size() > 0) { application.listeners(this.listeners.toArray(new ApplicationListener[this.listeners.size()])); } - this.application.listeners(new ParentContextCloserApplicationListener() { - - @Override - public void onApplicationEvent(ParentContextAvailableEvent event) { - ConfigurableApplicationContext child = event.getApplicationContext(); - if (child.getParent() instanceof ConfigurableApplicationContext) { - ConfigurableApplicationContext parent = (ConfigurableApplicationContext) child - .getParent(); - parent.addApplicationListener(new ModuleContextCloserListener(child)); - } - } - - /** - * Module context closer listener that sets the order based on {@link ModuleType} - */ - final class ModuleContextCloserListener extends ContextCloserListener implements Ordered { - - public ModuleContextCloserListener(ConfigurableApplicationContext moduleContext) { - super(moduleContext); - } - - @Override - public int getOrder() { - // Make sure producer modules get closed before the consumer modules (sink/processor) - // by setting them the highest precedence - ModuleType moduleType = getType(); - if (moduleType == ModuleType.source || moduleType == ModuleType.job) { - return HIGHEST_PRECEDENCE; - } - else if (getType() == ModuleType.processor) { - return LOWEST_PRECEDENCE - 10; - } - else { - return LOWEST_PRECEDENCE; - } - } - - } - }); + this.application.listeners(new ModuleParentContextCloserApplicationListener(getDeploymentMetadata().getIndex())); this.context = this.application.run(); if (logger.isInfoEnabled()) { logger.info("initialized module: " + this.toString());