[New] Added ExecutionHandler.toExecution(String, Locator)

This commit is contained in:
Robert von Burg 2021-08-03 11:28:02 +02:00
parent cbba1b2dfb
commit 3aa02aeb77
2 changed files with 33 additions and 8 deletions

View File

@ -12,13 +12,13 @@ import li.strolch.agent.api.ObserverEvent;
import li.strolch.agent.api.StrolchRealm; import li.strolch.agent.api.StrolchRealm;
import li.strolch.execution.command.ArchiveActivityCommand; import li.strolch.execution.command.ArchiveActivityCommand;
import li.strolch.execution.policy.ExecutionPolicy; 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.handler.operationslog.OperationsLog;
import li.strolch.model.*; import li.strolch.model.*;
import li.strolch.model.activity.Action; import li.strolch.model.activity.Action;
import li.strolch.model.activity.Activity; 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.model.parameter.StringParameter;
import li.strolch.persistence.api.StrolchTransaction; import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.privilege.model.Certificate; import li.strolch.privilege.model.Certificate;
@ -123,6 +123,20 @@ public class EventBasedExecutionHandler extends ExecutionHandler {
toExecution(controller); 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 @Override
public void removeFromExecution(Controller controller) { public void removeFromExecution(Controller controller) {
if (this.controllers.removeElement(controller.getRealm(), controller.getLocator()) != null) { if (this.controllers.removeElement(controller.getRealm(), controller.getLocator()) != null) {
@ -222,8 +236,8 @@ public class EventBasedExecutionHandler extends ExecutionHandler {
runAsAgent(ctx -> getContainer().getRealmNames().forEach(realm -> { runAsAgent(ctx -> getContainer().getRealmNames().forEach(realm -> {
try (StrolchTransaction tx = openTx(realm, ctx.getCertificate(), false)) { try (StrolchTransaction tx = openTx(realm, ctx.getCertificate(), false)) {
Resource executionHandlerConfig = tx Resource executionHandlerConfig = tx.getResourceBy(TYPE_CONFIGURATION,
.getResourceBy(TYPE_CONFIGURATION, ExecutionHandler.class.getSimpleName()); ExecutionHandler.class.getSimpleName());
if (executionHandlerConfig == null) { if (executionHandlerConfig == null) {
this.statesByRealm.put(realm, ExecutionHandlerState.Running); this.statesByRealm.put(realm, ExecutionHandlerState.Running);
} else { } else {
@ -256,8 +270,8 @@ public class EventBasedExecutionHandler extends ExecutionHandler {
@Override @Override
public void setState(Certificate cert, String realm, ExecutionHandlerState state) { public void setState(Certificate cert, String realm, ExecutionHandlerState state) {
try (StrolchTransaction tx = openTx(realm, cert, false)) { try (StrolchTransaction tx = openTx(realm, cert, false)) {
Resource executionHandlerConfig = tx Resource executionHandlerConfig = tx.getResourceBy(TYPE_CONFIGURATION,
.getResourceBy(TYPE_CONFIGURATION, ExecutionHandler.class.getSimpleName()); ExecutionHandler.class.getSimpleName());
if (executionHandlerConfig == null) { if (executionHandlerConfig == null) {
executionHandlerConfig = new Resource(ExecutionHandler.class.getSimpleName(), executionHandlerConfig = new Resource(ExecutionHandler.class.getSimpleName(),
"ExecutionHandler Configuration", TYPE_CONFIGURATION); "ExecutionHandler Configuration", TYPE_CONFIGURATION);

View File

@ -102,10 +102,21 @@ public abstract class ExecutionHandler extends StrolchComponent {
* @param realm * @param realm
* the realm where the {@link Activity} resides * the realm where the {@link Activity} resides
* @param activity * @param activity
* the the {@link Activity} * the {@link Activity}
*/ */
public abstract void toExecution(String realm, Activity 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 * Removes the given {@link Controller} from execution, so it is not executed further
* *