From 3770e7b65cc38734c7f3f76914f6c0c33c28cbe1 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Fri, 17 Feb 2017 13:37:35 +0100 Subject: [PATCH] [Minor] Give component name, when state change invalid --- .../li/strolch/agent/api/ComponentState.java | 20 +++++++++---------- .../strolch/agent/api/StrolchComponent.java | 10 +++++----- .../agent/impl/ComponentContainerImpl.java | 10 +++++----- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/li.strolch.agent/src/main/java/li/strolch/agent/api/ComponentState.java b/li.strolch.agent/src/main/java/li/strolch/agent/api/ComponentState.java index b38c8736d..d34559feb 100644 --- a/li.strolch.agent/src/main/java/li/strolch/agent/api/ComponentState.java +++ b/li.strolch.agent/src/main/java/li/strolch/agent/api/ComponentState.java @@ -21,7 +21,7 @@ public enum ComponentState { UNDEFINED, SETUP, INITIALIZED, STARTED, STOPPED, DESTROYED; - public ComponentState validateStateChange(ComponentState newState) { + public ComponentState validateStateChange(ComponentState newState, String componentName) { if (this == newState) return this; @@ -29,35 +29,35 @@ public enum ComponentState { switch (this) { case UNDEFINED: if (newState != ComponentState.SETUP && newState != STOPPED) - throw getIllegalStateEx(newState); + throw getIllegalStateEx(newState, componentName); break; case SETUP: if (newState != ComponentState.INITIALIZED && newState != STOPPED && newState != DESTROYED) - throw getIllegalStateEx(newState); + throw getIllegalStateEx(newState, componentName); break; case INITIALIZED: if (newState != ComponentState.STARTED && newState != STOPPED && newState != DESTROYED) - throw getIllegalStateEx(newState); + throw getIllegalStateEx(newState, componentName); break; case STARTED: if (newState != ComponentState.STOPPED) - throw getIllegalStateEx(newState); + throw getIllegalStateEx(newState, componentName); break; case STOPPED: if (newState != ComponentState.STARTED && newState != ComponentState.DESTROYED) - throw getIllegalStateEx(newState); + throw getIllegalStateEx(newState, componentName); break; case DESTROYED: - throw getIllegalStateEx(newState); + throw getIllegalStateEx(newState, componentName); default: - throw getIllegalStateEx(newState); + throw getIllegalStateEx(newState, componentName); } return newState; } - private IllegalStateException getIllegalStateEx(ComponentState newState) { - String msg = "Moving from state {0} to state {1} is not allowed!"; //$NON-NLS-1$ + private IllegalStateException getIllegalStateEx(ComponentState newState, String componentName) { + String msg = "Moving from state {0} to state {1} is not allowed for component " + componentName; //$NON-NLS-1$ msg = MessageFormat.format(msg, this, newState); throw new IllegalStateException(msg); } diff --git a/li.strolch.agent/src/main/java/li/strolch/agent/api/StrolchComponent.java b/li.strolch.agent/src/main/java/li/strolch/agent/api/StrolchComponent.java index 8dd6d2864..ee80841be 100644 --- a/li.strolch.agent/src/main/java/li/strolch/agent/api/StrolchComponent.java +++ b/li.strolch.agent/src/main/java/li/strolch/agent/api/StrolchComponent.java @@ -136,7 +136,7 @@ public class StrolchComponent { * @param configuration */ public void setup(ComponentConfiguration configuration) { - this.state = this.state.validateStateChange(ComponentState.SETUP); + this.state = this.state.validateStateChange(ComponentState.SETUP, getName()); } /** @@ -147,7 +147,7 @@ public class StrolchComponent { */ public void initialize(ComponentConfiguration configuration) throws Exception { this.configuration = configuration; - this.state = this.state.validateStateChange(ComponentState.INITIALIZED); + this.state = this.state.validateStateChange(ComponentState.INITIALIZED, getName()); } /** @@ -157,7 +157,7 @@ public class StrolchComponent { * @throws Exception */ public void start() throws Exception { - this.state = this.state.validateStateChange(ComponentState.STARTED); + this.state = this.state.validateStateChange(ComponentState.STARTED, getName()); } /** @@ -167,7 +167,7 @@ public class StrolchComponent { * @throws Exception */ public void stop() throws Exception { - this.state = this.state.validateStateChange(ComponentState.STOPPED); + this.state = this.state.validateStateChange(ComponentState.STOPPED, getName()); } /** @@ -177,7 +177,7 @@ public class StrolchComponent { * @throws Exception */ public void destroy() throws Exception { - this.state = this.state.validateStateChange(ComponentState.DESTROYED); + this.state = this.state.validateStateChange(ComponentState.DESTROYED, getName()); } /** diff --git a/li.strolch.agent/src/main/java/li/strolch/agent/impl/ComponentContainerImpl.java b/li.strolch.agent/src/main/java/li/strolch/agent/impl/ComponentContainerImpl.java index 102e65197..4896c4b18 100644 --- a/li.strolch.agent/src/main/java/li/strolch/agent/impl/ComponentContainerImpl.java +++ b/li.strolch.agent/src/main/java/li/strolch/agent/impl/ComponentContainerImpl.java @@ -178,7 +178,7 @@ public class ComponentContainerImpl implements ComponentContainer { } public void setup(StrolchConfiguration strolchConfiguration) { - this.state.validateStateChange(ComponentState.SETUP); + this.state.validateStateChange(ComponentState.SETUP, "agent"); // set the application locale Locale.setDefault(strolchConfiguration.getRuntimeConfiguration().getLocale()); @@ -220,7 +220,7 @@ public class ComponentContainerImpl implements ComponentContainer { } public void initialize(StrolchConfiguration strolchConfiguration) { - this.state.validateStateChange(ComponentState.INITIALIZED); + this.state.validateStateChange(ComponentState.INITIALIZED, "agent"); // now we can initialize the components String msg = "{0}:{1} Initializing {2} Strolch Components..."; //$NON-NLS-1$ @@ -238,7 +238,7 @@ public class ComponentContainerImpl implements ComponentContainer { } public void start() { - this.state.validateStateChange(ComponentState.STARTED); + this.state.validateStateChange(ComponentState.STARTED, "agent"); String msg = "{0}:{1} Starting {2} Strolch Components..."; //$NON-NLS-1$ String environment = getEnvironment(); @@ -257,7 +257,7 @@ public class ComponentContainerImpl implements ComponentContainer { } public void stop() { - this.state.validateStateChange(ComponentState.STOPPED); + this.state.validateStateChange(ComponentState.STOPPED, "agent"); String msg = "{0}:{1} Stopping {2} Strolch Components..."; //$NON-NLS-1$ String environment = getEnvironment(); @@ -278,7 +278,7 @@ public class ComponentContainerImpl implements ComponentContainer { } public void destroy() { - this.state.validateStateChange(ComponentState.DESTROYED); + this.state.validateStateChange(ComponentState.DESTROYED, "agent"); String msg = "{0}:{1} Destroying {2} Strolch Components..."; //$NON-NLS-1$ String environment = getEnvironment();