Skip to content
This repository was archived by the owner on Apr 5, 2022. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -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());
Expand Down