[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
|
||||
for (ComponentController controller : controllers) {
|
||||
if (controller.getState() == ComponentState.INITIALIZED)
|
||||
continue;
|
||||
|
||||
StrolchComponent component = controller.getComponent();
|
||||
String componentName = component.getName();
|
||||
ComponentConfiguration componentConfiguration = this.strolchConfiguration
|
||||
|
@ -173,6 +176,9 @@ public class ComponentContainerImpl implements ComponentContainer {
|
|||
|
||||
// Start each component
|
||||
for (ComponentController controller : controllers) {
|
||||
if (controller.getState() == ComponentState.STARTED)
|
||||
continue;
|
||||
|
||||
StrolchComponent component = controller.getComponent();
|
||||
String msg = "Starting component {0}..."; //$NON-NLS-1$
|
||||
String componentName = component.getName();
|
||||
|
@ -191,6 +197,9 @@ public class ComponentContainerImpl implements ComponentContainer {
|
|||
|
||||
// Stop each component
|
||||
for (ComponentController controller : controllers) {
|
||||
if (controller.getState() == ComponentState.STOPPED)
|
||||
continue;
|
||||
|
||||
StrolchComponent component = controller.getComponent();
|
||||
String msg = "Stopping component {0}..."; //$NON-NLS-1$
|
||||
String componentName = component.getName();
|
||||
|
@ -208,6 +217,9 @@ public class ComponentContainerImpl implements ComponentContainer {
|
|||
|
||||
// Destroy each component
|
||||
for (ComponentController controller : controllers) {
|
||||
if (controller.getState() == ComponentState.DESTROYED)
|
||||
continue;
|
||||
|
||||
StrolchComponent component = controller.getComponent();
|
||||
String msg = "Destroying component {0}..."; //$NON-NLS-1$
|
||||
String componentName = component.getName();
|
||||
|
|
|
@ -19,6 +19,7 @@ import java.text.MessageFormat;
|
|||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import li.strolch.agent.api.ComponentState;
|
||||
import li.strolch.agent.api.StrolchComponent;
|
||||
import li.strolch.runtime.configuration.StrolchConfigurationException;
|
||||
|
||||
|
@ -36,6 +37,10 @@ public class ComponentController {
|
|||
this.downstreamDependencies = new HashSet<>();
|
||||
}
|
||||
|
||||
public ComponentState getState() {
|
||||
return this.component.getState();
|
||||
}
|
||||
|
||||
public StrolchComponent getComponent() {
|
||||
return this.component;
|
||||
}
|
||||
|
|
|
@ -25,8 +25,14 @@ import li.strolch.runtime.configuration.ComponentConfiguration;
|
|||
import li.strolch.runtime.configuration.StrolchConfiguration;
|
||||
import li.strolch.runtime.configuration.StrolchConfigurationException;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import ch.eitchnet.utils.helper.StringHelper;
|
||||
|
||||
public class ComponentDependencyAnalyzer {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ComponentDependencyAnalyzer.class);
|
||||
private StrolchConfiguration strolchConfiguration;
|
||||
private Map<String, ComponentController> controllerMap;
|
||||
|
||||
|
@ -134,5 +140,21 @@ public class ComponentDependencyAnalyzer {
|
|||
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.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
|
@ -81,6 +82,7 @@ public class ConfigurationParserTest {
|
|||
assertEquals("li.strolch.runtime.privilege.DefaultStrolchPrivilegeHandler",
|
||||
privilegeHandlerConfiguration.getImpl());
|
||||
assertEquals(1, privilegeHandlerConfiguration.getPropertyKeys().size());
|
||||
assertTrue(privilegeHandlerConfiguration.getDependencies().contains("PersistenceHandler"));
|
||||
assertEquals("PrivilegeConfig.xml", privilegeHandlerConfiguration.getString("privilegeConfigFile", null));
|
||||
|
||||
// <Component>
|
||||
|
|
|
@ -28,6 +28,8 @@
|
|||
<name>ResourceGeneratorHandler</name>
|
||||
<api>li.strolch.runtime.test.component.model.ResourceGeneratorHandlerTest</api>
|
||||
<impl>li.strolch.runtime.test.component.model.ResourceGeneratorHandlerTestImpl</impl>
|
||||
<depends>PersistenceHandler</depends>
|
||||
<depends>ServiceHandler</depends>
|
||||
<Properties>
|
||||
<verbose>true</verbose>
|
||||
</Properties>
|
||||
|
|
Loading…
Reference in New Issue