[Fix] Fix able to restart error actions by setting to STOPPED first
This commit is contained in:
parent
3e2e21da6d
commit
5471a3176b
|
@ -72,7 +72,7 @@ public enum State {
|
||||||
* {@link #EXECUTED}
|
* {@link #EXECUTED}
|
||||||
*/
|
*/
|
||||||
public boolean inExecutionPhase() {
|
public boolean inExecutionPhase() {
|
||||||
return this == EXECUTION || this == STOPPED || this == WARNING || this == ERROR || this == EXECUTED;
|
return this == EXECUTION || this == STOPPED || this == WARNING || this == ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -135,28 +135,28 @@ public enum State {
|
||||||
* @return true if {@link #inExecutionPhase()} but not executed and not already in warning
|
* @return true if {@link #inExecutionPhase()} but not executed and not already in warning
|
||||||
*/
|
*/
|
||||||
public boolean canSetToWarning() {
|
public boolean canSetToWarning() {
|
||||||
return inExecutionPhase() && this != State.EXECUTED;
|
return inExecutionPhase();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return true if {@link #inExecutionPhase()} but not executed and not already stopped
|
* @return true if {@link #inExecutionPhase()} but not executed and not already stopped
|
||||||
*/
|
*/
|
||||||
public boolean canSetToStopped() {
|
public boolean canSetToStopped() {
|
||||||
return inExecutionPhase() && this != State.EXECUTED;
|
return inExecutionPhase();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return true if {@link #inExecutionPhase()} but not executed and not already in error
|
* @return true if {@link #inExecutionPhase()} but not executed and not already in error
|
||||||
*/
|
*/
|
||||||
public boolean canSetToError() {
|
public boolean canSetToError() {
|
||||||
return inExecutionPhase() && this != State.EXECUTED;
|
return inExecutionPhase();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return true if {@link #inExecutionPhase()} but not executed
|
* @return true if {@link #inExecutionPhase()} but not executed
|
||||||
*/
|
*/
|
||||||
public boolean canSetToExecuted() {
|
public boolean canSetToExecuted() {
|
||||||
return inExecutionPhase() && this != State.EXECUTED;
|
return inExecutionPhase();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static State parse(String s) {
|
public static State parse(String s) {
|
||||||
|
@ -203,9 +203,9 @@ public enum State {
|
||||||
}
|
}
|
||||||
|
|
||||||
// then execution
|
// then execution
|
||||||
else if (childState.inExecutionPhase()) {
|
else if (childState.inExecutionPhase() || childState == State.EXECUTED) {
|
||||||
if (!state.inExecutionWarningPhase()) {
|
if (!state.inExecutionWarningPhase()) {
|
||||||
if (state.inExecutionPhase())
|
if (state.inExecutionPhase() || state == State.EXECUTED)
|
||||||
state = State.min(state, childState);
|
state = State.min(state, childState);
|
||||||
else
|
else
|
||||||
state = State.EXECUTION;
|
state = State.EXECUTION;
|
||||||
|
@ -214,7 +214,7 @@ public enum State {
|
||||||
|
|
||||||
// then planning
|
// then planning
|
||||||
else if (childState.inPlanningPhase()) {
|
else if (childState.inPlanningPhase()) {
|
||||||
if (state.inExecutionPhase()) {
|
if (state.inExecutionPhase() || state == State.EXECUTED) {
|
||||||
if (!state.inExecutionWarningPhase())
|
if (!state.inExecutionWarningPhase())
|
||||||
state = State.EXECUTION;
|
state = State.EXECUTION;
|
||||||
} else {
|
} else {
|
||||||
|
@ -227,7 +227,7 @@ public enum State {
|
||||||
|
|
||||||
// then created
|
// then created
|
||||||
else if (childState.inCreatedPhase()) {
|
else if (childState.inCreatedPhase()) {
|
||||||
if (state.inExecutionPhase()) {
|
if (state.inExecutionPhase() || state == State.EXECUTED) {
|
||||||
if (!state.inExecutionWarningPhase())
|
if (!state.inExecutionWarningPhase())
|
||||||
state = State.EXECUTION;
|
state = State.EXECUTION;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -0,0 +1,51 @@
|
||||||
|
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;
|
||||||
|
import li.strolch.model.activity.Activity;
|
||||||
|
import li.strolch.persistence.api.StrolchTransaction;
|
||||||
|
import li.strolch.utils.dbc.DBC;
|
||||||
|
|
||||||
|
public class ExecuteStoppedActionCommand extends ExecutionCommand {
|
||||||
|
|
||||||
|
private Action action;
|
||||||
|
|
||||||
|
public ExecuteStoppedActionCommand(ComponentContainer container, StrolchTransaction tx) {
|
||||||
|
super(container, tx);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAction(Action action) {
|
||||||
|
this.action = action;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void validate() {
|
||||||
|
DBC.PRE.assertNotNull("action can not be null", this.action);
|
||||||
|
|
||||||
|
if (this.action.getState() != State.STOPPED) {
|
||||||
|
String msg = "Action {0} is not in state " + State.STOPPED + " and can thus not be put into execution!";
|
||||||
|
msg = MessageFormat.format(msg, this.action.getState(), State.ERROR, this.action.getLocator());
|
||||||
|
throw new StrolchException(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void doCommand() {
|
||||||
|
Activity rootElement = this.action.getRootElement();
|
||||||
|
tx().lock(rootElement);
|
||||||
|
|
||||||
|
State currentState = rootElement.getState();
|
||||||
|
rootElement.accept(this);
|
||||||
|
|
||||||
|
updateOrderState(rootElement, currentState, rootElement.getState());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void undo() {
|
||||||
|
// can't undo execution
|
||||||
|
}
|
||||||
|
}
|
|
@ -89,13 +89,16 @@ public abstract class ExecutionCommand extends Command implements TimeOrderingVi
|
||||||
// in series we can never have two Actions in execution, so if we found the action in execution, we stop
|
// in series we can never have two Actions in execution, so if we found the action in execution, we stop
|
||||||
if (element instanceof Action //
|
if (element instanceof Action //
|
||||||
&& (state == State.EXECUTION //
|
&& (state == State.EXECUTION //
|
||||||
|| state == State.WARNING)) {
|
|| state == State.WARNING //
|
||||||
|
|| state == State.ERROR)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean canExecute = isExecutable(element);
|
boolean canExecute = isExecutable(element);
|
||||||
if (canExecute) {
|
if (canExecute) {
|
||||||
element.accept(this);
|
element.accept(this);
|
||||||
|
|
||||||
|
// in series we stop when the first action is set to execution
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -113,6 +116,8 @@ public abstract class ExecutionCommand extends Command implements TimeOrderingVi
|
||||||
if (element.getState().isExecuted())
|
if (element.getState().isExecuted())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
// in parallel we execute all the actions in the activity
|
||||||
|
|
||||||
boolean canExecute = isExecutable(element);
|
boolean canExecute = isExecutable(element);
|
||||||
if (canExecute) {
|
if (canExecute) {
|
||||||
element.accept(this);
|
element.accept(this);
|
||||||
|
@ -132,8 +137,12 @@ public abstract class ExecutionCommand extends Command implements TimeOrderingVi
|
||||||
if (state.compareTo(State.EXECUTION) < 0)
|
if (state.compareTo(State.EXECUTION) < 0)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// in stopped or error
|
// in stopped, means we can re-execute
|
||||||
return state == State.STOPPED || state == State.ERROR;
|
if (state == State.STOPPED)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
// if in ERROR, then must first be handled
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue