[Minor] better error handling when the agent does not start

Should the agent not be able to start due to configuration problems, 
then the agent must still be stopped, thus state changes in this context
should not lead to exceptions when shutting down.
This commit is contained in:
Robert von Burg 2013-12-24 16:51:31 +01:00
parent 4fd2cf1d0c
commit 6aaf7a5364
3 changed files with 29 additions and 16 deletions

View File

@ -257,25 +257,36 @@ public class ComponentContainerImpl implements ComponentContainer {
logger.info("Stopping strolch components..."); //$NON-NLS-1$
Set<ComponentController> 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<ComponentController> 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<ComponentController> 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<ComponentController> 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;
}
}

View File

@ -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:

View File

@ -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) {