if (spooler_task.params().value(dependentJobChainName+";"+ dependentNodeName + "_required_orders") != null && spooler_task.params().value(dependentJobChainName+";"+ dependentNodeName + "_required_orders").length() > 0) {
requiredOrders = Integer.parseInt(spooler_task.params().value(dependentJobChainName+";"+ dependentNodeName + "_required_orders"));
} else if (spooler_task.params().value(dependentJobChainName + "_required_orders") != null && spooler_task.params().value(dependentJobChainName + "_required_orders").length() > 0) {
String s = spooler_task.params().value(dependentJobChainName + "_required_orders");
if (s.equalsIgnoreCase("job_chain.order_count")){
Job_chain j = spooler.job_chain(dependentJobChainPath);
spooler_log.debug9("Waiting for all orders in job_chain " + dependentJobChainPath + " ...");
if (j != null) {
requiredOrders = j.order_count();
}else {
spooler_log.warn(dependentJobChainPath + "does not exist");
requiredOrders = 1;
}
}else {
requiredOrders = Integer.parseInt(spooler_task.params().value(dependentJobChainName + "_required_orders"));
}
} else if (spooler_task.params().value("required_orders") != null && spooler_task.params().value("required_orders").length() > 0) {
requiredOrders = Integer.parseInt(spooler_task.params().value("required_orders"));
}
// should any of the dependent job chains have less orders enqueued than required, then the current order will be set on hold
if (requiredOrders > dependentJobChainOrders) {
passOrders = false;
}else {
if (minimumSyncHits > 0) satisfiedNode++;
}
spooler_log.info("job chain [" + dependentJobChainPath + "], state ["+dependentNodeName+"]"+syncSessionDebug+" requires " + requiredOrders + " orders being present, " + dependentJobChainOrders + " orders have been enqueued");
// move this information to a hashmap for further use
int[] orders = new int[2];
orders[0] = dependentJobChainOrders;
orders[1] = requiredOrders;
dependentJobChainNodes.put(dependentJobChainPath+";"+dependentNodeName, orders);
}
spooler_log.info("Synchits:" + satisfiedNode);
passOrders = (passOrders || satisfiedNode > 0 && satisfiedNode >= minimumSyncHits);
if (!passOrders) {
// suspend/setback the current order for this job chain: it will be suspended
if (this.setbackType.equalsIgnoreCase("setback") ) {
spooler_task.order().setback();
} else {
if (!spooler_task.order().suspended()) {
spooler_task.order().set_state(spooler_task.order().state()); //Damit der Suspend auf den sync-Knoten geht und nicht auf den n�chsten.
spooler_task.order().set_suspended(true);
}
}
spooler_log.info("order is set on hold: " + spooler_task.order().id() + ", " + spooler_task.order().title());
}
// display an overview of all dependent job chains
Iterator jobChainNodesIterator = dependentJobChainNodes.keySet().iterator();
while (jobChainNodesIterator.hasNext()) {
String keyName = (String)jobChainNodesIterator.next();
dependentJobChainPath = keyName.split(";")[0];
dependentNodeName = keyName.split(";")[1];
if (dependentJobChainPath == null) { continue; }
if (dependentNodeName == null) { continue; }
int[] orders = (int[])dependentJobChainNodes.get(keyName);
if (orders == null) { continue; }
spooler_log.info("synchronized job chain: " + dependentJobChainPath + ", state ["+dependentNodeName+"]"+syncSessionDebug+", required orders: " + orders[1] + ", pending orders: " + orders[0]);
}
} catch (Exception ex) {
throw new Exception("could not check pending orders in dependent job chains: " + ex.getMessage());
}
// signal to other job chains that the next order should be passed through to its next state
if (passOrders) {
Iterator jobChainNodesIterator = dependentJobChainNodes.keySet().iterator();
while (jobChainNodesIterator.hasNext()) {
String keyName = (String)jobChainNodesIterator.next();
dependentJobChainPath = keyName.split(";")[0];
dependentNodeName = keyName.split(";")[1];
if (dependentJobChainPath == null) { continue; }
if (dependentNodeName == null) { continue; }
int[] orders = (int[])dependentJobChainNodes.get(keyName);
if (orders == null) { continue; }
spooler_log.debug6("checking job chain: " + dependentJobChainPath+", state ["+dependentNodeName+"]");
if (this.setbackType.equalsIgnoreCase("setback")) {
String signalVariable = keyName+ "_pass_through_next_order";
// signal current job chain to pass through the required number of orders minus the current one
if (dependentJobChainPath.equals(currentJobChainPath) && dependentNodeName.equals(currentNodeName)) {
if (orders[1]-1 > 0) {
spooler_log.debug6("setting signal variable: " + signalVariable+"=" + Integer.toString(orders[1]-1));
spooler.set_var(signalVariable, Integer.toString(orders[1]-1));
}
} else {
// make other job chain pass through the required number of orders
spooler_log.debug6("setting signal variable: " + signalVariable+"=" + Integer.toString(orders[1]));
spooler.set_var(signalVariable, Integer.toString(orders[1]));
}
spooler_log.info("signalling next " + orders[1] + " orders to be passed through by job chain: " + dependentJobChainPath+", state ["+dependentNodeName+"]");
}
try { // to signal waiting orders to start immediately
NodeList signalNodes = null;
if (this.setbackType.equalsIgnoreCase("setback")) {
signalNodes = currentStatusXPath.selectNodeList("/spooler/answer/state/job_chains/job_chain[@path = '" + dependentJobChainPath + "']/job_chain_node[@state = '" + dependentNodeName + "']/order_queue/order[@setback_count > 0 and @setback != '' "+syncSessionCondition+"]");
spooler_log.debug9("orders being set back: " + signalNodes.getLength() + " /spooler/answer/state/job_chains/job_chain[@path = '" + dependentJobChainPath + "']/job_chain_node[@state = '" + dependentNodeName + "']/order_queue/order[@setback_count > 0 and @setback != ''"+syncSessionCondition+"]");
} else {
signalNodes = currentStatusXPath.selectNodeList("/spooler/answer/state/job_chains/job_chain[@path = '" + dependentJobChainPath + "']/job_chain_node[@state = '" + dependentNodeName + "']/order_queue/order[@suspended = 'yes' "+syncSessionCondition+"]");
spooler_log.debug9("orders being suspended: " + signalNodes.getLength() + " /spooler/answer/state/job_chains/job_chain[@path = '" + dependentJobChainPath + "']/job_chain_node[@state = '" + dependentNodeName + "']/order_queue/order[@suspended = 'yes' "+syncSessionCondition+"]");
}
if (signalNodes == null || signalNodes.getLength() < 1) {
spooler_log.info("no suspended or set back orders found in dependent job chain: " + dependentJobChainPath);
continue;
}
SOSXMLXPath xPath = null;
String answer = "";
int requiredOrders = 1;
if (dependentJobChainPath.lastIndexOf("/") > -1) {
dependentJobChainName = dependentJobChainPath.substring(dependentJobChainPath.lastIndexOf("/")+1);
} else {
dependentJobChainName = dependentJobChainPath;
}
if (spooler_task.params().value(dependentJobChainName + "_required_orders") != null && spooler_task.params().value(dependentJobChainName + "_required_orders").length() > 0) {
requiredOrders = Integer.parseInt(spooler_task.params().value(dependentJobChainName + "_required_orders"));
} else if (spooler_task.params().value("required_orders") != null && spooler_task.params().value("required_orders").length() > 0) {
requiredOrders = Integer.parseInt(spooler_task.params().value("required_orders"));
}
for(int i=0; i<signalNodes.getLength(); i++) {
if (i >= requiredOrders) {
spooler_log.debug9("maximum number of orders for reactivation reached: found " + i + ", required " + requiredOrders);
break;
}
spooler_log.info("signalling order [" + signalNodes.item(i).getAttributes().getNamedItem("id").getNodeValue() + "] to be continued for job chain [" + dependentJobChainPath + "]");
if (signalNodes.item(i).getAttributes().getNamedItem("setback") != null) {
if (!this.setbackType.equalsIgnoreCase("setback")) {
String signalVariable = keyName+ "_pass_through_next_order";
// signal current job chain to pass through the required number of orders minus the current one
if (dependentJobChainPath.equals(currentJobChainPath) && dependentNodeName.equals(currentNodeName)) {
if (orders[1]-1 > 0) {
spooler.set_var(signalVariable, Integer.toString(orders[1]-1));
}
} else {
// make other job chains pass through the required number of orders
spooler.set_var(signalVariable, Integer.toString(orders[1]));
}
spooler_log.info("signalling next " + orders[1] + " orders to be passed through by job chain: " + dependentJobChainPath+", state ["+dependentNodeName+"]");
}
spooler_log.debug9("activate order after setback: <modify_order job_chain='" + dependentJobChainPath + "' order='" + signalNodes.item(i).getAttributes().getNamedItem("id").getNodeValue() + "' setback='no'/>");
answer = spooler.execute_xml("<modify_order job_chain='" + dependentJobChainPath + "' order='" + signalNodes.item(i).getAttributes().getNamedItem("id").getNodeValue() + "' setback='no'/>");
} else {
Job_chain j = spooler.job_chain(dependentJobChainPath);
spooler_log.debug9("---> dependentJobChainPath:" + dependentJobChainPath);
Job_chain_node n = j.node(signalNodes.item(i).getAttributes().getNamedItem("state").getNodeValue());
Job_chain_node next_n = n.next_node();
if (next_n.job() == null) {
spooler_log.info("end state reached");
}
String next_state = n.next_state();