[New] Added check to not set Action to execution state if already executed in ExecutionPolicy.setActionState()

This commit is contained in:
Robert von Burg 2023-10-27 16:22:41 +02:00
parent 380f5b6597
commit 0b2df5a3b4
Signed by: eitch
GPG Key ID: 75DB9C85C74331F7
1 changed files with 15 additions and 0 deletions

View File

@ -20,6 +20,7 @@ import li.strolch.privilege.model.PrivilegeContext;
import li.strolch.runtime.StrolchConstants;
import li.strolch.runtime.privilege.PrivilegedRunnable;
import li.strolch.runtime.privilege.PrivilegedRunnableWithResult;
import li.strolch.utils.time.PeriodDuration;
import java.time.Duration;
import java.util.concurrent.ThreadLocalRandom;
@ -246,6 +247,9 @@ public abstract class ExecutionPolicy extends StrolchPolicy {
* @param state the new state to set
*/
protected void setActionState(Action action, State state) {
if (action.getState().inClosedPhase())
throw new IllegalStateException("Action " + action.getLocator() + " has state " + action.getState() +
" and can not be changed to " + state);
action.setState(state);
@ -270,6 +274,17 @@ public abstract class ExecutionPolicy extends StrolchPolicy {
return action.findObjectivesParam(PARAM_DURATION, true);
}
/**
* Delays the given {@link Runnable} by the given {@link PeriodDuration}
*
* @param duration the duration to delay
* @param runnable the action to delay
*/
public void delay(PeriodDuration duration, Runnable runnable) {
long delayMs = duration.toMillis();
getDelayedExecutionTimer().delay(delayMs, runnable);
}
/**
* Delays the given {@link Runnable} by the given {@link Duration}
*