[Fix] Fixed ExecutionPolicy not initialized before use

This commit is contained in:
Robert von Burg 2024-01-19 10:21:46 +01:00
parent 9c15d0d1d2
commit 63670a77b6
Signed by: eitch
GPG Key ID: 75DB9C85C74331F7
3 changed files with 18 additions and 15 deletions

View File

@ -96,7 +96,9 @@ public class Controller {
public ExecutionPolicy refreshExecutionPolicy(StrolchTransaction tx, Action action) {
ExecutionPolicy executionPolicy = this.inExecution.computeIfAbsent(action.getLocator(), e -> {
Resource resource = tx.readLock(tx.getResourceFor(action, true));
return tx.getPolicy(resource, ExecutionPolicy.class);
ExecutionPolicy policy = tx.getPolicy(resource, ExecutionPolicy.class);
policy.initialize(action);
return policy;
});
// always update the TX and controller

View File

@ -23,9 +23,11 @@ public abstract class ActionExecutionCommand extends BasePlanningAndExecutionCom
}
protected ExecutionPolicy getExecutionPolicy(Action action) {
if (this.executionPolicy != null)
return this.executionPolicy;
return tx().getPolicy(action, ExecutionPolicy.class);
if (this.executionPolicy == null) {
this.executionPolicy = tx().getPolicy(action, ExecutionPolicy.class);
this.executionPolicy.initialize(action);
}
return this.executionPolicy;
}
@Override

View File

@ -97,7 +97,6 @@ public class PlanAndExecuteActivityCommand extends BasePlanningAndExecutionComma
executionPolicy = getExecutionPolicy(action);
}
executionPolicy.initialize(action);
if (!executionPolicy.isExecutable(action)) {
logger.info("Action " + action.getLocator() + " is not yet executable.");
return;
@ -195,16 +194,7 @@ public class PlanAndExecuteActivityCommand extends BasePlanningAndExecutionComma
}
// stop execution if at least one action is not executable from this entire tree
boolean anyActionNotExecutable = activity.streamActionsDeep().anyMatch(a -> {
if (!a.getState().canSetToExecution())
return false;
ExecutionPolicy executionPolicy = getExecutionPolicy(a);
executionPolicy.initialize(a);
boolean executable = executionPolicy.isExecutable(a);
if (!executable)
logger.info("Action " + a.getLocator() + " is not executable yet!");
return !executable;
});
boolean anyActionNotExecutable = activity.streamActionsDeep().anyMatch(this::isActionExecutable);
if (anyActionNotExecutable)
return;
}
@ -219,4 +209,13 @@ public class PlanAndExecuteActivityCommand extends BasePlanningAndExecutionComma
element.accept(this);
}
}
private boolean isActionExecutable(Action action) {
if (!action.getState().canSetToExecution())
return false;
boolean executable = getExecutionPolicy(action).isExecutable(action);
if (!executable)
logger.info("Action " + action.getLocator() + " is not yet executable!");
return !executable;
}
}