[Fix] Fixed ExecutionPolicy not initialized before use
This commit is contained in:
parent
9c15d0d1d2
commit
63670a77b6
|
@ -96,7 +96,9 @@ public class Controller {
|
||||||
public ExecutionPolicy refreshExecutionPolicy(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.readLock(tx.getResourceFor(action, true));
|
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
|
// always update the TX and controller
|
||||||
|
|
|
@ -23,9 +23,11 @@ public abstract class ActionExecutionCommand extends BasePlanningAndExecutionCom
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ExecutionPolicy getExecutionPolicy(Action action) {
|
protected ExecutionPolicy getExecutionPolicy(Action action) {
|
||||||
if (this.executionPolicy != null)
|
if (this.executionPolicy == null) {
|
||||||
return this.executionPolicy;
|
this.executionPolicy = tx().getPolicy(action, ExecutionPolicy.class);
|
||||||
return tx().getPolicy(action, ExecutionPolicy.class);
|
this.executionPolicy.initialize(action);
|
||||||
|
}
|
||||||
|
return this.executionPolicy;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -97,7 +97,6 @@ public class PlanAndExecuteActivityCommand extends BasePlanningAndExecutionComma
|
||||||
executionPolicy = getExecutionPolicy(action);
|
executionPolicy = getExecutionPolicy(action);
|
||||||
}
|
}
|
||||||
|
|
||||||
executionPolicy.initialize(action);
|
|
||||||
if (!executionPolicy.isExecutable(action)) {
|
if (!executionPolicy.isExecutable(action)) {
|
||||||
logger.info("Action " + action.getLocator() + " is not yet executable.");
|
logger.info("Action " + action.getLocator() + " is not yet executable.");
|
||||||
return;
|
return;
|
||||||
|
@ -195,16 +194,7 @@ public class PlanAndExecuteActivityCommand extends BasePlanningAndExecutionComma
|
||||||
}
|
}
|
||||||
|
|
||||||
// stop execution if at least one action is not executable from this entire tree
|
// stop execution if at least one action is not executable from this entire tree
|
||||||
boolean anyActionNotExecutable = activity.streamActionsDeep().anyMatch(a -> {
|
boolean anyActionNotExecutable = activity.streamActionsDeep().anyMatch(this::isActionExecutable);
|
||||||
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;
|
|
||||||
});
|
|
||||||
if (anyActionNotExecutable)
|
if (anyActionNotExecutable)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -219,4 +209,13 @@ public class PlanAndExecuteActivityCommand extends BasePlanningAndExecutionComma
|
||||||
element.accept(this);
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue