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