wsNodes.add(subWorkflowNode);
}
}
for (int i = 0; i < wsNodes.size(); i++) {
final WSNode node1 = (WSNode) wsNodes.get(i);
SystemComponentInvoker systemInvoker = null;
List<DataPort> outputPorts1 = node1.getOutputPorts();
List<Node> endForEachNodes = new ArrayList<Node>();
for (DataPort port : outputPorts1) {
Iterator<Node> endForEachNodeItr1 = port.getToNodes().iterator();
while (endForEachNodeItr1.hasNext()) {
Node node2 = endForEachNodeItr1.next();
if (node2 instanceof EndForEachNode) {
endForEachNodes.add(node2);
} else if (node2 instanceof OutputNode) {
// intentionally left noop
} else {
throw new WorkFlowInterpreterException("Found More than one node inside foreach");
}
}
}
final List<Node> finalEndForEachNodes = endForEachNodes;
Iterator<Node> endForEachNodeItr1 = node1.getOutputPort(0).getToNodes().iterator();
while (endForEachNodeItr1.hasNext()) {
Node node2 = endForEachNodeItr1.next();
// Start reading input came for foreach node
int parallelRuns = listOfValues.size() * node1.getOutputPorts().size();
if (listOfValues.size() > 0) {
forEachNode.setState(NodeExecutionState.EXECUTING);
node1.setState(NodeExecutionState.EXECUTING);
List<DataPort> outputPorts = node1.getOutputPorts();
final AtomicInteger counter = new AtomicInteger();
for (Node endFor : endForEachNodes) {
systemInvoker = new SystemComponentInvoker();
this.invokerMap.put(endFor, systemInvoker);
}
final Map<Node, Invoker> finalMap = this.invokerMap;
new Thread() {
@Override
public void run() {
try {
runInThread(listOfValues, forEachNode, node1, finalEndForEachNodes, finalMap, counter, inputNumbers);
} catch (WorkflowException e) {
WorkflowInterpreter.this.config.getGUI().getErrorWindow().error(e);
}
}
}.start();
while (counter.intValue() < parallelRuns) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
if (!(node2 instanceof OutputNode)) {
listOfValues.removeAll(listOfValues);
String output = (String) systemInvoker.getOutput(node1.getOutputPort(0).getName());
XmlElement xmlElement = XMLUtil.stringToXmlElement("<result>" + output + "</result>");
Iterator iterator1 = xmlElement.children().iterator();
while (iterator1.hasNext()) {
Object next1 = iterator1.next();
if (next1 instanceof XmlElement) {