From 13a7c83d96cb588f79699c8a4d1109d1137a2bdc Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Fri, 20 Jan 2017 10:23:47 +0100 Subject: [PATCH] [New] Added new SimpleExecution and DurationExecution extends it --- .../execution/policy/DurationExecution.java | 57 +------------- .../execution/policy/SimpleExecution.java | 78 +++++++++++++++++++ 2 files changed, 80 insertions(+), 55 deletions(-) create mode 100644 li.strolch.service/src/main/java/li/strolch/execution/policy/SimpleExecution.java diff --git a/li.strolch.service/src/main/java/li/strolch/execution/policy/DurationExecution.java b/li.strolch.service/src/main/java/li/strolch/execution/policy/DurationExecution.java index 48403ba6f..9e8218f7b 100644 --- a/li.strolch.service/src/main/java/li/strolch/execution/policy/DurationExecution.java +++ b/li.strolch.service/src/main/java/li/strolch/execution/policy/DurationExecution.java @@ -1,9 +1,7 @@ package li.strolch.execution.policy; import li.strolch.agent.api.ComponentContainer; -import li.strolch.command.UpdateActivityCommand; import li.strolch.model.Locator; -import li.strolch.model.State; import li.strolch.model.activity.Action; import li.strolch.model.parameter.DurationParameter; import li.strolch.persistence.api.StrolchTransaction; @@ -17,7 +15,7 @@ import li.strolch.runtime.StrolchConstants.PolicyConstants; * * @author Robert von Burg */ -public class DurationExecution extends ExecutionPolicy { +public class DurationExecution extends SimpleExecution { public DurationExecution(ComponentContainer container, StrolchTransaction tx) { super(container, tx); @@ -34,57 +32,6 @@ public class DurationExecution extends ExecutionPolicy { logger.warn("Executing action " + action.getLocator() + " has a duration of " + durationP.getValueAsString()); getDelayedExecutionTimer().execute(realmName, getContainer(), locator, durationP.getValue()); - action.setState(State.EXECUTION); - - UpdateActivityCommand command = new UpdateActivityCommand(getContainer(), tx()); - command.setActivity(action.getRootElement()); - command.doCommand(); - - logger.info("Action " + action.getLocator() + " is now in EXECUTION!"); - } - - @Override - public void toExecuted(Action action) { - - action.setState(State.EXECUTED); - - UpdateActivityCommand command = new UpdateActivityCommand(getContainer(), tx()); - command.setActivity(action.getRootElement()); - command.doCommand(); - - logger.info("Action " + action.getLocator() + " is now EXECUTED!"); - } - - @Override - public void toStopped(Action action) { - - getDelayedExecutionTimer().cancel(action.getLocator()); - - action.setState(State.STOPPED); - - UpdateActivityCommand command = new UpdateActivityCommand(getContainer(), tx()); - command.setActivity(action.getRootElement()); - command.doCommand(); - - logger.warn("Action " + action.getLocator() + " is now STOPPED!"); - } - - @Override - public void toError(Action action) { - - getDelayedExecutionTimer().cancel(action.getLocator()); - - action.setState(State.ERROR); - - UpdateActivityCommand command = new UpdateActivityCommand(getContainer(), tx()); - command.setActivity(action.getRootElement()); - command.doCommand(); - - logger.error("Action " + action.getLocator() + " is now in ERROR!"); - } - - @Override - public void undo() { - logger.error("Can not undo an " + getClass()); + super.toExecution(action); } } diff --git a/li.strolch.service/src/main/java/li/strolch/execution/policy/SimpleExecution.java b/li.strolch.service/src/main/java/li/strolch/execution/policy/SimpleExecution.java new file mode 100644 index 000000000..16672b066 --- /dev/null +++ b/li.strolch.service/src/main/java/li/strolch/execution/policy/SimpleExecution.java @@ -0,0 +1,78 @@ +package li.strolch.execution.policy; + +import li.strolch.agent.api.ComponentContainer; +import li.strolch.command.UpdateActivityCommand; +import li.strolch.model.State; +import li.strolch.model.activity.Action; +import li.strolch.persistence.api.StrolchTransaction; + +/** + *

+ * Simple Execution Policy which sets the state of the action depending on the method called. + *

+ * + * @author Robert von Burg + */ +public class SimpleExecution extends ExecutionPolicy { + + public SimpleExecution(ComponentContainer container, StrolchTransaction tx) { + super(container, tx); + } + + @Override + public void toExecution(Action action) { + + action.setState(State.EXECUTION); + + UpdateActivityCommand command = new UpdateActivityCommand(getContainer(), tx()); + command.setActivity(action.getRootElement()); + command.doCommand(); + + logger.info("Action " + action.getLocator() + " is now in EXECUTION!"); + } + + @Override + public void toExecuted(Action action) { + + action.setState(State.EXECUTED); + + UpdateActivityCommand command = new UpdateActivityCommand(getContainer(), tx()); + command.setActivity(action.getRootElement()); + command.doCommand(); + + logger.info("Action " + action.getLocator() + " is now EXECUTED!"); + } + + @Override + public void toStopped(Action action) { + + getDelayedExecutionTimer().cancel(action.getLocator()); + + action.setState(State.STOPPED); + + UpdateActivityCommand command = new UpdateActivityCommand(getContainer(), tx()); + command.setActivity(action.getRootElement()); + command.doCommand(); + + logger.warn("Action " + action.getLocator() + " is now STOPPED!"); + } + + @Override + public void toError(Action action) { + + getDelayedExecutionTimer().cancel(action.getLocator()); + + action.setState(State.ERROR); + + UpdateActivityCommand command = new UpdateActivityCommand(getContainer(), tx()); + command.setActivity(action.getRootElement()); + command.doCommand(); + + logger.error("Action " + action.getLocator() + " is now in ERROR!"); + } + + @Override + public void undo() { + logger.error("Can not undo execution policy " + getClass()); + } +}