* @param pobjJSCmd
* @return
*/
public Answer run(JSCmdBase pobjJSCmd) {
final String conMethodName = conClassName + "::run";
Answer objAnswer = null;
String strT = pobjJSCmd.toXMLString();
String strA = "";
try {
logger.debug(String.format("%1$s: Request: %n%2$s", conMethodName, strT));
if (objOptions.TransferMethod.isTcp()) {
this.getSocket().sendRequest(strT);
strA = getSocket().getResponse();
objAnswer = getAnswer(strA);
}
else
if (objOptions.TransferMethod.isUdp()) {
DatagramSocket udpSocket = null;
int intPortNumber = 0;
try {
udpSocket = new DatagramSocket();
intPortNumber = objOptions.PortNumber.value();
InetAddress objInetAddress = objOptions.ServerName.getInetAddress();
udpSocket.connect(objInetAddress, intPortNumber);
if (strT.indexOf("<?xml") == -1) {
strT = "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>" + strT;
}
byte[] btyBuffer = strT.getBytes();
udpSocket.send(new DatagramPacket(btyBuffer, btyBuffer.length, objInetAddress, intPortNumber));
}
catch (Exception e) {
e.printStackTrace();
throw e;
}
finally {
if (udpSocket != null) {
logger.debug(String.format("Command sent using UDP to host '%1$s' at port '%2$d'", objOptions.ServerName.toString(), intPortNumber) );
udpSocket.disconnect();
udpSocket = null;
}
}
}
else {
throw new JobSchedulerException(String.format("TransferMethod '%1$s' not supported (yet)", objOptions.TransferMethod.Value()));
}
}
catch (Exception e) {
throw new JobSchedulerException(String.format("%1$s: %2$s", conMethodName, e.getMessage()), e);
}
if (objAnswer != null) {
// TODO in Answer den original-response des js als string ablegen.
// TODO eigenst�ndige BasisKlasse JSAnswerBase bauen. ableiten von JSCmdBase.
if (objAnswer.getERROR() != null) {
throw new JobSchedulerException("Job Scheduler responds an error due to an invalid or wrong command\n" + strT);
}
}
return objAnswer;
} // private Object run