[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:
parent
4fd2cf1d0c
commit
6aaf7a5364
|
@ -257,25 +257,36 @@ public class ComponentContainerImpl implements ComponentContainer {
|
||||||
|
|
||||||
logger.info("Stopping strolch components..."); //$NON-NLS-1$
|
logger.info("Stopping strolch components..."); //$NON-NLS-1$
|
||||||
|
|
||||||
Set<ComponentController> rootUpstreamComponents = this.dependencyAnalyzer.findRootDownstreamComponents();
|
if (this.dependencyAnalyzer == null) {
|
||||||
stop(rootUpstreamComponents);
|
logger.info("Strolch Components have been stopped."); //$NON-NLS-1$
|
||||||
this.state = this.state.validateStateChange(ComponentState.STOPPED);
|
} 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$
|
String msg = "All {0} Strolch Components have been stopped."; //$NON-NLS-1$
|
||||||
logger.info(MessageFormat.format(msg, this.controllerMap.size()));
|
logger.info(MessageFormat.format(msg, this.controllerMap.size()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void destroy() {
|
public void destroy() {
|
||||||
|
|
||||||
logger.info("Destroying strolch components..."); //$NON-NLS-1$
|
logger.info("Destroying strolch components..."); //$NON-NLS-1$
|
||||||
|
|
||||||
Set<ComponentController> rootUpstreamComponents = this.dependencyAnalyzer.findRootDownstreamComponents();
|
if (this.dependencyAnalyzer == null) {
|
||||||
destroy(rootUpstreamComponents);
|
logger.info("Strolch Components have been destroyed."); //$NON-NLS-1$
|
||||||
this.state = this.state.validateStateChange(ComponentState.DESTROYED);
|
} 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$
|
String msg = "All {0} Strolch Components have been destroyed!"; //$NON-NLS-1$
|
||||||
logger.info(MessageFormat.format(msg, this.controllerMap.size()));
|
logger.info(MessageFormat.format(msg, this.controllerMap.size()));
|
||||||
this.controllerMap.clear();
|
this.controllerMap.clear();
|
||||||
this.componentMap.clear();
|
this.componentMap.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.controllerMap = null;
|
||||||
|
this.componentMap = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,11 +28,11 @@ public enum ComponentState {
|
||||||
|
|
||||||
switch (this) {
|
switch (this) {
|
||||||
case UNDEFINED:
|
case UNDEFINED:
|
||||||
if (newState != ComponentState.INITIALIZED)
|
if (newState != ComponentState.INITIALIZED && newState != STOPPED)
|
||||||
throw getIllegalStateEx(newState);
|
throw getIllegalStateEx(newState);
|
||||||
break;
|
break;
|
||||||
case INITIALIZED:
|
case INITIALIZED:
|
||||||
if (newState != ComponentState.STARTED)
|
if (newState != ComponentState.STARTED && newState != STOPPED)
|
||||||
throw getIllegalStateEx(newState);
|
throw getIllegalStateEx(newState);
|
||||||
break;
|
break;
|
||||||
case STARTED:
|
case STARTED:
|
||||||
|
|
|
@ -66,11 +66,13 @@ public class StrolchAgent {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stop() {
|
public void stop() {
|
||||||
this.container.stop();
|
if (this.container != null)
|
||||||
|
this.container.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void destroy() {
|
public void destroy() {
|
||||||
this.container.destroy();
|
if (this.container != null)
|
||||||
|
this.container.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setup(File path) {
|
public void setup(File path) {
|
||||||
|
|
Loading…
Reference in New Issue