if (this.config.isActOnProvenance()) {
try {
this.getConfig().getConfiguration().getJcrComponentRegistry().getRegistry()
.saveWorkflowExecutionStatus(this.config.getTopic(), ExecutionStatus.STARTED);
} catch (RegistryException e) {
throw new WorkflowException(e);
}
}
ArrayList<Node> inputNodes = this.getInputNodesDynamically();
Object[] values = new Object[inputNodes.size()];
String[] keywords = new String[inputNodes.size()];
for (int i = 0; i < inputNodes.size(); ++i) {
Node node = inputNodes.get(i);
NodeController.getGUI(node).setBodyColor(NodeState.FINISHED.color);
notifyViaInteractor(WorkflowExecutionMessage.NODE_STATE_CHANGED, null);
keywords[i] = ((InputNode) node).getName();
values[i] = ((InputNode) node).getDefaultValue();
}
this.config.getNotifier().workflowStarted(values, keywords);
while (this.getWorkflow().getExecutionState() != WorkflowExecutionState.STOPPED) {
if (getRemainNodesDynamically() == 0) {
notifyViaInteractor(WorkflowExecutionMessage.EXECUTION_STATE_CHANGED, WorkflowExecutionState.PAUSED);
// if (this.config.getMode() ==
// WorkflowInterpreterConfiguration.GUI_MODE) {
// this.notifyPause();
// } else {
// this.getWorkflow().setExecutionState(
// WorkflowExecutionState.STOPPED);
// }
}
// ok we have paused sleep
while (this.getWorkflow().getExecutionState() == WorkflowExecutionState.PAUSED) {
try {
Thread.sleep(400);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
// get task list and execute them
ArrayList<Node> readyNodes = this.getReadyNodesDynamically();
for (Node node : readyNodes) {
if (node.isBreak()) {
this.notifyPause();
break;
}
if (this.getWorkflow().getExecutionState() == WorkflowExecutionState.PAUSED
|| this.getWorkflow().getExecutionState() == WorkflowExecutionState.STOPPED) {
break;
// stop executing and sleep in the outer loop cause we
// want
// recalculate the execution stack
}
boolean nodeOutputLoadedFromProvenance = false;
if (this.config.isActOnProvenance()) {
nodeOutputLoadedFromProvenance = readProvenance(node);
if (!nodeOutputLoadedFromProvenance) {
executeDynamically(node);
}
} else {
executeDynamically(node);
}
if (this.getWorkflow().getExecutionState() == WorkflowExecutionState.STEP) {
this.getWorkflow().setExecutionState(WorkflowExecutionState.PAUSED);
break;
}
}
// TODO commented this for foreach, fix this.
sendOutputsDynamically();
// Dry run sleep a lil bit to release load
if (readyNodes.size() == 0) {
// when there are no ready nodes and no running nodes
// and there are failed nodes then workflow is stuck because
// of failure
// so we should pause the execution
if (InterpreterUtil.getRunningNodeCountDynamically(this.getGraph()) == 0
&& InterpreterUtil.getFailedNodeCountDynamically(this.getGraph()) != 0) {
this.getWorkflow().setExecutionState(WorkflowExecutionState.PAUSED);
}
try {
Thread.sleep(400);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
if (InterpreterUtil.getFailedNodeCountDynamically(this.getGraph()) == 0) {
if (this.config.isActOnProvenance()) {
try {
try {
this.getConfig().getConfiguration().getJcrComponentRegistry().getRegistry()
.saveWorkflowExecutionStatus(this.config.getTopic(), ExecutionStatus.FINISHED);
} catch (Exception e) {
throw new WorkflowException(e);
}
} catch (Exception e) {
throw new WorkflowException(e);
}
// System.out.println(this.config.getConfiguration().getJcrComponentRegistry().getRegistry().getWorkflowStatus(this.topic));
}
} else {
if (this.config.isActOnProvenance()) {
try {
this.getConfig().getConfiguration().getJcrComponentRegistry().getRegistry()
.saveWorkflowExecutionStatus(this.config.getTopic(), ExecutionStatus.FAILED);
} catch (RegistryException e) {
throw new WorkflowException(e);
}
}
}
this.config.getNotifier().workflowTerminated();
// if (this.config.getMode() ==