[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;
}
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();

View File

@ -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));
}
}
}

View File

@ -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() {

View File

@ -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);
}
/**