diff --git a/li.strolch.service/src/main/java/li/strolch/execution/EventBasedExecutionHandler.java b/li.strolch.service/src/main/java/li/strolch/execution/EventBasedExecutionHandler.java index a56e92131..eff777436 100644 --- a/li.strolch.service/src/main/java/li/strolch/execution/EventBasedExecutionHandler.java +++ b/li.strolch.service/src/main/java/li/strolch/execution/EventBasedExecutionHandler.java @@ -12,13 +12,13 @@ import li.strolch.agent.api.ObserverEvent; import li.strolch.agent.api.StrolchRealm; import li.strolch.execution.command.ArchiveActivityCommand; import li.strolch.execution.policy.ExecutionPolicy; -import li.strolch.model.log.LogMessage; -import li.strolch.model.log.LogMessageState; -import li.strolch.model.log.LogSeverity; import li.strolch.handler.operationslog.OperationsLog; import li.strolch.model.*; import li.strolch.model.activity.Action; import li.strolch.model.activity.Activity; +import li.strolch.model.log.LogMessage; +import li.strolch.model.log.LogMessageState; +import li.strolch.model.log.LogSeverity; import li.strolch.model.parameter.StringParameter; import li.strolch.persistence.api.StrolchTransaction; import li.strolch.privilege.model.Certificate; @@ -123,6 +123,20 @@ public class EventBasedExecutionHandler extends ExecutionHandler { toExecution(controller); } + @Override + public void toExecution(String realm, Locator activityLoc) { + ExecutionHandlerState state = this.statesByRealm.getOrDefault(realm, ExecutionHandlerState.Running); + if (state == ExecutionHandlerState.HaltNew) + throw new IllegalStateException( + "ExecutionHandler state is " + state + ", can not add activities for execution!"); + + Controller controller = this.controllers.getElement(realm, activityLoc); + if (controller == null) + throw new IllegalStateException("No controller registered for activity " + activityLoc); + + toExecution(controller); + } + @Override public void removeFromExecution(Controller controller) { if (this.controllers.removeElement(controller.getRealm(), controller.getLocator()) != null) { @@ -222,8 +236,8 @@ public class EventBasedExecutionHandler extends ExecutionHandler { runAsAgent(ctx -> getContainer().getRealmNames().forEach(realm -> { try (StrolchTransaction tx = openTx(realm, ctx.getCertificate(), false)) { - Resource executionHandlerConfig = tx - .getResourceBy(TYPE_CONFIGURATION, ExecutionHandler.class.getSimpleName()); + Resource executionHandlerConfig = tx.getResourceBy(TYPE_CONFIGURATION, + ExecutionHandler.class.getSimpleName()); if (executionHandlerConfig == null) { this.statesByRealm.put(realm, ExecutionHandlerState.Running); } else { @@ -256,8 +270,8 @@ public class EventBasedExecutionHandler extends ExecutionHandler { @Override public void setState(Certificate cert, String realm, ExecutionHandlerState state) { try (StrolchTransaction tx = openTx(realm, cert, false)) { - Resource executionHandlerConfig = tx - .getResourceBy(TYPE_CONFIGURATION, ExecutionHandler.class.getSimpleName()); + Resource executionHandlerConfig = tx.getResourceBy(TYPE_CONFIGURATION, + ExecutionHandler.class.getSimpleName()); if (executionHandlerConfig == null) { executionHandlerConfig = new Resource(ExecutionHandler.class.getSimpleName(), "ExecutionHandler Configuration", TYPE_CONFIGURATION); diff --git a/li.strolch.service/src/main/java/li/strolch/execution/ExecutionHandler.java b/li.strolch.service/src/main/java/li/strolch/execution/ExecutionHandler.java index 976155840..da52c62d2 100644 --- a/li.strolch.service/src/main/java/li/strolch/execution/ExecutionHandler.java +++ b/li.strolch.service/src/main/java/li/strolch/execution/ExecutionHandler.java @@ -102,10 +102,21 @@ public abstract class ExecutionHandler extends StrolchComponent { * @param realm * the realm where the {@link Activity} resides * @param activity - * the the {@link Activity} + * the {@link Activity} */ public abstract void toExecution(String realm, Activity activity); + /** + * Triggers the execution of the given {@link Activity}'s {@link Locator}. If the {@link Controller} is available, + * then it is triggered + * + * @param realm + * the realm where the {@link Activity} resides + * @param activityLoc + * the {@link Locator} for the activity to execute + */ + public abstract void toExecution(String realm, Locator activityLoc); + /** * Removes the given {@link Controller} from execution, so it is not executed further *