public boolean spooler_process() {
String request = "";
String response = "";
Variable_set parameters = null;
SOSSchedulerCommand remoteCommand = null;
String signalId = null;
HashMap res = null ;
try {
if (listOfSignalObject.hasNext()) {
res = (HashMap)listOfSignalObject.next();
parameters = spooler_task.params();
//wenn scheduler_remote_host und scheduler_remote_port nicht angegeben sind, dann
//die Einstellungen aus der Settings lesen
if((sosString.parseToString(getHost()).length() == 0
|| sosString.parseToString(getHost()).equalsIgnoreCase("localhost")) &&
getPort() == 4444) {
SOSConnectionSettings settings = new SOSConnectionSettings(sosConnection, "SETTINGS", new SOSSchedulerLogger(this.spooler.log()));
Properties section = settings.getSection(application, sectionname);
if(sosString.parseToString(section, "scheduler.host").length() > 0){
setHost(sosString.parseToString(section, "scheduler.host"));
spooler_log.info(".. settings [scheduler.host]: " + this.getHost());
//Port auslesen nur wenn host auch aus der Settingstabelle ausgelesen wurde.
if(sosString.parseToString(section, "scheduler.port").length() > 0){
int sPort = 0;
try {
sPort = Integer.parseInt(sosString.parseToString(section, "scheduler.port"));
setPort(sPort);
spooler_log.info(".. settings [scheduler.port]: " + this.getPort());
} catch (Exception e) {
spooler_log.warn("..error while reading settings[scheduler.port]: " + e.getMessage());
}
}
}
}
signalId = sosString.parseToString(res, "signal_id");
spooler_log.debug("..signal Id: " + signalId);
request = "<add_order";
request += " replace=\"" + (this.isReplace() ? "yes" : "no") + "\"";
if (this.getOrderId() != null && this.getOrderId().length() > 0) request += " id=\"" + this.getOrderId() + "\"";
if (this.getAt() != null && this.getAt().length() > 0) request += " at=\"" + this.getAt() + "\"";
if (sosString.parseToString(res, "job_chain").length() > 0) request += " job_chain=\"" + sosString.parseToString(res, "job_chain") + "\"";
else if (this.getJobChain() != null && this.getJobChain().length() > 0) request += " job_chain=\"" + this.getJobChain() + "\"";
if (this.getPriority() != null && this.getPriority().length() > 0) request += " priority=\"" + this.getPriority() + "\"";
if (this.getState() != null && this.getState().length() > 0) request += " state=\"" + this.getState() + "\"";
request += " title=\"" + (sosString.parseToString(getTitle()).length() > 0 ? getTitle()+":"+signalId : signalId )+ "\"";
if (this.getWebService() != null && this.getWebService().length() > 0) request += " web_service=\"" + this.getWebService() + "\"";
request += ">";
request += "<params>";
String[] params = parameters.names().split(";");
for(int i=0; i<params.length; i++) {
if (!params[i].startsWith("scheduler_remote_") && !params[i].equalsIgnoreCase("sos_settings_file")) {
request += "<param name=\"" + params[i] + "\" value=\"" + parameters.var(params[i]) + "\"/>";
}
}
//Parameter aus der Tabelle SCHEDULER_SIGNAL_PARAMETERS
String selParameters = "SELECT \"NAME\", \"VALUE\", \"LONG_VALUE\" FROM "
+ TABLE_SCHEDULER_SIGNAL_PARAMETERS+
" WHERE \"SIGNAL_ID\" = " + signalId ;
if(sosString.parseToString(res.get("operation")).length() > 0) {
String value = sosString.parseToString(res.get("operation")).toLowerCase() ;
request += "<param name=\"operation\" value=\"" + value+ "\"/>";
}
ArrayList listOfParams = sosConnection.getArray(selParameters);
for (int i =0; i < listOfParams.size(); i++) {
HashMap h = (HashMap)listOfParams.get(i);
String value = (sosString.parseToString(h.get("value")).length() > 0) ? sosString.parseToString(h.get("value")) : sosString.parseToString(h.get("long_value")) ;
request += "<param name=\"" + h.get("name") + "\" value=\"" + value+ "\"/>";
}
request += "</params>";
if (this.getRunTime() != null && this.getRunTime().length() > 0) request += this.getRunTime();
request += "</add_order>";
remoteCommand = new SOSSchedulerCommand(this.getHost(), this.getPort(), this.getProtocol());
remoteCommand.connect();
spooler_log.info("sending request to remote Job Scheduler [" + this.getHost() + ":" + this.getPort() + "]: " + request);
remoteCommand.sendRequest(request);
if (this.getProtocol().equalsIgnoreCase("tcp")) { // no response is returned for UDP messages
response = remoteCommand.getResponse();
SOSXMLXPath xpath = new SOSXMLXPath(new StringBuffer(response));
String errCode = xpath.selectSingleNodeValue("//ERROR/@code");
String errMessage = xpath.selectSingleNodeValue("//ERROR/@text");
spooler_log.info("remote job scheduler response: " + response);
if ((errCode != null && errCode.length() > 0) || (errMessage != null && errMessage.length() > 0)) {
spooler_log.warn("remote Job Scheduler response reports error message: " + errMessage + " [" + errCode + "]");
}
}
//status = 1 entspricht Export-Auftrag erzeugt
String upStr = "UPDATE " +
TABLE_SCHEDULER_SIGNAL_OBECTS +
" SET \"STATUS\" = 1 WHERE \"SIGNAL_ID\" = " + signalId;
sosConnection.executeUpdate(upStr);
sosConnection.commit();
}
countProcessOk++;
return listOfSignalObject.hasNext();
} catch (Exception e) {
countProcessError++;
spooler_log.error("error occurred for remote execution: " + e.getMessage());
if(sosConnection != null) {
try {
sosConnection.rollback();
String upStr = "UPDATE " +
TABLE_SCHEDULER_SIGNAL_OBECTS +
" SET \"STATUS\" = 1001 WHERE \"SIGNAL_ID\" = " + signalId;
sosConnection.executeUpdate(upStr);
sosConnection.commit();
} catch (Exception x) {}
}
return false;
} finally {
if (remoteCommand != null) {
try { remoteCommand.disconnect(); } catch (Exception x) {} // gracefully ignore this error
}
}
}