[Major] Renamed Controller.getExecutionPolicy() to refreshExecutionPolicy()

This commit is contained in:
Robert von Burg 2020-03-04 11:09:36 +01:00
parent 11c2268b9a
commit e96d811f66
4 changed files with 32 additions and 22 deletions

View File

@ -72,7 +72,7 @@ public class Controller {
return this.activity; 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 -> { ExecutionPolicy executionPolicy = this.inExecution.computeIfAbsent(action.getLocator(), e -> {
Resource resource = tx.getResourceFor(action, true); Resource resource = tx.getResourceFor(action, true);
return tx.getPolicy(resource.getPolicyDef(ExecutionPolicy.class)); return tx.getPolicy(resource.getPolicyDef(ExecutionPolicy.class));
@ -80,6 +80,7 @@ public class Controller {
// always update the TX and controller // always update the TX and controller
executionPolicy.setController(tx, this); executionPolicy.setController(tx, this);
executionPolicy.setStopped(false);
return executionPolicy; return executionPolicy;
} }
@ -172,7 +173,7 @@ public class Controller {
// set this action to executed // set this action to executed
SetActionToExecutedCommand command = new SetActionToExecutedCommand(tx); SetActionToExecutedCommand command = new SetActionToExecutedCommand(tx);
command.setExecutionPolicy(getExecutionPolicy(tx, action)); command.setExecutionPolicy(refreshExecutionPolicy(tx, action));
command.setAction(action); command.setAction(action);
command.validate(); command.validate();
command.doCommand(); command.doCommand();
@ -211,7 +212,7 @@ public class Controller {
// set this action to executed // set this action to executed
SetActionToStoppedCommand command = new SetActionToStoppedCommand(tx); SetActionToStoppedCommand command = new SetActionToStoppedCommand(tx);
command.setExecutionPolicy(getExecutionPolicy(tx, action)); command.setExecutionPolicy(refreshExecutionPolicy(tx, action));
command.setAction(action); command.setAction(action);
command.validate(); command.validate();
command.doCommand(); command.doCommand();
@ -241,7 +242,7 @@ public class Controller {
// set this action to executed // set this action to executed
SetActionToErrorCommand command = new SetActionToErrorCommand(tx); SetActionToErrorCommand command = new SetActionToErrorCommand(tx);
command.setExecutionPolicy(getExecutionPolicy(tx, action)); command.setExecutionPolicy(refreshExecutionPolicy(tx, action));
command.setAction(action); command.setAction(action);
command.validate(); command.validate();
command.doCommand(); command.doCommand();
@ -271,7 +272,7 @@ public class Controller {
// set this action to executed // set this action to executed
SetActionToWarningCommand command = new SetActionToWarningCommand(tx); SetActionToWarningCommand command = new SetActionToWarningCommand(tx);
command.setExecutionPolicy(getExecutionPolicy(tx, action)); command.setExecutionPolicy(refreshExecutionPolicy(tx, action));
command.setAction(action); command.setAction(action);
command.validate(); command.validate();
command.doCommand(); command.doCommand();

View File

@ -72,19 +72,26 @@ public class SimpleDurationExecutionTimer implements DelayedExecutionTimer {
this.simulationTasks.remove(locator); this.simulationTasks.remove(locator);
ExecutionHandler executionHandler = container.getComponent(ExecutionHandler.class); ExecutionHandler executionHandler = container.getComponent(ExecutionHandler.class);
Controller controller = executionHandler.getController(realm, locator); Controller controller = executionHandler.getController(realm, locator);
if (controller != null) { if (controller == null) {
try { logger.warn("Controller already remove for " + locator);
if (!controller.isStopped(locator)) return;
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)) { if (controller.isStopped(locator)) {
this.agent.getContainer().getComponent(OperationsLog.class).addMessage( logger.warn("Execution for " + locator + " is already stopped.");
new LogMessage(realm, SYSTEM_USER_AGENT, locator, LogSeverity.Exception, return;
ResourceBundle.getBundle("strolch-service"), "execution.handler.failed.executed") }
.withException(e).value("reason", e));
} 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));
} }
} }
} }

View File

@ -30,7 +30,7 @@ public class ExecuteActivityCommand extends BasePlanningAndExecutionCommand
} }
private ExecutionPolicy getExecutionPolicy(Action action) { private ExecutionPolicy getExecutionPolicy(Action action) {
return this.controller.getExecutionPolicy(tx(), action); return this.controller.refreshExecutionPolicy(tx(), action);
} }
public boolean needsRetriggerOfExecution() { public boolean needsRetriggerOfExecution() {

View File

@ -73,6 +73,10 @@ public abstract class ExecutionPolicy extends StrolchPolicy {
return this.stopped; 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} * 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 * the delay duration
*/ */
protected void delayToExecutedBy(Duration duration) { protected void delayToExecutedBy(Duration duration) {
String realmName = tx().getRealmName();
long delayMs = duration.toMillis(); long delayMs = duration.toMillis();
if (delayMs < 20) { if (delayMs < 20) {
logger.warn("Delay time for " + this.actionLoc + " is less than 20ms, overriding!"); logger.warn("Delay time for " + this.actionLoc + " is less than 20ms, overriding!");
delayMs = 20; delayMs = 20;
} }
logger.info("Delaying toExecuted of " + this.actionLoc + " by " + formatMillisecondsDuration(delayMs)); 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) { 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 * the UOM of the delay time
*/ */
protected void delayToExecutedBy(long delay, TimeUnit delayUnit) { protected void delayToExecutedBy(long delay, TimeUnit delayUnit) {
String realmName = tx().getRealmName();
long delayMs = delayUnit.toMillis(delay); long delayMs = delayUnit.toMillis(delay);
if (delayMs < 20) { if (delayMs < 20) {
logger.warn("Delay time for " + this.actionLoc + " is less than 20ms, overriding!"); logger.warn("Delay time for " + this.actionLoc + " is less than 20ms, overriding!");
delayMs = 20; delayMs = 20;
} }
logger.info("Delaying toExecuted of " + this.actionLoc + " by " + formatMillisecondsDuration(delayMs)); 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);
} }
/** /**