[Bugfix] fixed a bug where components were started multiple times
This occurs when multiple upstream dependencies are shared by components . When starting the container the root upstream dependencies are started and then all those direct downstream dependencies, leading to components being started multiple times.
This commit is contained in:
parent
11fbf61cb3
commit
bee3c353ab
|
@ -152,6 +152,9 @@ public class ComponentContainerImpl implements ComponentContainer {
|
||||||
|
|
||||||
// initialize each component
|
// initialize each component
|
||||||
for (ComponentController controller : controllers) {
|
for (ComponentController controller : controllers) {
|
||||||
|
if (controller.getState() == ComponentState.INITIALIZED)
|
||||||
|
continue;
|
||||||
|
|
||||||
StrolchComponent component = controller.getComponent();
|
StrolchComponent component = controller.getComponent();
|
||||||
String componentName = component.getName();
|
String componentName = component.getName();
|
||||||
ComponentConfiguration componentConfiguration = this.strolchConfiguration
|
ComponentConfiguration componentConfiguration = this.strolchConfiguration
|
||||||
|
@ -173,6 +176,9 @@ public class ComponentContainerImpl implements ComponentContainer {
|
||||||
|
|
||||||
// Start each component
|
// Start each component
|
||||||
for (ComponentController controller : controllers) {
|
for (ComponentController controller : controllers) {
|
||||||
|
if (controller.getState() == ComponentState.STARTED)
|
||||||
|
continue;
|
||||||
|
|
||||||
StrolchComponent component = controller.getComponent();
|
StrolchComponent component = controller.getComponent();
|
||||||
String msg = "Starting component {0}..."; //$NON-NLS-1$
|
String msg = "Starting component {0}..."; //$NON-NLS-1$
|
||||||
String componentName = component.getName();
|
String componentName = component.getName();
|
||||||
|
@ -191,6 +197,9 @@ public class ComponentContainerImpl implements ComponentContainer {
|
||||||
|
|
||||||
// Stop each component
|
// Stop each component
|
||||||
for (ComponentController controller : controllers) {
|
for (ComponentController controller : controllers) {
|
||||||
|
if (controller.getState() == ComponentState.STOPPED)
|
||||||
|
continue;
|
||||||
|
|
||||||
StrolchComponent component = controller.getComponent();
|
StrolchComponent component = controller.getComponent();
|
||||||
String msg = "Stopping component {0}..."; //$NON-NLS-1$
|
String msg = "Stopping component {0}..."; //$NON-NLS-1$
|
||||||
String componentName = component.getName();
|
String componentName = component.getName();
|
||||||
|
@ -208,6 +217,9 @@ public class ComponentContainerImpl implements ComponentContainer {
|
||||||
|
|
||||||
// Destroy each component
|
// Destroy each component
|
||||||
for (ComponentController controller : controllers) {
|
for (ComponentController controller : controllers) {
|
||||||
|
if (controller.getState() == ComponentState.DESTROYED)
|
||||||
|
continue;
|
||||||
|
|
||||||
StrolchComponent component = controller.getComponent();
|
StrolchComponent component = controller.getComponent();
|
||||||
String msg = "Destroying component {0}..."; //$NON-NLS-1$
|
String msg = "Destroying component {0}..."; //$NON-NLS-1$
|
||||||
String componentName = component.getName();
|
String componentName = component.getName();
|
||||||
|
|
|
@ -19,6 +19,7 @@ import java.text.MessageFormat;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import li.strolch.agent.api.ComponentState;
|
||||||
import li.strolch.agent.api.StrolchComponent;
|
import li.strolch.agent.api.StrolchComponent;
|
||||||
import li.strolch.runtime.configuration.StrolchConfigurationException;
|
import li.strolch.runtime.configuration.StrolchConfigurationException;
|
||||||
|
|
||||||
|
@ -36,6 +37,10 @@ public class ComponentController {
|
||||||
this.downstreamDependencies = new HashSet<>();
|
this.downstreamDependencies = new HashSet<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ComponentState getState() {
|
||||||
|
return this.component.getState();
|
||||||
|
}
|
||||||
|
|
||||||
public StrolchComponent getComponent() {
|
public StrolchComponent getComponent() {
|
||||||
return this.component;
|
return this.component;
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,8 +25,14 @@ import li.strolch.runtime.configuration.ComponentConfiguration;
|
||||||
import li.strolch.runtime.configuration.StrolchConfiguration;
|
import li.strolch.runtime.configuration.StrolchConfiguration;
|
||||||
import li.strolch.runtime.configuration.StrolchConfigurationException;
|
import li.strolch.runtime.configuration.StrolchConfigurationException;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import ch.eitchnet.utils.helper.StringHelper;
|
||||||
|
|
||||||
public class ComponentDependencyAnalyzer {
|
public class ComponentDependencyAnalyzer {
|
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(ComponentDependencyAnalyzer.class);
|
||||||
private StrolchConfiguration strolchConfiguration;
|
private StrolchConfiguration strolchConfiguration;
|
||||||
private Map<String, ComponentController> controllerMap;
|
private Map<String, ComponentController> controllerMap;
|
||||||
|
|
||||||
|
@ -134,5 +140,21 @@ public class ComponentDependencyAnalyzer {
|
||||||
controller.addUpstreamDependency(dependency);
|
controller.addUpstreamDependency(dependency);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logDependencies(0, findRootUpstreamComponents());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param components
|
||||||
|
*/
|
||||||
|
private void logDependencies(int depth, Set<ComponentController> components) {
|
||||||
|
if (depth == 0) {
|
||||||
|
logger.info("Dependency tree:");
|
||||||
|
}
|
||||||
|
String inset = StringHelper.normalizeLength(" ", depth * 2, false, ' ');
|
||||||
|
for (ComponentController controller : components) {
|
||||||
|
logger.info(inset + controller.getComponent().getName());
|
||||||
|
logDependencies(depth + 1, controller.getDownstreamDependencies());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@ package li.strolch.runtime.test.component;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
|
@ -81,6 +82,7 @@ public class ConfigurationParserTest {
|
||||||
assertEquals("li.strolch.runtime.privilege.DefaultStrolchPrivilegeHandler",
|
assertEquals("li.strolch.runtime.privilege.DefaultStrolchPrivilegeHandler",
|
||||||
privilegeHandlerConfiguration.getImpl());
|
privilegeHandlerConfiguration.getImpl());
|
||||||
assertEquals(1, privilegeHandlerConfiguration.getPropertyKeys().size());
|
assertEquals(1, privilegeHandlerConfiguration.getPropertyKeys().size());
|
||||||
|
assertTrue(privilegeHandlerConfiguration.getDependencies().contains("PersistenceHandler"));
|
||||||
assertEquals("PrivilegeConfig.xml", privilegeHandlerConfiguration.getString("privilegeConfigFile", null));
|
assertEquals("PrivilegeConfig.xml", privilegeHandlerConfiguration.getString("privilegeConfigFile", null));
|
||||||
|
|
||||||
// <Component>
|
// <Component>
|
||||||
|
|
|
@ -28,6 +28,8 @@
|
||||||
<name>ResourceGeneratorHandler</name>
|
<name>ResourceGeneratorHandler</name>
|
||||||
<api>li.strolch.runtime.test.component.model.ResourceGeneratorHandlerTest</api>
|
<api>li.strolch.runtime.test.component.model.ResourceGeneratorHandlerTest</api>
|
||||||
<impl>li.strolch.runtime.test.component.model.ResourceGeneratorHandlerTestImpl</impl>
|
<impl>li.strolch.runtime.test.component.model.ResourceGeneratorHandlerTestImpl</impl>
|
||||||
|
<depends>PersistenceHandler</depends>
|
||||||
|
<depends>ServiceHandler</depends>
|
||||||
<Properties>
|
<Properties>
|
||||||
<verbose>true</verbose>
|
<verbose>true</verbose>
|
||||||
</Properties>
|
</Properties>
|
||||||
|
|
Loading…
Reference in New Issue