diff --git a/src/main/java/li/strolch/runtime/agent/ComponentContainerImpl.java b/src/main/java/li/strolch/runtime/agent/ComponentContainerImpl.java index 94c229d45..30f1747a6 100644 --- a/src/main/java/li/strolch/runtime/agent/ComponentContainerImpl.java +++ b/src/main/java/li/strolch/runtime/agent/ComponentContainerImpl.java @@ -257,25 +257,36 @@ public class ComponentContainerImpl implements ComponentContainer { logger.info("Stopping strolch components..."); //$NON-NLS-1$ - Set rootUpstreamComponents = this.dependencyAnalyzer.findRootDownstreamComponents(); - stop(rootUpstreamComponents); - this.state = this.state.validateStateChange(ComponentState.STOPPED); + if (this.dependencyAnalyzer == null) { + logger.info("Strolch Components have been stopped."); //$NON-NLS-1$ + } else { + Set rootUpstreamComponents = this.dependencyAnalyzer.findRootDownstreamComponents(); + stop(rootUpstreamComponents); + this.state = this.state.validateStateChange(ComponentState.STOPPED); - String msg = "All {0} Strolch Components have been stopped."; //$NON-NLS-1$ - logger.info(MessageFormat.format(msg, this.controllerMap.size())); + String msg = "All {0} Strolch Components have been stopped."; //$NON-NLS-1$ + logger.info(MessageFormat.format(msg, this.controllerMap.size())); + } } public void destroy() { logger.info("Destroying strolch components..."); //$NON-NLS-1$ - Set rootUpstreamComponents = this.dependencyAnalyzer.findRootDownstreamComponents(); - destroy(rootUpstreamComponents); - this.state = this.state.validateStateChange(ComponentState.DESTROYED); + if (this.dependencyAnalyzer == null) { + logger.info("Strolch Components have been destroyed."); //$NON-NLS-1$ + } else { + Set rootUpstreamComponents = this.dependencyAnalyzer.findRootDownstreamComponents(); + destroy(rootUpstreamComponents); + this.state = this.state.validateStateChange(ComponentState.DESTROYED); - String msg = "All {0} Strolch Components have been destroyed!"; //$NON-NLS-1$ - logger.info(MessageFormat.format(msg, this.controllerMap.size())); - this.controllerMap.clear(); - this.componentMap.clear(); + String msg = "All {0} Strolch Components have been destroyed!"; //$NON-NLS-1$ + logger.info(MessageFormat.format(msg, this.controllerMap.size())); + this.controllerMap.clear(); + this.componentMap.clear(); + } + + this.controllerMap = null; + this.componentMap = null; } } diff --git a/src/main/java/li/strolch/runtime/agent/ComponentState.java b/src/main/java/li/strolch/runtime/agent/ComponentState.java index 5a34de2db..12c96beb0 100644 --- a/src/main/java/li/strolch/runtime/agent/ComponentState.java +++ b/src/main/java/li/strolch/runtime/agent/ComponentState.java @@ -28,11 +28,11 @@ public enum ComponentState { switch (this) { case UNDEFINED: - if (newState != ComponentState.INITIALIZED) + if (newState != ComponentState.INITIALIZED && newState != STOPPED) throw getIllegalStateEx(newState); break; case INITIALIZED: - if (newState != ComponentState.STARTED) + if (newState != ComponentState.STARTED && newState != STOPPED) throw getIllegalStateEx(newState); break; case STARTED: diff --git a/src/main/java/li/strolch/runtime/agent/StrolchAgent.java b/src/main/java/li/strolch/runtime/agent/StrolchAgent.java index 6215ed29e..80e2395d7 100644 --- a/src/main/java/li/strolch/runtime/agent/StrolchAgent.java +++ b/src/main/java/li/strolch/runtime/agent/StrolchAgent.java @@ -66,11 +66,13 @@ public class StrolchAgent { } public void stop() { - this.container.stop(); + if (this.container != null) + this.container.stop(); } public void destroy() { - this.container.destroy(); + if (this.container != null) + this.container.destroy(); } public void setup(File path) {