[Fix] Multiple bug fixes for execution
This commit is contained in:
parent
c6f627be87
commit
c90f698e87
|
@ -1,8 +1,8 @@
|
|||
package li.strolch.execution;
|
||||
|
||||
import static java.util.Collections.synchronizedMap;
|
||||
import static li.strolch.runtime.StrolchConstants.SYSTEM_USER_AGENT;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.ResourceBundle;
|
||||
|
@ -52,7 +52,7 @@ public class Controller {
|
|||
this.activityType = activity.getType();
|
||||
this.activityId = activity.getId();
|
||||
this.activity = activity;
|
||||
this.inExecution = Collections.synchronizedMap(new HashMap<>());
|
||||
this.inExecution = synchronizedMap(new HashMap<>());
|
||||
}
|
||||
|
||||
public String getRealm() {
|
||||
|
@ -83,6 +83,10 @@ public class Controller {
|
|||
return executionPolicy;
|
||||
}
|
||||
|
||||
public void removeExecutionPolicy(Action action) {
|
||||
this.inExecution.remove(action.getLocator());
|
||||
}
|
||||
|
||||
protected StrolchTransaction openTx(Certificate cert) {
|
||||
return this.executionHandler.openTx(this.realm, cert, getClass(), false);
|
||||
}
|
||||
|
@ -145,7 +149,7 @@ public class Controller {
|
|||
command.validate();
|
||||
command.doCommand();
|
||||
|
||||
notifyObserverUpdate();
|
||||
updateObservers();
|
||||
|
||||
return command.needsRetriggerOfExecution();
|
||||
}
|
||||
|
@ -173,7 +177,7 @@ public class Controller {
|
|||
command.validate();
|
||||
command.doCommand();
|
||||
|
||||
notifyObserverUpdate();
|
||||
updateObservers();
|
||||
|
||||
// flush so we can see the changes performed
|
||||
tx.flush();
|
||||
|
@ -215,6 +219,8 @@ public class Controller {
|
|||
tx.commitOnClose();
|
||||
}
|
||||
});
|
||||
|
||||
updateObservers();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -243,6 +249,8 @@ public class Controller {
|
|||
tx.commitOnClose();
|
||||
}
|
||||
});
|
||||
|
||||
updateObservers();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -271,6 +279,8 @@ public class Controller {
|
|||
tx.commitOnClose();
|
||||
}
|
||||
});
|
||||
|
||||
updateObservers();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -319,7 +329,7 @@ public class Controller {
|
|||
});
|
||||
}
|
||||
|
||||
private void notifyObserverUpdate() {
|
||||
private void updateObservers() {
|
||||
StrolchRealm realm = this.executionHandler.getContainer().getRealm(this.realm);
|
||||
if (!realm.isUpdateObservers())
|
||||
return;
|
||||
|
|
|
@ -72,6 +72,10 @@ public class ExecuteActivityCommand extends BasePlanningAndExecutionCommand
|
|||
|
||||
ConfirmationPolicy confirmationPolicy = getConfirmationPolicy(action);
|
||||
ExecutionPolicy executionPolicy = getExecutionPolicy(action);
|
||||
if (executionPolicy.isStopped()) {
|
||||
this.controller.removeExecutionPolicy(action);
|
||||
executionPolicy = getExecutionPolicy(action);
|
||||
}
|
||||
|
||||
if (!executionPolicy.isExecutable(action)) {
|
||||
logger.info("Action " + action.getLocator() + " is not yet executable.");
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
package li.strolch.execution.policy;
|
||||
|
||||
import li.strolch.model.Locator;
|
||||
import static li.strolch.runtime.StrolchConstants.PolicyConstants.BAG_OBJECTIVES;
|
||||
import static li.strolch.runtime.StrolchConstants.PolicyConstants.PARAM_DURATION;
|
||||
|
||||
import li.strolch.model.activity.Action;
|
||||
import li.strolch.model.parameter.DurationParameter;
|
||||
import li.strolch.persistence.api.StrolchTransaction;
|
||||
import li.strolch.runtime.StrolchConstants.PolicyConstants;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
@ -16,8 +17,6 @@ import li.strolch.runtime.StrolchConstants.PolicyConstants;
|
|||
*/
|
||||
public class DurationExecution extends SimpleExecution {
|
||||
|
||||
protected Locator actionLoc;
|
||||
|
||||
public DurationExecution(StrolchTransaction tx) {
|
||||
super(tx);
|
||||
}
|
||||
|
@ -25,19 +24,9 @@ public class DurationExecution extends SimpleExecution {
|
|||
@Override
|
||||
public void toExecution(Action action) {
|
||||
|
||||
DurationParameter durationP = action
|
||||
.findParameter(PolicyConstants.BAG_OBJECTIVES, PolicyConstants.PARAM_DURATION, true);
|
||||
|
||||
String realmName = tx().getRealmName();
|
||||
this.actionLoc = action.getLocator();
|
||||
logger.info("Executing action " + actionLoc + " has a duration of " + durationP.getValueAsString());
|
||||
getDelayedExecutionTimer().execute(realmName, getContainer(), this.actionLoc, durationP.toMillis());
|
||||
DurationParameter durationP = action.findParameter(BAG_OBJECTIVES, PARAM_DURATION, true);
|
||||
delayToExecutedBy(durationP.getDuration());
|
||||
|
||||
super.toExecution(action);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleStopped() {
|
||||
getDelayedExecutionTimer().cancel(this.actionLoc);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -83,9 +83,4 @@ public class SimpleExecution extends ExecutionPolicy {
|
|||
addMessage(message);
|
||||
getController().asyncToWarning(message.getLocator());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleStopped() {
|
||||
getDelayedExecutionTimer().cancel(this.actionLoc);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,22 +25,22 @@ public class SetActionToErrorService extends AbstractService<LocatorArgument, Se
|
|||
@Override
|
||||
protected ServiceResult internalDoService(LocatorArgument arg) throws Exception {
|
||||
|
||||
ExecutionHandler executionHandler = getComponent(ExecutionHandler.class);
|
||||
Controller controller = executionHandler.getController(getArgOrUserRealm(arg), arg.locator.trim(3));
|
||||
if (controller != null) {
|
||||
controller.toError(arg.locator);
|
||||
return ServiceResult.success();
|
||||
}
|
||||
|
||||
try (StrolchTransaction tx = openArgOrUserTx(arg)) {
|
||||
|
||||
tx.lock(arg.locator.trim(3));
|
||||
Action action = tx.findElement(arg.locator);
|
||||
tx.lock(action.getResourceLocator());
|
||||
|
||||
ExecutionHandler executionHandler = getComponent(ExecutionHandler.class);
|
||||
Controller controller = executionHandler.getController(tx.getRealmName(), action.getRootElement());
|
||||
if (controller != null) {
|
||||
controller.toError(action.getLocator());
|
||||
} else {
|
||||
|
||||
SetActionToErrorCommand command = new SetActionToErrorCommand(tx);
|
||||
command.setAction(action);
|
||||
tx.addCommand(command);
|
||||
}
|
||||
SetActionToErrorCommand command = new SetActionToErrorCommand(tx);
|
||||
command.setAction(action);
|
||||
tx.addCommand(command);
|
||||
|
||||
tx.commitOnClose();
|
||||
}
|
||||
|
|
|
@ -25,21 +25,22 @@ public class SetActionToExecutedService extends AbstractService<LocatorArgument,
|
|||
@Override
|
||||
protected ServiceResult internalDoService(LocatorArgument arg) throws Exception {
|
||||
|
||||
ExecutionHandler executionHandler = getComponent(ExecutionHandler.class);
|
||||
Controller controller = executionHandler.getController(getArgOrUserRealm(arg), arg.locator.trim(3));
|
||||
if (controller != null) {
|
||||
controller.toExecuted(arg.locator);
|
||||
return ServiceResult.success();
|
||||
}
|
||||
|
||||
try (StrolchTransaction tx = openArgOrUserTx(arg)) {
|
||||
|
||||
tx.lock(arg.locator.trim(3));
|
||||
Action action = tx.findElement(arg.locator);
|
||||
tx.lock(action.getResourceLocator());
|
||||
|
||||
ExecutionHandler executionHandler = getComponent(ExecutionHandler.class);
|
||||
Controller controller = executionHandler.getController(tx.getRealmName(), action.getRootElement());
|
||||
if (controller != null) {
|
||||
controller.toExecuted(action.getLocator());
|
||||
} else {
|
||||
SetActionToExecutedCommand command = new SetActionToExecutedCommand(tx);
|
||||
command.setAction(action);
|
||||
tx.addCommand(command);
|
||||
}
|
||||
SetActionToExecutedCommand command = new SetActionToExecutedCommand(tx);
|
||||
command.setAction(action);
|
||||
tx.addCommand(command);
|
||||
|
||||
tx.commitOnClose();
|
||||
}
|
||||
|
|
|
@ -25,21 +25,22 @@ public class SetActionToStoppedService extends AbstractService<LocatorArgument,
|
|||
@Override
|
||||
protected ServiceResult internalDoService(LocatorArgument arg) throws Exception {
|
||||
|
||||
ExecutionHandler executionHandler = getComponent(ExecutionHandler.class);
|
||||
Controller controller = executionHandler.getController(getArgOrUserRealm(arg), arg.locator.trim(3));
|
||||
if (controller != null) {
|
||||
controller.toStopped(arg.locator);
|
||||
return ServiceResult.success();
|
||||
}
|
||||
|
||||
try (StrolchTransaction tx = openArgOrUserTx(arg)) {
|
||||
|
||||
tx.lock(arg.locator.trim(3));
|
||||
Action action = tx.findElement(arg.locator);
|
||||
tx.lock(action.getResourceLocator());
|
||||
|
||||
ExecutionHandler executionHandler = getComponent(ExecutionHandler.class);
|
||||
Controller controller = executionHandler.getController(tx.getRealmName(), action.getRootElement());
|
||||
if (controller != null) {
|
||||
controller.toStopped(action.getLocator());
|
||||
} else {
|
||||
SetActionToStoppedCommand command = new SetActionToStoppedCommand(tx);
|
||||
command.setAction(action);
|
||||
tx.addCommand(command);
|
||||
}
|
||||
SetActionToStoppedCommand command = new SetActionToStoppedCommand(tx);
|
||||
command.setAction(action);
|
||||
tx.addCommand(command);
|
||||
|
||||
tx.commitOnClose();
|
||||
}
|
||||
|
|
|
@ -25,21 +25,22 @@ public class SetActionToWarningService extends AbstractService<LocatorArgument,
|
|||
@Override
|
||||
protected ServiceResult internalDoService(LocatorArgument arg) throws Exception {
|
||||
|
||||
ExecutionHandler executionHandler = getComponent(ExecutionHandler.class);
|
||||
Controller controller = executionHandler.getController(getArgOrUserRealm(arg), arg.locator.trim(3));
|
||||
if (controller != null) {
|
||||
controller.toWarning(arg.locator);
|
||||
return ServiceResult.success();
|
||||
}
|
||||
|
||||
try (StrolchTransaction tx = openArgOrUserTx(arg)) {
|
||||
|
||||
tx.lock(arg.locator.trim(3));
|
||||
Action action = tx.findElement(arg.locator);
|
||||
tx.lock(action.getResourceLocator());
|
||||
|
||||
ExecutionHandler executionHandler = getComponent(ExecutionHandler.class);
|
||||
Controller controller = executionHandler.getController(tx.getRealmName(), action.getRootElement());
|
||||
if (controller != null) {
|
||||
controller.toWarning(action.getLocator());
|
||||
} else {
|
||||
SetActionToWarningCommand command = new SetActionToWarningCommand(tx);
|
||||
command.setAction(action);
|
||||
tx.addCommand(command);
|
||||
}
|
||||
SetActionToWarningCommand command = new SetActionToWarningCommand(tx);
|
||||
command.setAction(action);
|
||||
tx.addCommand(command);
|
||||
|
||||
tx.commitOnClose();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue