diff --git a/li.strolch.agent/src/main/java/li/strolch/agent/api/StrolchComponent.java b/li.strolch.agent/src/main/java/li/strolch/agent/api/StrolchComponent.java index 49b92e978..a9b038390 100644 --- a/li.strolch.agent/src/main/java/li/strolch/agent/api/StrolchComponent.java +++ b/li.strolch.agent/src/main/java/li/strolch/agent/api/StrolchComponent.java @@ -425,7 +425,7 @@ public class StrolchComponent { * @return the newly created transaction */ protected StrolchTransaction openTx(Certificate cert, boolean readOnly) { - return getContainer().getRealm(cert).openTx(cert, this.getClass(), readOnly); + return getContainer().getRealm(cert).openTx(cert, getClass(), readOnly); } /** @@ -457,7 +457,7 @@ public class StrolchComponent { * @return the newly created transaction */ protected StrolchTransaction openTx(String realm, Certificate cert, boolean readOnly) { - return getContainer().getRealm(realm).openTx(cert, this.getClass(), readOnly); + return getContainer().getRealm(realm).openTx(cert, getClass(), readOnly); } /** diff --git a/li.strolch.agent/src/main/java/li/strolch/persistence/api/AbstractTransaction.java b/li.strolch.agent/src/main/java/li/strolch/persistence/api/AbstractTransaction.java index 0114f9847..2ccb64bbd 100644 --- a/li.strolch.agent/src/main/java/li/strolch/persistence/api/AbstractTransaction.java +++ b/li.strolch.agent/src/main/java/li/strolch/persistence/api/AbstractTransaction.java @@ -416,13 +416,14 @@ public abstract class AbstractTransaction implements StrolchTransaction { } @Override - public T findElement(Locator locator) throws StrolchException, ClassCastException { + public T findElement(Locator locator) throws StrolchModelException, ClassCastException { return findElement(locator, false); } @SuppressWarnings("unchecked") @Override - public T findElement(Locator locator, boolean allowNull) { + public T findElement(Locator locator, boolean allowNull) + throws StrolchModelException, ClassCastException { // Resource// // Resource///Bag/ @@ -435,7 +436,7 @@ public abstract class AbstractTransaction implements StrolchTransaction { if (locator.getSize() < 3) { String msg = "The locator is invalid as it does not have at least three path elements (e.g. Resource/MyType/@id): {0}"; //$NON-NLS-1$ msg = MessageFormat.format(msg, locator.toString()); - throw new StrolchException(msg); + throw new StrolchModelException(msg); } List elements = locator.getPathElements(); @@ -454,14 +455,15 @@ public abstract class AbstractTransaction implements StrolchTransaction { groupedParameterizedElement = getActivityBy(type, id); break; default: - throw new StrolchException(MessageFormat.format("Unknown object class {0}", objectClassType)); //$NON-NLS-1$ + throw new StrolchModelException( + MessageFormat.format("Unknown object class {0}", objectClassType)); //$NON-NLS-1$ } if (groupedParameterizedElement == null) { if (allowNull) return null; String msg = "No top level object could be found with locator {0}"; //$NON-NLS-1$ - throw new StrolchException(MessageFormat.format(msg, locator)); + throw new StrolchModelException(MessageFormat.format(msg, locator)); } if (elements.size() == 3) @@ -477,7 +479,7 @@ public abstract class AbstractTransaction implements StrolchTransaction { if (allowNull) return null; String msg = "Could not find ParameterBag for locator {0} on element {1}"; //$NON-NLS-1$ - throw new StrolchException( + throw new StrolchModelException( MessageFormat.format(msg, locator, groupedParameterizedElement.getLocator())); } @@ -490,7 +492,7 @@ public abstract class AbstractTransaction implements StrolchTransaction { if (allowNull) return null; String msg = "Could not find Parameter for locator {0} on element {1}"; //$NON-NLS-1$ - throw new StrolchException(MessageFormat.format(msg, locator, bag.getLocator())); + throw new StrolchModelException(MessageFormat.format(msg, locator, bag.getLocator())); } return (T) parameter; @@ -498,9 +500,10 @@ public abstract class AbstractTransaction implements StrolchTransaction { if (elements.size() != 5) { String msg = "Missing state Id on locator {0}"; //$NON-NLS-1$ - throw new StrolchException(MessageFormat.format(msg, locator)); + throw new StrolchModelException(MessageFormat.format(msg, locator)); } + @SuppressWarnings("ConstantConditions") Resource resource = (Resource) groupedParameterizedElement; String stateId = elements.get(4); @@ -518,7 +521,7 @@ public abstract class AbstractTransaction implements StrolchTransaction { if (!(element instanceof Activity)) { String msg = "Invalid locator {0} with part {1} as not an Activity but deeper element specified"; //$NON-NLS-1$ - throw new StrolchException(MessageFormat.format(msg, locator, next)); + throw new StrolchModelException(MessageFormat.format(msg, locator, next)); } element = ((Activity) element).getElement(next); @@ -531,7 +534,7 @@ public abstract class AbstractTransaction implements StrolchTransaction { return null; String msg = "Invalid locator {0} with part {1}"; //$NON-NLS-1$ - throw new StrolchException(MessageFormat.format(msg, locator, stateOrBagOrActivity)); + throw new StrolchModelException(MessageFormat.format(msg, locator, stateOrBagOrActivity)); } @Override diff --git a/li.strolch.agent/src/main/java/li/strolch/persistence/api/StrolchTransaction.java b/li.strolch.agent/src/main/java/li/strolch/persistence/api/StrolchTransaction.java index 9f19e18af..23d49cf74 100644 --- a/li.strolch.agent/src/main/java/li/strolch/persistence/api/StrolchTransaction.java +++ b/li.strolch.agent/src/main/java/li/strolch/persistence/api/StrolchTransaction.java @@ -534,11 +534,11 @@ public interface StrolchTransaction extends AutoCloseable { * Used to find a {@link StrolchElement} by a {@link Locator}, throwing exception if the element is not found *

* - * @throws StrolchException + * @throws StrolchModelException * if the element could not be found * @see #findElement(Locator, boolean) */ - T findElement(Locator locator) throws StrolchException, ClassCastException; + T findElement(Locator locator) throws StrolchModelException, ClassCastException; /** *

@@ -565,14 +565,14 @@ public interface StrolchTransaction extends AutoCloseable { * an inexistant {@link Resource} or an inexistand {@link Parameter} on a Resource, then a {@link StrolchException} * is thrown * - * @throws StrolchException + * @throws StrolchModelException * if the element could not be found and {@code allowNull} is false * @throws ClassCastException * if the querying code is not asking for the correct instance. Do not query a {@link Parameter} if the variable * to which the result is to be is stored is a {@link Resource}, etc. */ T findElement(Locator locator, boolean allowNull) - throws StrolchException, ClassCastException; + throws StrolchModelException, ClassCastException; /** *

Finds a parameter with the given @bagKey and @paramKey on the given @element, but if it does not exists diff --git a/li.strolch.agent/src/main/java/li/strolch/service/api/Command.java b/li.strolch.agent/src/main/java/li/strolch/service/api/Command.java index b6ff122ee..1bf35902a 100644 --- a/li.strolch.agent/src/main/java/li/strolch/service/api/Command.java +++ b/li.strolch.agent/src/main/java/li/strolch/service/api/Command.java @@ -304,11 +304,12 @@ public abstract class Command implements Restrictable { /** *

- * Should the transaction fail, either due to a {@link Command} throwing an exception when {@link #validate()} is - * called, or while committing the transaction, then this method should properly undo any changes it has done. It is - * imperative that this method does not throw further exceptions and that the state to be rolled back is remembered - * in the Command during committing + * This method can be used to undo actions peformed during the command, should the TX fail. In earlier versions of + * Strolch this was important to undo model changes, but the model changes are only visible after a commit succeeds, + * so this is no longer necessary. *

*/ - public abstract void undo(); + public void undo() { + // do nothing + } } diff --git a/li.strolch.model/src/main/java/li/strolch/model/State.java b/li.strolch.model/src/main/java/li/strolch/model/State.java index 224be9018..4f64e5f72 100644 --- a/li.strolch.model/src/main/java/li/strolch/model/State.java +++ b/li.strolch.model/src/main/java/li/strolch/model/State.java @@ -30,6 +30,7 @@ public enum State { CREATED("Created"), //$NON-NLS-1$ PLANNING("Planning"), //$NON-NLS-1$ PLANNED("Planned"), //$NON-NLS-1$ + EXECUTABLE("Executable"), //$NON-NLS-1$ EXECUTION("Execution"), //$NON-NLS-1$ WARNING("Warning"), //$NON-NLS-1$ ERROR("Error"), //$NON-NLS-1$ @@ -39,7 +40,7 @@ public enum State { private String state; - private State(String state) { + State(String state) { this.state = state; } @@ -62,8 +63,8 @@ public enum State { } /** - * @return true if the state is one of {@link #EXECUTION}, {@link #STOPPED}, {@link #WARNING}, {@link #ERROR} or - * {@link #EXECUTED} + * @return true if the state is one of {@link #EXECUTABLE} {@link #EXECUTION}, {@link #STOPPED}, {@link #WARNING}, + * {@link #ERROR} or {@link #EXECUTED} */ public boolean inExecutionPhase() { return this == EXECUTION || this == STOPPED || this == WARNING || this == ERROR; @@ -168,10 +169,17 @@ public enum State { } /** - * @return true if {@link #CREATED} or {@link #PLANNING} or {@link #PLANNED} or {@link #EXECUTION} or {@link #STOPPED} + * @return true if {@link #PLANNED} or {@link #EXECUTABLE} or {@link #EXECUTION} */ - public boolean canSetToExecution() { - return this == CREATED || this == PLANNING || this == PLANNED || this == EXECUTION || this == State.STOPPED; + public boolean isExecutable() { + return this == PLANNED || this == EXECUTABLE || this == EXECUTION; + } + + /** + * @return true if state >= {@link #EXECUTED} + */ + public boolean canNotSetToExecution() { + return this.compareTo(State.EXECUTED) >= 0; } /** @@ -249,7 +257,7 @@ public enum State { return WARNING; // execution - if (states.contains(EXECUTION)) + if (states.contains(EXECUTABLE) || states.contains(EXECUTION)) return EXECUTION; if (states.contains(EXECUTED) && (states.contains(CREATED) || states.contains(PLANNING) || states .contains(PLANNED))) @@ -275,4 +283,5 @@ public enum State { // should never happen, unless new state is introduced throw new IllegalStateException("Unhandled situation with states: " + states.stream().map(e -> e.state) .collect(Collectors.joining(", "))); - }} + } +} diff --git a/li.strolch.model/src/main/java/li/strolch/model/activity/Activity.java b/li.strolch.model/src/main/java/li/strolch/model/activity/Activity.java index 1e8583ee2..d078b758b 100644 --- a/li.strolch.model/src/main/java/li/strolch/model/activity/Activity.java +++ b/li.strolch.model/src/main/java/li/strolch/model/activity/Activity.java @@ -381,6 +381,27 @@ public class Activity extends AbstractStrolchRootElement } } + public T getElementByLocator(Locator locator) { + DBC.PRE.assertEquals("Locator is not for this activity!", getLocator(), locator.trim(3)); + DBC.PRE.assertTrue("Locator must have at least 5 parts", locator.getSize() >= 4); + + IActivityElement element = this; + for (int i = 3; i < locator.getSize(); i++) { + String next = locator.get(i); + + if (!(element instanceof Activity)) { + String msg = "Invalid locator {0} with part {1} as not an Activity but deeper element specified"; //$NON-NLS-1$ + throw new StrolchModelException(MessageFormat.format(msg, locator, next)); + } + + element = ((Activity) element).getElement(next); + } + + @SuppressWarnings("unchecked") + T t = (T) element; + return t; + } + /** * @return the iterator for entries, which include the id as key and the {@link IActivityElement} as value */ diff --git a/li.strolch.service/src/main/java/li/strolch/execution/ArchiveExecutedActivitiesJob.java b/li.strolch.service/src/main/java/li/strolch/execution/ArchiveExecutedActivitiesJob.java index b91f9a6ee..0d8215415 100644 --- a/li.strolch.service/src/main/java/li/strolch/execution/ArchiveExecutedActivitiesJob.java +++ b/li.strolch.service/src/main/java/li/strolch/execution/ArchiveExecutedActivitiesJob.java @@ -3,6 +3,7 @@ package li.strolch.execution; import java.util.concurrent.TimeUnit; import li.strolch.agent.api.StrolchAgent; +import li.strolch.execution.command.ArchiveActivityCommand; import li.strolch.job.JobMode; import li.strolch.job.StrolchJob; import li.strolch.model.State; @@ -23,13 +24,16 @@ public class ArchiveExecutedActivitiesJob extends StrolchJob { @Override protected void execute(PrivilegeContext ctx) { - ExecutionHandler executionHandler = getComponent(ExecutionHandler.class); - - try (StrolchTransaction tx = openTx(ctx.getCertificate(), true)) { + try (StrolchTransaction tx = openTx(ctx.getCertificate())) { tx.streamActivities().forEach(activity -> { - if (activity.getState() == State.EXECUTED) - executionHandler.archiveActivity(tx.getRealmName(), activity.getLocator()); + if (activity.getState() == State.EXECUTED) { + ArchiveActivityCommand command = new ArchiveActivityCommand(tx); + command.setActivity(activity); + tx.addCommand(command); + } }); + + tx.commitOnClose(); } } } diff --git a/li.strolch.service/src/main/java/li/strolch/execution/Controller.java b/li.strolch.service/src/main/java/li/strolch/execution/Controller.java new file mode 100644 index 000000000..e2888d36f --- /dev/null +++ b/li.strolch.service/src/main/java/li/strolch/execution/Controller.java @@ -0,0 +1,70 @@ +package li.strolch.execution; + +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +import li.strolch.execution.command.ExecuteActivityCommand; +import li.strolch.execution.policy.ExecutionPolicy; +import li.strolch.model.Locator; +import li.strolch.model.State; +import li.strolch.model.activity.Activity; +import li.strolch.persistence.api.StrolchTransaction; +import li.strolch.privilege.base.PrivilegeException; +import li.strolch.privilege.model.Certificate; +import li.strolch.privilege.model.PrivilegeContext; +import li.strolch.runtime.privilege.PrivilegedRunnable; + +public class Controller { + + private ExecutionHandler executionHandler; + private Activity activity; + private Map inExecution; + + public Controller(ExecutionHandler executionHandler, Activity activity) { + this.executionHandler = executionHandler; + this.activity = activity; + this.inExecution = new HashMap<>(); + } + + public State getState() { + return this.activity.getState(); + } + + public Activity getActivity() { + return this.activity; + } + + public Set getInExecution() { + return this.inExecution.keySet(); + } + + protected StrolchTransaction openTx(Certificate cert) { + return this.executionHandler.openTx(cert, getClass(), false); + } + + protected void runAsAgent(PrivilegedRunnable runnable) throws PrivilegeException, Exception { + this.executionHandler.runAsAgent(runnable); + } + + private Activity refreshActivity(StrolchTransaction tx) { + this.activity = tx.getActivityBy(this.activity.getType(), this.activity.getId(), true); + return this.activity; + } + + public void execute() { + try (StrolchTransaction tx = openTx(ctx.getCertificate())) { + + ExecuteActivityCommand command = new ExecuteActivityCommand(tx); + command.setActivity(refreshActivity(tx)); + command.validate(); + command.doCommand(); + + tx.commitOnClose(); + } + } + + public void stop() { + + } +} 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 29f8b4c18..38f2b500c 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 @@ -1,7 +1,9 @@ package li.strolch.execution; +import static java.util.Collections.emptySet; import static li.strolch.model.StrolchModelConstants.*; import static li.strolch.runtime.StrolchConstants.SYSTEM_USER_AGENT; +import static li.strolch.utils.collections.SynchronizedCollections.synchronizedMapOfMaps; import java.util.*; import java.util.concurrent.ExecutorService; @@ -9,7 +11,6 @@ import java.util.concurrent.ExecutorService; import li.strolch.agent.api.ComponentContainer; import li.strolch.agent.api.ObserverEvent; import li.strolch.execution.command.*; -import li.strolch.execution.policy.ActivityArchivalPolicy; import li.strolch.execution.policy.ExecutionPolicy; import li.strolch.handler.operationslog.LogMessage; import li.strolch.handler.operationslog.LogSeverity; @@ -19,13 +20,11 @@ import li.strolch.model.activity.Action; import li.strolch.model.activity.Activity; import li.strolch.model.activity.IActivityElement; import li.strolch.model.parameter.StringParameter; -import li.strolch.model.policy.PolicyDef; import li.strolch.persistence.api.StrolchTransaction; -import li.strolch.policy.PolicyHandler; import li.strolch.privilege.model.Certificate; import li.strolch.privilege.model.PrivilegeContext; import li.strolch.runtime.configuration.ComponentConfiguration; -import li.strolch.utils.collections.MapOfSets; +import li.strolch.utils.collections.MapOfMaps; import li.strolch.utils.dbc.DBC; /** @@ -36,11 +35,10 @@ import li.strolch.utils.dbc.DBC; */ public class EventBasedExecutionHandler extends ExecutionHandler { - private static final String KEY_DEFAULT_ACTIVITY_ARCHIVAL = "key:DefaultActivityArchival"; private static final String PROP_RESTART_EXECUTION = "restartExecution"; private Map statesByRealm; - private MapOfSets registeredActivities; + private MapOfMaps controllers; private DelayedExecutionTimer delayedExecutionTimer; @@ -48,11 +46,23 @@ public class EventBasedExecutionHandler extends ExecutionHandler { super(container, componentName); } + private ExecutorService getExecutor() { + return getExecutorService("ExecutionHandler"); + } + + @Override + public Set getActiveActivitiesLocator(String realm) { + if (this.controllers == null) + return emptySet(); + Map activities = this.controllers.getMap(realm); + if (activities == null) + return emptySet(); + return activities.keySet(); + } + @Override public void initialize(ComponentConfiguration configuration) throws Exception { - - this.registeredActivities = new MapOfSets<>(); - + this.controllers = synchronizedMapOfMaps(new MapOfMaps<>()); super.initialize(configuration); } @@ -85,67 +95,34 @@ public class EventBasedExecutionHandler extends ExecutionHandler { super.stop(); } - @Override - public Set getActiveActivitiesLocator(String realm) { - if (this.registeredActivities == null || !this.registeredActivities.containsSet(realm)) - return Collections.emptySet(); - - synchronized (this.registeredActivities) { - return new HashSet<>(this.registeredActivities.getSet(realm)); - } - } - @Override public void addForExecution(String realm, Activity activity) { - 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!"); - Locator rootElemLoc = activity.getLocator(); - synchronized (this.registeredActivities) { - this.registeredActivities.addElement(realm, rootElemLoc); - } - - notifyObserverAdd(realm, activity); - toExecution(realm, rootElemLoc); - } - - @Override - public void addForExecution(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!"); - - Locator rootElemLoc = activityLoc.trim(3); - synchronized (this.registeredActivities) { - this.registeredActivities.addElement(realm, rootElemLoc); - } - - getExecutor().submit(() -> notifyObserverAdd(realm, activityLoc)); - toExecution(realm, activityLoc); + Controller controller = new Controller(this, activity); + this.controllers.addElement(realm, activity.getLocator(), controller); + notifyObserverAdd(realm, controller); + toExecution(realm, activity); } @Override public void removeFromExecution(String realm, Locator activityLoc) { Locator rootElemLoc = activityLoc.trim(3); - synchronized (this.registeredActivities) { - this.registeredActivities.removeElement(realm, rootElemLoc); - } - getExecutor().submit(() -> notifyObserverRemove(realm, activityLoc)); + Controller controller = this.controllers.removeElement(realm, rootElemLoc); + if (controller != null) + getExecutor().submit(() -> notifyObserverRemove(realm, controller)); } @Override public void clearAllCurrentExecutions(String realm) { - Set removed = this.registeredActivities.removeSet(realm); + Map removed = this.controllers.removeMap(realm); getExecutor().submit(() -> notifyObserverRemove(realm, removed)); } private void restartActivityExecution(PrivilegeContext ctx) { - // iterate the realms for (String realmName : getContainer().getRealmNames()) { reloadActivitiesInExecution(ctx, realmName); @@ -180,7 +157,8 @@ public class EventBasedExecutionHandler extends ExecutionHandler { tx.update(activity); // register for execution - this.registeredActivities.addElement(realmName, activity.getLocator()); + Controller controller = new Controller(this, activity); + this.controllers.addElement(realmName, activity.getLocator(), controller); }); // commit changes to state @@ -200,12 +178,12 @@ public class EventBasedExecutionHandler extends ExecutionHandler { return; } - synchronized (this.registeredActivities) { - Set locators = this.registeredActivities.getSet(realm); - if (locators != null) { - for (Locator locator : locators) { + synchronized (this.controllers) { + Map controllers = this.controllers.getMap(realm); + if (controllers != null) { + for (Controller controller : controllers.values()) { // execute async - toExecution(realm, locator); + toExecution(realm, controller); } } } @@ -283,23 +261,23 @@ public class EventBasedExecutionHandler extends ExecutionHandler { } @Override - public void toExecution(String realm, Locator locator) { + public void toExecution(String realm, Activity activity) { ExecutionHandlerState state = this.statesByRealm.getOrDefault(realm, ExecutionHandlerState.Running); if (state == ExecutionHandlerState.Paused) { - logger.warn("Ignoring execution of " + locator + " for paused realm " + realm); + logger.warn("Ignoring execution of " + activity.getLocator() + " for paused realm " + realm); return; } getExecutor().execute(() -> { try { - runAsAgent(ctx -> toExecution(realm, locator, ctx)); + runAsAgent(ctx -> toExecution(realm, activity, ctx)); } catch (Exception e) { - logger.error("Failed to set " + locator + " to execution due to " + e.getMessage(), e); + logger.error("Failed to set " + activity.getLocator() + " to execution", e); if (getContainer().hasComponent(OperationsLog.class)) { getComponent(OperationsLog.class).addMessage( - new LogMessage(realm, SYSTEM_USER_AGENT, locator, LogSeverity.Exception, + new LogMessage(realm, SYSTEM_USER_AGENT, activity.getLocator(), LogSeverity.Exception, ResourceBundle.getBundle("strolch-service"), "execution.handler.failed.execution") .withException(e).value("reason", e)); } @@ -307,17 +285,11 @@ public class EventBasedExecutionHandler extends ExecutionHandler { }); } - private ExecutorService getExecutor() { - return getExecutorService("ExecutionHandler"); - } - @Override public void toExecuted(String realm, Locator locator) { getExecutor().execute(() -> { try { - runAsAgent(ctx -> { - toExecuted(realm, locator, ctx); - }); + runAsAgent(ctx -> toExecuted(realm, locator, ctx)); } catch (Exception e) { logger.error("Failed to set " + locator + " to executed due to " + e.getMessage(), e); @@ -335,9 +307,7 @@ public class EventBasedExecutionHandler extends ExecutionHandler { public void toStopped(String realm, Locator locator) { getExecutor().execute(() -> { try { - runAsAgent(ctx -> { - toStopped(realm, locator, ctx); - }); + runAsAgent(ctx -> toStopped(realm, locator, ctx)); } catch (Exception e) { logger.error("Failed to set " + locator + " to stopped due to " + e.getMessage(), e); @@ -355,9 +325,7 @@ public class EventBasedExecutionHandler extends ExecutionHandler { public void toError(String realm, Locator locator) { getExecutor().execute(() -> { try { - runAsAgent(ctx -> { - toError(realm, locator, ctx); - }); + runAsAgent(ctx -> toError(realm, locator, ctx)); } catch (Exception e) { logger.error("Failed to set " + locator + " to error due to " + e.getMessage(), e); @@ -375,9 +343,7 @@ public class EventBasedExecutionHandler extends ExecutionHandler { public void toWarning(String realm, Locator locator) { getExecutor().execute(() -> { try { - runAsAgent(ctx -> { - toWarning(realm, locator, ctx); - }); + runAsAgent(ctx -> toWarning(realm, locator, ctx)); } catch (Exception e) { logger.error("Failed to set " + locator + " to warning due to " + e.getMessage(), e); @@ -392,42 +358,24 @@ public class EventBasedExecutionHandler extends ExecutionHandler { } @Override - public void archiveActivity(String realm, Locator activityLoc) { + public void archiveActivity(String realm, Activity activity) { getExecutor().execute(() -> { try { runAsAgent(ctx -> { - try (StrolchTransaction tx = openTx(realm, ctx.getCertificate(), ActivityArchivalPolicy.class, + try (StrolchTransaction tx = openTx(realm, ctx.getCertificate(), ArchiveActivityCommand.class, false)) { - tx.lock(activityLoc); - - Activity activity = tx.findElement(activityLoc, true); - if (activity == null) { - return; - } - - logger.info("Activity " + activity.getLocator() + " is in state " + activity.getState()); - - PolicyDef policyDef; - if (activity.hasPolicyDef(ActivityArchivalPolicy.class.getSimpleName())) { - policyDef = activity.getPolicyDef(ActivityArchivalPolicy.class.getSimpleName()); - } else { - policyDef = PolicyDef.valueOf(ActivityArchivalPolicy.class.getSimpleName(), - KEY_DEFAULT_ACTIVITY_ARCHIVAL); - } - - PolicyHandler policyHandler = getComponent(PolicyHandler.class); - ActivityArchivalPolicy archivalPolicy = policyHandler.getPolicy(policyDef, tx); - archivalPolicy.archive(activity); - + ArchiveActivityCommand command = new ArchiveActivityCommand(tx); + command.setActivityLoc(activity.getLocator()); + tx.addCommand(command); tx.commitOnClose(); } }); } catch (Exception e) { - logger.error("Failed to archive " + activityLoc + " due to " + e.getMessage(), e); + logger.error("Failed to archive " + activity.getLocator() + " due to " + e.getMessage(), e); if (getContainer().hasComponent(OperationsLog.class)) { getComponent(OperationsLog.class).addMessage( - new LogMessage(realm, SYSTEM_USER_AGENT, activityLoc, LogSeverity.Exception, + new LogMessage(realm, SYSTEM_USER_AGENT, activity.getLocator(), LogSeverity.Exception, ResourceBundle.getBundle("strolch-service"), "execution.handler.failed.archive") .withException(e).value("reason", e)); } @@ -596,27 +544,7 @@ public class EventBasedExecutionHandler extends ExecutionHandler { triggerExecution(realm); } - private void notifyObserverAdd(String realm, Locator activityLoc) { - if (!getContainer().getRealm(realm).isUpdateObservers()) - return; - - try { - runAsAgent(ctx -> { - try (StrolchTransaction tx = openTx(realm, ctx.getCertificate(), true)) { - Activity activity = tx.findElement(activityLoc, true); - if (activity != null) { - ObserverEvent observerEvent = new ObserverEvent(); - observerEvent.added.addElement(Tags.CONTROLLER, activity); - getContainer().getRealm(realm).getObserverHandler().notify(observerEvent); - } - } - }); - } catch (Exception e) { - logger.error("Failed to notify observers of new controller " + activityLoc); - } - } - - private void notifyObserverAdd(String realm, Activity rootElement) { + private void notifyObserverAdd(String realm, Controller controller) { if (!getContainer().getRealm(realm).isUpdateObservers()) return; @@ -625,7 +553,7 @@ public class EventBasedExecutionHandler extends ExecutionHandler { getContainer().getRealm(realm).getObserverHandler().notify(observerEvent); } - private void notifyObserverUpdate(StrolchTransaction tx, Activity rootElement) { + private void notifyObserverUpdate(StrolchTransaction tx, Controller controller) { if (!getContainer().getRealm(tx.getRealmName()).isUpdateObservers()) return; @@ -634,7 +562,7 @@ public class EventBasedExecutionHandler extends ExecutionHandler { tx.getContainer().getRealm(tx.getRealmName()).getObserverHandler().notify(observerEvent); } - private void notifyObserverRemove(StrolchTransaction tx, Activity rootElement) { + private void notifyObserverRemove(StrolchTransaction tx, Controller controller) { if (!getContainer().getRealm(tx.getRealmName()).isUpdateObservers()) return; @@ -643,7 +571,7 @@ public class EventBasedExecutionHandler extends ExecutionHandler { tx.getContainer().getRealm(tx.getRealmName()).getObserverHandler().notify(observerEvent); } - private void notifyObserverRemove(String realm, Locator activityLoc) { + private void notifyObserverRemove(String realm, Controller controller) { if (!getContainer().getRealm(realm).isUpdateObservers()) return; @@ -663,7 +591,7 @@ public class EventBasedExecutionHandler extends ExecutionHandler { } } - private void notifyObserverRemove(String realm, Set activityLocs) { + private void notifyObserverRemove(String realm, Map removed) { if (!getContainer().getRealm(realm).isUpdateObservers()) return; 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 e33faca4c..b93c37478 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 @@ -11,8 +11,11 @@ import li.strolch.model.State; import li.strolch.model.activity.Action; import li.strolch.model.activity.Activity; import li.strolch.model.activity.TimeOrdering; +import li.strolch.persistence.api.StrolchTransaction; +import li.strolch.privilege.base.PrivilegeException; import li.strolch.privilege.model.Certificate; import li.strolch.privilege.model.PrivilegeContext; +import li.strolch.runtime.privilege.PrivilegedRunnable; /** *

@@ -41,16 +44,13 @@ public abstract class ExecutionHandler extends StrolchComponent { public static final String PARAM_STATE = "state"; - /** - * Registers the given {@link Locator} of an {@link Activity} for execution, and submits it for execution - * immediately in an asynchronous manner - * - * @param realm - * the realm where the {@link Activity} resides - * @param activityLoc - * the {@link Locator} of the {@link Activity} - */ - public abstract void addForExecution(String realm, Locator activityLoc); + public StrolchTransaction openTx(Certificate cert, Class action, boolean readOnly) { + return super.openTx(cert, action.getName(), readOnly); + } + + public void runAsAgent(PrivilegedRunnable runnable) throws PrivilegeException, Exception { + super.runAsAgent(runnable); + } /** * Registers the given {@link Activity} for execution, and submits it for execution immediately in an asynchronous @@ -126,10 +126,10 @@ public abstract class ExecutionHandler extends StrolchComponent { * * @param realm * the realm where the activity resides - * @param activityLoc - * the {@link Locator} of the {@link Activity} + * @param activity + * the {@link Activity} */ - public abstract void archiveActivity(String realm, Locator activityLoc); + public abstract void archiveActivity(String realm, Activity activity); /** * Returns the {@link Set} of {@link Locator Locators} of {@link Activity Activities} which are registered for @@ -157,14 +157,14 @@ public abstract class ExecutionHandler extends StrolchComponent { public abstract DelayedExecutionTimer getDelayedExecutionTimer(); /** - * Starts the execution of the given {@link Activity} with the given {@link Locator} + * Starts the execution of the given {@link Activity} * * @param realm * the realm where the {@link Activity} resides - * @param activityLoc - * the {@link Locator} of the {@link Activity} + * @param activity + * the {@link Activity} */ - public abstract void toExecution(String realm, Locator activityLoc); + public abstract void toExecution(String realm, Activity activity); /** * Completes the execution of the given {@link Action} with the given {@link Locator} diff --git a/li.strolch.service/src/main/java/li/strolch/execution/command/ArchiveActivityCommand.java b/li.strolch.service/src/main/java/li/strolch/execution/command/ArchiveActivityCommand.java new file mode 100644 index 000000000..1b6bcd8d4 --- /dev/null +++ b/li.strolch.service/src/main/java/li/strolch/execution/command/ArchiveActivityCommand.java @@ -0,0 +1,54 @@ +package li.strolch.execution.command; + +import li.strolch.execution.policy.ActivityArchivalPolicy; +import li.strolch.model.Locator; +import li.strolch.model.activity.Activity; +import li.strolch.model.policy.PolicyDef; +import li.strolch.persistence.api.StrolchTransaction; +import li.strolch.policy.PolicyHandler; +import li.strolch.service.api.Command; +import li.strolch.utils.dbc.DBC; + +public class ArchiveActivityCommand extends Command { + + private static final String KEY_DEFAULT_ACTIVITY_ARCHIVAL = "key:DefaultActivityArchival"; + + private Locator activityLoc; + + public ArchiveActivityCommand(StrolchTransaction tx) { + super(tx); + } + + public void setActivityLoc(Locator activityLoc) { + this.activityLoc = activityLoc; + } + + @Override + public void validate() { + DBC.PRE.assertNotNull("activity can not be null!", this.activityLoc); + } + + @Override + public void doCommand() { + tx().lock(this.activityLoc); + + Activity activity = tx().getActivityBy(this.activityLoc.get(1), this.activityLoc.get(2)); + if (activity == null) { + logger.error("Activity " + this.activityLoc + " does not exist anymore, can not archive!"); + return; + } + + logger.info("Activity " + activity.getLocator() + " is in state " + activity.getState()); + + PolicyDef policyDef; + if (activity.hasPolicyDef(ActivityArchivalPolicy.class.getSimpleName())) { + policyDef = activity.getPolicyDef(ActivityArchivalPolicy.class.getSimpleName()); + } else { + policyDef = PolicyDef.valueOf(ActivityArchivalPolicy.class.getSimpleName(), KEY_DEFAULT_ACTIVITY_ARCHIVAL); + } + + PolicyHandler policyHandler = getComponent(PolicyHandler.class); + ActivityArchivalPolicy archivalPolicy = policyHandler.getPolicy(policyDef, tx()); + archivalPolicy.archive(activity); + } +} diff --git a/li.strolch.service/src/main/java/li/strolch/execution/command/ExecuteActivityCommand.java b/li.strolch.service/src/main/java/li/strolch/execution/command/ExecuteActivityCommand.java index b50b711e0..493202a4f 100644 --- a/li.strolch.service/src/main/java/li/strolch/execution/command/ExecuteActivityCommand.java +++ b/li.strolch.service/src/main/java/li/strolch/execution/command/ExecuteActivityCommand.java @@ -1,6 +1,5 @@ package li.strolch.execution.command; -import li.strolch.agent.api.ComponentContainer; import li.strolch.model.State; import li.strolch.model.activity.Activity; import li.strolch.persistence.api.StrolchTransaction; @@ -10,8 +9,8 @@ public class ExecuteActivityCommand extends ExecutionCommand { private Activity activity; - public ExecuteActivityCommand(ComponentContainer container, StrolchTransaction tx) { - super(container, tx); + public ExecuteActivityCommand(StrolchTransaction tx) { + super(tx); } public void setActivity(Activity activity) { @@ -21,7 +20,6 @@ public class ExecuteActivityCommand extends ExecutionCommand { @Override public void validate() { DBC.PRE.assertNotNull("activity can not be null!", this.activity); - tx().lock(this.activity.getRootElement()); } @Override @@ -34,9 +32,4 @@ public class ExecuteActivityCommand extends ExecutionCommand { updateOrderState(tx(), rootElement, currentState, rootElement.getState()); } - - @Override - public void undo() { - // can't undo execution - } } diff --git a/li.strolch.service/src/main/java/li/strolch/execution/command/ExecuteStoppedActionCommand.java b/li.strolch.service/src/main/java/li/strolch/execution/command/ExecuteStoppedActionCommand.java index c72aab5c7..615dd8477 100644 --- a/li.strolch.service/src/main/java/li/strolch/execution/command/ExecuteStoppedActionCommand.java +++ b/li.strolch.service/src/main/java/li/strolch/execution/command/ExecuteStoppedActionCommand.java @@ -2,7 +2,6 @@ package li.strolch.execution.command; import java.text.MessageFormat; -import li.strolch.agent.api.ComponentContainer; import li.strolch.exception.StrolchException; import li.strolch.model.State; import li.strolch.model.activity.Action; @@ -14,8 +13,8 @@ public class ExecuteStoppedActionCommand extends ExecutionCommand { private Action action; - public ExecuteStoppedActionCommand(ComponentContainer container, StrolchTransaction tx) { - super(container, tx); + public ExecuteStoppedActionCommand(StrolchTransaction tx) { + super(tx); } public void setAction(Action action) { @@ -47,9 +46,4 @@ public class ExecuteStoppedActionCommand extends ExecutionCommand { updateOrderState(tx(), rootElement, currentState, rootElement.getState()); } - - @Override - public void undo() { - // can't undo execution - } } diff --git a/li.strolch.service/src/main/java/li/strolch/execution/command/ExecutionCommand.java b/li.strolch.service/src/main/java/li/strolch/execution/command/ExecutionCommand.java index 6fbfd12eb..f532ed989 100644 --- a/li.strolch.service/src/main/java/li/strolch/execution/command/ExecutionCommand.java +++ b/li.strolch.service/src/main/java/li/strolch/execution/command/ExecutionCommand.java @@ -8,7 +8,6 @@ import static li.strolch.utils.helper.StringHelper.isEmpty; import java.util.Iterator; import java.util.Map.Entry; -import li.strolch.agent.api.ComponentContainer; import li.strolch.exception.StrolchException; import li.strolch.execution.policy.ConfirmationPolicy; import li.strolch.execution.policy.ExecutionPolicy; @@ -29,8 +28,8 @@ import li.strolch.service.api.Command; public abstract class ExecutionCommand extends Command implements TimeOrderingVisitor, IActivityElementVisitor { - public ExecutionCommand(ComponentContainer container, StrolchTransaction tx) { - super(container, tx); + public ExecutionCommand(StrolchTransaction tx) { + super(tx); } protected Locator getResourceLocator(Action action) { diff --git a/li.strolch.service/src/main/java/li/strolch/execution/command/PlanActionCommand.java b/li.strolch.service/src/main/java/li/strolch/execution/command/PlanActionCommand.java index 754fa6668..7413c604d 100644 --- a/li.strolch.service/src/main/java/li/strolch/execution/command/PlanActionCommand.java +++ b/li.strolch.service/src/main/java/li/strolch/execution/command/PlanActionCommand.java @@ -72,8 +72,13 @@ public class PlanActionCommand extends PlanningCommand { @Override public Void visitAction(Action action) { + PlanningPolicy planningPolicy = tx().getPolicy(action.findPolicy(PlanningPolicy.class, NO_PLANNING)); planningPolicy.plan(action); + + if (action.getState() == State.PLANNED) + getConfirmationPolicy(action).toPlanned(action); + return null; } } diff --git a/li.strolch.service/src/main/java/li/strolch/execution/command/PlanningCommand.java b/li.strolch.service/src/main/java/li/strolch/execution/command/PlanningCommand.java index b658acca4..95cc9c4f7 100644 --- a/li.strolch.service/src/main/java/li/strolch/execution/command/PlanningCommand.java +++ b/li.strolch.service/src/main/java/li/strolch/execution/command/PlanningCommand.java @@ -15,14 +15,23 @@ */ package li.strolch.execution.command; +import static li.strolch.utils.helper.StringHelper.DASH; +import static li.strolch.utils.helper.StringHelper.isEmpty; + import java.util.Iterator; import java.util.Map.Entry; +import li.strolch.exception.StrolchException; +import li.strolch.execution.policy.ConfirmationPolicy; +import li.strolch.model.Resource; import li.strolch.model.State; +import li.strolch.model.activity.Action; import li.strolch.model.activity.Activity; import li.strolch.model.activity.IActivityElement; +import li.strolch.model.policy.PolicyDef; import li.strolch.model.visitor.IActivityElementVisitor; import li.strolch.persistence.api.StrolchTransaction; +import li.strolch.policy.PolicyHandler; import li.strolch.service.api.Command; /** @@ -52,4 +61,22 @@ public abstract class PlanningCommand extends Command implements IActivityElemen } return null; } + + protected Resource getResource(Action action) { + String resourceId = action.getResourceId(); + if (isEmpty(resourceId) || resourceId.equals(DASH)) + throw new StrolchException("No resourceId defined on action " + action.getLocator()); + String resourceType = action.getResourceType(); + if (isEmpty(resourceType) || resourceType.equals(DASH)) + throw new StrolchException("No resourceType defined on action " + action.getLocator()); + + return tx().getResourceBy(resourceType, resourceId, true); + } + + + protected ConfirmationPolicy getConfirmationPolicy(Action action) { + Resource resource = getResource(action); + PolicyDef executionPolicyDef = resource.getPolicyDefs().getPolicyDef(ConfirmationPolicy.class.getSimpleName()); + return getComponent(PolicyHandler.class).getPolicy(executionPolicyDef, tx()); + } } diff --git a/li.strolch.service/src/main/java/li/strolch/execution/command/SetActionToClosedCommand.java b/li.strolch.service/src/main/java/li/strolch/execution/command/SetActionToClosedCommand.java index 6b8d13a2f..97163a71d 100644 --- a/li.strolch.service/src/main/java/li/strolch/execution/command/SetActionToClosedCommand.java +++ b/li.strolch.service/src/main/java/li/strolch/execution/command/SetActionToClosedCommand.java @@ -2,7 +2,6 @@ package li.strolch.execution.command; import java.text.MessageFormat; -import li.strolch.agent.api.ComponentContainer; import li.strolch.exception.StrolchException; import li.strolch.model.State; import li.strolch.model.activity.Action; @@ -14,8 +13,8 @@ public class SetActionToClosedCommand extends ExecutionCommand { private Action action; - public SetActionToClosedCommand(ComponentContainer container, StrolchTransaction tx) { - super(container, tx); + public SetActionToClosedCommand(StrolchTransaction tx) { + super(tx); } public void setAction(Action action) { @@ -55,9 +54,4 @@ public class SetActionToClosedCommand extends ExecutionCommand { updateOrderState(tx(), rootElement, currentState, rootElement.getState()); } - - @Override - public void undo() { - // can not undo - } } diff --git a/li.strolch.service/src/main/java/li/strolch/execution/command/SetActionToCreatedCommand.java b/li.strolch.service/src/main/java/li/strolch/execution/command/SetActionToCreatedCommand.java index 9337dac9a..efdaa4107 100644 --- a/li.strolch.service/src/main/java/li/strolch/execution/command/SetActionToCreatedCommand.java +++ b/li.strolch.service/src/main/java/li/strolch/execution/command/SetActionToCreatedCommand.java @@ -2,7 +2,6 @@ package li.strolch.execution.command; import java.text.MessageFormat; -import li.strolch.agent.api.ComponentContainer; import li.strolch.exception.StrolchException; import li.strolch.model.State; import li.strolch.model.activity.Action; @@ -14,8 +13,8 @@ public class SetActionToCreatedCommand extends ExecutionCommand { private Action action; - public SetActionToCreatedCommand(ComponentContainer container, StrolchTransaction tx) { - super(container, tx); + public SetActionToCreatedCommand(StrolchTransaction tx) { + super(tx); } public void setAction(Action action) { @@ -55,9 +54,4 @@ public class SetActionToCreatedCommand extends ExecutionCommand { updateOrderState(tx(), rootElement, currentState, rootElement.getState()); } - - @Override - public void undo() { - // can not undo - } } diff --git a/li.strolch.service/src/main/java/li/strolch/execution/command/SetActionToErrorCommand.java b/li.strolch.service/src/main/java/li/strolch/execution/command/SetActionToErrorCommand.java index d5841da74..03719b85e 100644 --- a/li.strolch.service/src/main/java/li/strolch/execution/command/SetActionToErrorCommand.java +++ b/li.strolch.service/src/main/java/li/strolch/execution/command/SetActionToErrorCommand.java @@ -2,7 +2,6 @@ package li.strolch.execution.command; import java.text.MessageFormat; -import li.strolch.agent.api.ComponentContainer; import li.strolch.exception.StrolchException; import li.strolch.model.State; import li.strolch.model.activity.Action; @@ -14,8 +13,8 @@ public class SetActionToErrorCommand extends ExecutionCommand { private Action action; - public SetActionToErrorCommand(ComponentContainer container, StrolchTransaction tx) { - super(container, tx); + public SetActionToErrorCommand(StrolchTransaction tx) { + super(tx); } public void setAction(Action action) { @@ -54,9 +53,4 @@ public class SetActionToErrorCommand extends ExecutionCommand { updateOrderState(tx(), rootElement, currentState, rootElement.getState()); } - - @Override - public void undo() { - // can not undo - } } diff --git a/li.strolch.service/src/main/java/li/strolch/execution/command/SetActionToExecutedCommand.java b/li.strolch.service/src/main/java/li/strolch/execution/command/SetActionToExecutedCommand.java index 5c84facfc..ad1385614 100644 --- a/li.strolch.service/src/main/java/li/strolch/execution/command/SetActionToExecutedCommand.java +++ b/li.strolch.service/src/main/java/li/strolch/execution/command/SetActionToExecutedCommand.java @@ -2,7 +2,6 @@ package li.strolch.execution.command; import java.text.MessageFormat; -import li.strolch.agent.api.ComponentContainer; import li.strolch.exception.StrolchException; import li.strolch.model.State; import li.strolch.model.activity.Action; @@ -14,8 +13,8 @@ public class SetActionToExecutedCommand extends ExecutionCommand { private Action action; - public SetActionToExecutedCommand(ComponentContainer container, StrolchTransaction tx) { - super(container, tx); + public SetActionToExecutedCommand(StrolchTransaction tx) { + super(tx); } public void setAction(Action action) { @@ -54,9 +53,4 @@ public class SetActionToExecutedCommand extends ExecutionCommand { updateOrderState(tx(), rootElement, currentState, rootElement.getState()); } - - @Override - public void undo() { - // can not undo - } } diff --git a/li.strolch.service/src/main/java/li/strolch/execution/command/SetActionToPlannedCommand.java b/li.strolch.service/src/main/java/li/strolch/execution/command/SetActionToPlannedCommand.java index 6f17c28a9..3c91fb27e 100644 --- a/li.strolch.service/src/main/java/li/strolch/execution/command/SetActionToPlannedCommand.java +++ b/li.strolch.service/src/main/java/li/strolch/execution/command/SetActionToPlannedCommand.java @@ -2,7 +2,6 @@ package li.strolch.execution.command; import java.text.MessageFormat; -import li.strolch.agent.api.ComponentContainer; import li.strolch.exception.StrolchException; import li.strolch.model.State; import li.strolch.model.activity.Action; @@ -14,8 +13,8 @@ public class SetActionToPlannedCommand extends ExecutionCommand { private Action action; - public SetActionToPlannedCommand(ComponentContainer container, StrolchTransaction tx) { - super(container, tx); + public SetActionToPlannedCommand(StrolchTransaction tx) { + super(tx); } public void setAction(Action action) { @@ -55,9 +54,4 @@ public class SetActionToPlannedCommand extends ExecutionCommand { updateOrderState(tx(), rootElement, currentState, rootElement.getState()); } - - @Override - public void undo() { - // can not undo - } } diff --git a/li.strolch.service/src/main/java/li/strolch/execution/command/SetActionToPlanningCommand.java b/li.strolch.service/src/main/java/li/strolch/execution/command/SetActionToPlanningCommand.java index 22b02c509..1efbd211d 100644 --- a/li.strolch.service/src/main/java/li/strolch/execution/command/SetActionToPlanningCommand.java +++ b/li.strolch.service/src/main/java/li/strolch/execution/command/SetActionToPlanningCommand.java @@ -2,7 +2,6 @@ package li.strolch.execution.command; import java.text.MessageFormat; -import li.strolch.agent.api.ComponentContainer; import li.strolch.exception.StrolchException; import li.strolch.model.State; import li.strolch.model.activity.Action; @@ -14,8 +13,8 @@ public class SetActionToPlanningCommand extends ExecutionCommand { private Action action; - public SetActionToPlanningCommand(ComponentContainer container, StrolchTransaction tx) { - super(container, tx); + public SetActionToPlanningCommand(StrolchTransaction tx) { + super(tx); } public void setAction(Action action) { @@ -55,9 +54,4 @@ public class SetActionToPlanningCommand extends ExecutionCommand { updateOrderState(tx(), rootElement, currentState, rootElement.getState()); } - - @Override - public void undo() { - // can not undo - } } diff --git a/li.strolch.service/src/main/java/li/strolch/execution/command/SetActionToStoppedCommand.java b/li.strolch.service/src/main/java/li/strolch/execution/command/SetActionToStoppedCommand.java index 726023796..ccf897e36 100644 --- a/li.strolch.service/src/main/java/li/strolch/execution/command/SetActionToStoppedCommand.java +++ b/li.strolch.service/src/main/java/li/strolch/execution/command/SetActionToStoppedCommand.java @@ -2,7 +2,6 @@ package li.strolch.execution.command; import java.text.MessageFormat; -import li.strolch.agent.api.ComponentContainer; import li.strolch.exception.StrolchException; import li.strolch.model.State; import li.strolch.model.activity.Action; @@ -14,8 +13,8 @@ public class SetActionToStoppedCommand extends ExecutionCommand { private Action action; - public SetActionToStoppedCommand(ComponentContainer container, StrolchTransaction tx) { - super(container, tx); + public SetActionToStoppedCommand(StrolchTransaction tx) { + super(tx); } public void setAction(Action action) { @@ -54,9 +53,4 @@ public class SetActionToStoppedCommand extends ExecutionCommand { updateOrderState(tx(), rootElement, currentState, rootElement.getState()); } - - @Override - public void undo() { - // can not undo - } } diff --git a/li.strolch.service/src/main/java/li/strolch/execution/command/SetActionToWarningCommand.java b/li.strolch.service/src/main/java/li/strolch/execution/command/SetActionToWarningCommand.java index 74ba55d67..98fbc628c 100644 --- a/li.strolch.service/src/main/java/li/strolch/execution/command/SetActionToWarningCommand.java +++ b/li.strolch.service/src/main/java/li/strolch/execution/command/SetActionToWarningCommand.java @@ -2,7 +2,6 @@ package li.strolch.execution.command; import java.text.MessageFormat; -import li.strolch.agent.api.ComponentContainer; import li.strolch.exception.StrolchException; import li.strolch.model.State; import li.strolch.model.activity.Action; @@ -14,8 +13,8 @@ public class SetActionToWarningCommand extends ExecutionCommand { private Action action; - public SetActionToWarningCommand(ComponentContainer container, StrolchTransaction tx) { - super(container, tx); + public SetActionToWarningCommand(StrolchTransaction tx) { + super(tx); } public void setAction(Action action) { @@ -54,9 +53,4 @@ public class SetActionToWarningCommand extends ExecutionCommand { updateOrderState(tx(), rootElement, currentState, rootElement.getState()); } - - @Override - public void undo() { - // can not undo - } } diff --git a/li.strolch.service/src/main/java/li/strolch/execution/service/SetActionStateService.java b/li.strolch.service/src/main/java/li/strolch/execution/service/SetActionStateService.java index f46a5fa03..63d82a6a5 100644 --- a/li.strolch.service/src/main/java/li/strolch/execution/service/SetActionStateService.java +++ b/li.strolch.service/src/main/java/li/strolch/execution/service/SetActionStateService.java @@ -42,7 +42,7 @@ public class SetActionStateService extends AbstractServiceOverview

  • API
  • Documentation
  • +
  • PLC
  • Tutorial
  • Downloads
  • Development
  • diff --git a/li.strolch.website/www.strolch.li/blog.html b/li.strolch.website/www.strolch.li/blog.html index e3e81ceb6..71567debe 100644 --- a/li.strolch.website/www.strolch.li/blog.html +++ b/li.strolch.website/www.strolch.li/blog.html @@ -33,6 +33,7 @@
  • Overview
  • API
  • Documentation
  • +
  • PLC
  • Tutorial
  • Downloads
  • Development
  • diff --git a/li.strolch.website/www.strolch.li/development.html b/li.strolch.website/www.strolch.li/development.html index 67acc3c38..130823289 100644 --- a/li.strolch.website/www.strolch.li/development.html +++ b/li.strolch.website/www.strolch.li/development.html @@ -32,6 +32,7 @@
  • Overview
  • API
  • Documentation
  • +
  • PLC
  • Tutorial
  • Downloads
  • Development
  • diff --git a/li.strolch.website/www.strolch.li/documentation-architecture.html b/li.strolch.website/www.strolch.li/documentation-architecture.html index a5418a734..bcd4ff32d 100644 --- a/li.strolch.website/www.strolch.li/documentation-architecture.html +++ b/li.strolch.website/www.strolch.li/documentation-architecture.html @@ -32,6 +32,7 @@
  • Overview
  • API
  • Documentation
  • +
  • PLC
  • Tutorial
  • Downloads
  • Development
  • diff --git a/li.strolch.website/www.strolch.li/documentation-components.html b/li.strolch.website/www.strolch.li/documentation-components.html index 70412dbf2..2281ec1cb 100644 --- a/li.strolch.website/www.strolch.li/documentation-components.html +++ b/li.strolch.website/www.strolch.li/documentation-components.html @@ -32,6 +32,7 @@
  • Overview
  • API
  • Documentation
  • +
  • PLC
  • Tutorial
  • Downloads
  • Development
  • diff --git a/li.strolch.website/www.strolch.li/documentation-do-and-dont.html b/li.strolch.website/www.strolch.li/documentation-do-and-dont.html index 88f5641dc..2d54e1744 100644 --- a/li.strolch.website/www.strolch.li/documentation-do-and-dont.html +++ b/li.strolch.website/www.strolch.li/documentation-do-and-dont.html @@ -32,6 +32,7 @@
  • Overview
  • API
  • Documentation
  • +
  • PLC
  • Tutorial
  • Downloads
  • Development
  • diff --git a/li.strolch.website/www.strolch.li/documentation-model.html b/li.strolch.website/www.strolch.li/documentation-model.html index 8c7469d41..db4c9b881 100644 --- a/li.strolch.website/www.strolch.li/documentation-model.html +++ b/li.strolch.website/www.strolch.li/documentation-model.html @@ -32,6 +32,7 @@
  • Overview
  • API
  • Documentation
  • +
  • PLC
  • Tutorial
  • Downloads
  • Development
  • diff --git a/li.strolch.website/www.strolch.li/documentation-observers.html b/li.strolch.website/www.strolch.li/documentation-observers.html index c86bdd742..21d4d95bd 100644 --- a/li.strolch.website/www.strolch.li/documentation-observers.html +++ b/li.strolch.website/www.strolch.li/documentation-observers.html @@ -32,6 +32,7 @@
  • Overview
  • API
  • Documentation
  • +
  • PLC
  • Tutorial
  • Downloads
  • Development
  • diff --git a/li.strolch.website/www.strolch.li/documentation-policies.html b/li.strolch.website/www.strolch.li/documentation-policies.html index 0e56388b5..d17f43389 100644 --- a/li.strolch.website/www.strolch.li/documentation-policies.html +++ b/li.strolch.website/www.strolch.li/documentation-policies.html @@ -32,6 +32,7 @@
  • Overview
  • API
  • Documentation
  • +
  • PLC
  • Tutorial
  • Downloads
  • Development
  • diff --git a/li.strolch.website/www.strolch.li/documentation-privileges.html b/li.strolch.website/www.strolch.li/documentation-privileges.html index 15b255204..514e50b0d 100644 --- a/li.strolch.website/www.strolch.li/documentation-privileges.html +++ b/li.strolch.website/www.strolch.li/documentation-privileges.html @@ -32,6 +32,7 @@
  • Overview
  • API
  • Documentation
  • +
  • PLC
  • Tutorial
  • Downloads
  • Development
  • diff --git a/li.strolch.website/www.strolch.li/documentation-queries.html b/li.strolch.website/www.strolch.li/documentation-queries.html index ac160274d..7f5b5b3fb 100644 --- a/li.strolch.website/www.strolch.li/documentation-queries.html +++ b/li.strolch.website/www.strolch.li/documentation-queries.html @@ -32,6 +32,7 @@
  • Overview
  • API
  • Documentation
  • +
  • PLC
  • Tutorial
  • Downloads
  • Development
  • diff --git a/li.strolch.website/www.strolch.li/documentation-realms.html b/li.strolch.website/www.strolch.li/documentation-realms.html index 829127491..94264e9d8 100644 --- a/li.strolch.website/www.strolch.li/documentation-realms.html +++ b/li.strolch.website/www.strolch.li/documentation-realms.html @@ -32,6 +32,7 @@
  • Overview
  • API
  • Documentation
  • +
  • PLC
  • Tutorial
  • Downloads
  • Development
  • diff --git a/li.strolch.website/www.strolch.li/documentation-reports.html b/li.strolch.website/www.strolch.li/documentation-reports.html index d57ca556d..a6ac5606a 100644 --- a/li.strolch.website/www.strolch.li/documentation-reports.html +++ b/li.strolch.website/www.strolch.li/documentation-reports.html @@ -32,6 +32,7 @@
  • Overview
  • API
  • Documentation
  • +
  • PLC
  • Tutorial
  • Downloads
  • Development
  • diff --git a/li.strolch.website/www.strolch.li/documentation-runtime.html b/li.strolch.website/www.strolch.li/documentation-runtime.html index 23a5df6ea..6cd59334a 100644 --- a/li.strolch.website/www.strolch.li/documentation-runtime.html +++ b/li.strolch.website/www.strolch.li/documentation-runtime.html @@ -32,6 +32,7 @@
  • Overview
  • API
  • Documentation
  • +
  • PLC
  • Tutorial
  • Downloads
  • Development
  • diff --git a/li.strolch.website/www.strolch.li/documentation-searches.html b/li.strolch.website/www.strolch.li/documentation-searches.html index d2cdae18d..c0f81b3da 100644 --- a/li.strolch.website/www.strolch.li/documentation-searches.html +++ b/li.strolch.website/www.strolch.li/documentation-searches.html @@ -32,6 +32,7 @@
  • Overview
  • API
  • Documentation
  • +
  • PLC
  • Tutorial
  • Downloads
  • Development
  • diff --git a/li.strolch.website/www.strolch.li/documentation-services-and-commands.html b/li.strolch.website/www.strolch.li/documentation-services-and-commands.html index b4b29ccc2..1a2fc9927 100644 --- a/li.strolch.website/www.strolch.li/documentation-services-and-commands.html +++ b/li.strolch.website/www.strolch.li/documentation-services-and-commands.html @@ -32,6 +32,7 @@
  • Overview
  • API
  • Documentation
  • +
  • PLC
  • Tutorial
  • Downloads
  • Development
  • diff --git a/li.strolch.website/www.strolch.li/documentation-transactions.html b/li.strolch.website/www.strolch.li/documentation-transactions.html index ae6428dd3..0839f305a 100644 --- a/li.strolch.website/www.strolch.li/documentation-transactions.html +++ b/li.strolch.website/www.strolch.li/documentation-transactions.html @@ -32,6 +32,7 @@
  • Overview
  • API
  • Documentation
  • +
  • PLC
  • Tutorial
  • Downloads
  • Development
  • diff --git a/li.strolch.website/www.strolch.li/documentation-versioning.html b/li.strolch.website/www.strolch.li/documentation-versioning.html index fc35246c8..01d33f344 100644 --- a/li.strolch.website/www.strolch.li/documentation-versioning.html +++ b/li.strolch.website/www.strolch.li/documentation-versioning.html @@ -32,6 +32,7 @@
  • Overview
  • API
  • Documentation
  • +
  • PLC
  • Tutorial
  • Downloads
  • Development
  • diff --git a/li.strolch.website/www.strolch.li/documentation.html b/li.strolch.website/www.strolch.li/documentation.html index 1a0ab897a..cbdc7ea93 100644 --- a/li.strolch.website/www.strolch.li/documentation.html +++ b/li.strolch.website/www.strolch.li/documentation.html @@ -32,6 +32,7 @@
  • Overview
  • API
  • Documentation
  • +
  • PLC
  • Tutorial
  • Downloads
  • Development
  • diff --git a/li.strolch.website/www.strolch.li/downloads.html b/li.strolch.website/www.strolch.li/downloads.html index 0fff25e7d..95d0916a1 100644 --- a/li.strolch.website/www.strolch.li/downloads.html +++ b/li.strolch.website/www.strolch.li/downloads.html @@ -33,6 +33,7 @@
  • Overview
  • API
  • Documentation
  • +
  • PLC
  • Tutorial
  • Downloads
  • Development
  • diff --git a/li.strolch.website/www.strolch.li/history.html b/li.strolch.website/www.strolch.li/history.html index e6278d2fe..25c134b5d 100644 --- a/li.strolch.website/www.strolch.li/history.html +++ b/li.strolch.website/www.strolch.li/history.html @@ -32,6 +32,7 @@
  • Overview
  • API
  • Documentation
  • +
  • PLC
  • Tutorial
  • Downloads
  • Development
  • diff --git a/li.strolch.website/www.strolch.li/index.html b/li.strolch.website/www.strolch.li/index.html index c4154930e..b27326690 100644 --- a/li.strolch.website/www.strolch.li/index.html +++ b/li.strolch.website/www.strolch.li/index.html @@ -32,6 +32,7 @@
  • Overview
  • API
  • Documentation
  • +
  • PLC
  • Tutorial
  • Downloads
  • Development
  • diff --git a/li.strolch.website/www.strolch.li/plc.html b/li.strolch.website/www.strolch.li/plc.html new file mode 100644 index 000000000..b99cfa2e6 --- /dev/null +++ b/li.strolch.website/www.strolch.li/plc.html @@ -0,0 +1,109 @@ + + + + + + + + + + + + Strolch: PLC + + + + + + + + + + + + +
    + + + +
    + + + +

    Overview

    + +

    Using Strolch as a PLC has certain advantages and disadvantages. The following is a list of advantages:

    +
      +
    • Same programming model and language for server and PLC
    • +
    • PLC has the same privilege handling as in Strolch
    • +
    • Simulating down to the PLC level is easily possible to quickly test the server logic
    • +
    + + + + +
    + + + + +
    + + + + + + + + + + + + + + diff --git a/li.strolch.website/www.strolch.li/tutorial-configuration.html b/li.strolch.website/www.strolch.li/tutorial-configuration.html index bd1bb7da0..583de548c 100644 --- a/li.strolch.website/www.strolch.li/tutorial-configuration.html +++ b/li.strolch.website/www.strolch.li/tutorial-configuration.html @@ -32,6 +32,7 @@
  • Overview
  • API
  • Documentation
  • +
  • PLC
  • Tutorial
  • Downloads
  • Development
  • diff --git a/li.strolch.website/www.strolch.li/tutorial-crud-book.html b/li.strolch.website/www.strolch.li/tutorial-crud-book.html index 63b9f58cf..ad2ca837f 100644 --- a/li.strolch.website/www.strolch.li/tutorial-crud-book.html +++ b/li.strolch.website/www.strolch.li/tutorial-crud-book.html @@ -32,6 +32,7 @@
  • Overview
  • API
  • Documentation
  • +
  • PLC
  • Tutorial
  • Downloads
  • Development
  • diff --git a/li.strolch.website/www.strolch.li/tutorial-model.html b/li.strolch.website/www.strolch.li/tutorial-model.html index b00074929..db63661c4 100644 --- a/li.strolch.website/www.strolch.li/tutorial-model.html +++ b/li.strolch.website/www.strolch.li/tutorial-model.html @@ -32,6 +32,7 @@
  • Overview
  • API
  • Documentation
  • +
  • PLC
  • Tutorial
  • Downloads
  • Development
  • diff --git a/li.strolch.website/www.strolch.li/tutorial.html b/li.strolch.website/www.strolch.li/tutorial.html index 03703b94f..62e2cf184 100644 --- a/li.strolch.website/www.strolch.li/tutorial.html +++ b/li.strolch.website/www.strolch.li/tutorial.html @@ -32,6 +32,7 @@
  • Overview
  • API
  • Documentation
  • +
  • PLC
  • Tutorial
  • Downloads
  • Development