From e96d811f663db66e785f316353a6103b73e1c475 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Wed, 4 Mar 2020 11:09:36 +0100 Subject: [PATCH] [Major] Renamed Controller.getExecutionPolicy() to refreshExecutionPolicy() --- .../java/li/strolch/execution/Controller.java | 11 ++++--- .../SimpleDurationExecutionTimer.java | 31 ++++++++++++------- .../command/ExecuteActivityCommand.java | 2 +- .../execution/policy/ExecutionPolicy.java | 10 +++--- 4 files changed, 32 insertions(+), 22 deletions(-) diff --git a/li.strolch.service/src/main/java/li/strolch/execution/Controller.java b/li.strolch.service/src/main/java/li/strolch/execution/Controller.java index a8eb8c9ca..fe5a56d3a 100644 --- a/li.strolch.service/src/main/java/li/strolch/execution/Controller.java +++ b/li.strolch.service/src/main/java/li/strolch/execution/Controller.java @@ -72,7 +72,7 @@ public class Controller { return this.activity; } - public ExecutionPolicy getExecutionPolicy(StrolchTransaction tx, Action action) { + public ExecutionPolicy refreshExecutionPolicy(StrolchTransaction tx, Action action) { ExecutionPolicy executionPolicy = this.inExecution.computeIfAbsent(action.getLocator(), e -> { Resource resource = tx.getResourceFor(action, true); return tx.getPolicy(resource.getPolicyDef(ExecutionPolicy.class)); @@ -80,6 +80,7 @@ public class Controller { // always update the TX and controller executionPolicy.setController(tx, this); + executionPolicy.setStopped(false); return executionPolicy; } @@ -172,7 +173,7 @@ public class Controller { // set this action to executed SetActionToExecutedCommand command = new SetActionToExecutedCommand(tx); - command.setExecutionPolicy(getExecutionPolicy(tx, action)); + command.setExecutionPolicy(refreshExecutionPolicy(tx, action)); command.setAction(action); command.validate(); command.doCommand(); @@ -211,7 +212,7 @@ public class Controller { // set this action to executed SetActionToStoppedCommand command = new SetActionToStoppedCommand(tx); - command.setExecutionPolicy(getExecutionPolicy(tx, action)); + command.setExecutionPolicy(refreshExecutionPolicy(tx, action)); command.setAction(action); command.validate(); command.doCommand(); @@ -241,7 +242,7 @@ public class Controller { // set this action to executed SetActionToErrorCommand command = new SetActionToErrorCommand(tx); - command.setExecutionPolicy(getExecutionPolicy(tx, action)); + command.setExecutionPolicy(refreshExecutionPolicy(tx, action)); command.setAction(action); command.validate(); command.doCommand(); @@ -271,7 +272,7 @@ public class Controller { // set this action to executed SetActionToWarningCommand command = new SetActionToWarningCommand(tx); - command.setExecutionPolicy(getExecutionPolicy(tx, action)); + command.setExecutionPolicy(refreshExecutionPolicy(tx, action)); command.setAction(action); command.validate(); command.doCommand(); diff --git a/li.strolch.service/src/main/java/li/strolch/execution/SimpleDurationExecutionTimer.java b/li.strolch.service/src/main/java/li/strolch/execution/SimpleDurationExecutionTimer.java index 42cad3ec1..76c51ce09 100644 --- a/li.strolch.service/src/main/java/li/strolch/execution/SimpleDurationExecutionTimer.java +++ b/li.strolch.service/src/main/java/li/strolch/execution/SimpleDurationExecutionTimer.java @@ -72,19 +72,26 @@ public class SimpleDurationExecutionTimer implements DelayedExecutionTimer { this.simulationTasks.remove(locator); ExecutionHandler executionHandler = container.getComponent(ExecutionHandler.class); Controller controller = executionHandler.getController(realm, locator); - if (controller != null) { - try { - if (!controller.isStopped(locator)) - controller.toExecuted(locator); - } catch (Exception e) { - logger.error("Failed to set " + locator + " to executed due to " + e.getMessage(), e); + if (controller == null) { + logger.warn("Controller already remove for " + locator); + return; + } - if (this.agent.getContainer().hasComponent(OperationsLog.class)) { - this.agent.getContainer().getComponent(OperationsLog.class).addMessage( - new LogMessage(realm, SYSTEM_USER_AGENT, locator, LogSeverity.Exception, - ResourceBundle.getBundle("strolch-service"), "execution.handler.failed.executed") - .withException(e).value("reason", e)); - } + if (controller.isStopped(locator)) { + logger.warn("Execution for " + locator + " is already stopped."); + return; + } + + try { + controller.toExecuted(locator); + } catch (Exception e) { + logger.error("Failed to set " + locator + " to executed due to " + e.getMessage(), e); + + if (this.agent.getContainer().hasComponent(OperationsLog.class)) { + this.agent.getContainer().getComponent(OperationsLog.class).addMessage( + new LogMessage(realm, SYSTEM_USER_AGENT, locator, LogSeverity.Exception, + ResourceBundle.getBundle("strolch-service"), "execution.handler.failed.executed") + .withException(e).value("reason", e)); } } } diff --git a/li.strolch.service/src/main/java/li/strolch/execution/command/ExecuteActivityCommand.java b/li.strolch.service/src/main/java/li/strolch/execution/command/ExecuteActivityCommand.java index 279439368..6144c233f 100644 --- a/li.strolch.service/src/main/java/li/strolch/execution/command/ExecuteActivityCommand.java +++ b/li.strolch.service/src/main/java/li/strolch/execution/command/ExecuteActivityCommand.java @@ -30,7 +30,7 @@ public class ExecuteActivityCommand extends BasePlanningAndExecutionCommand } private ExecutionPolicy getExecutionPolicy(Action action) { - return this.controller.getExecutionPolicy(tx(), action); + return this.controller.refreshExecutionPolicy(tx(), action); } public boolean needsRetriggerOfExecution() { diff --git a/li.strolch.service/src/main/java/li/strolch/execution/policy/ExecutionPolicy.java b/li.strolch.service/src/main/java/li/strolch/execution/policy/ExecutionPolicy.java index 9ae306bfc..81396505a 100644 --- a/li.strolch.service/src/main/java/li/strolch/execution/policy/ExecutionPolicy.java +++ b/li.strolch.service/src/main/java/li/strolch/execution/policy/ExecutionPolicy.java @@ -73,6 +73,10 @@ public abstract class ExecutionPolicy extends StrolchPolicy { return this.stopped; } + public void setStopped(boolean stopped) { + this.stopped = stopped; + } + /** * Returns the TX which is defined on this class, not the one defined on {@link StrolchPolicy} */ @@ -199,14 +203,13 @@ public abstract class ExecutionPolicy extends StrolchPolicy { * the delay duration */ protected void delayToExecutedBy(Duration duration) { - String realmName = tx().getRealmName(); long delayMs = duration.toMillis(); if (delayMs < 20) { logger.warn("Delay time for " + this.actionLoc + " is less than 20ms, overriding!"); delayMs = 20; } logger.info("Delaying toExecuted of " + this.actionLoc + " by " + formatMillisecondsDuration(delayMs)); - getDelayedExecutionTimer().execute(realmName, getContainer(), this.actionLoc, delayMs); + getDelayedExecutionTimer().execute(this.realm, getContainer(), this.actionLoc, delayMs); } protected void delayToExecutedByRandom(long duration, double minFactor, double maxFactor, TimeUnit delayUnit) { @@ -227,14 +230,13 @@ public abstract class ExecutionPolicy extends StrolchPolicy { * the UOM of the delay time */ protected void delayToExecutedBy(long delay, TimeUnit delayUnit) { - String realmName = tx().getRealmName(); long delayMs = delayUnit.toMillis(delay); if (delayMs < 20) { logger.warn("Delay time for " + this.actionLoc + " is less than 20ms, overriding!"); delayMs = 20; } logger.info("Delaying toExecuted of " + this.actionLoc + " by " + formatMillisecondsDuration(delayMs)); - getDelayedExecutionTimer().execute(realmName, getContainer(), this.actionLoc, delayMs); + getDelayedExecutionTimer().execute(this.realm, getContainer(), this.actionLoc, delayMs); } /**