/**
* Flush the data to the socket.
* Overwrite this in your derived class to send UDP
*/
protected void sendMessage(MsgInfo msgInfo, String requestId, MethodName methodName, boolean udp) throws XmlBlasterException, IOException {
I_ProgressListener listener = this.progressListener;
try {
// TODO: On server side the msgInfoParserClassName should be from CbSocketDriver configuration
byte[] msg = msgInfo.createRawMsg(getCbMsgInfoParserClassName());
if (log.isLoggable(Level.FINEST)) log.finest("Sending TCP data of length " + msg.length + " >" + XbfParser.createLiteral(msg) + "<");
if (listener != null) {
listener.progressWrite("", 0, msg.length);
}
else
log.fine("The progress listener is null");
int bytesLeft = msg.length;
int bytesRead = 0;
if (oStream == null)
throw new XmlBlasterException(glob, ErrorCode.COMMUNICATION_NOCONNECTION, ME, "sendMessage() invocation ignored, we are shutdown.");
synchronized (oStream) {
while (bytesLeft > 0) {
int toRead = bytesLeft > this.maxChunkSize ? this.maxChunkSize : bytesLeft;
oStream.write(msg, bytesRead, toRead);
oStream.flush();
bytesRead += toRead;
bytesLeft -= toRead;
if (listener != null)
listener.progressWrite("", bytesRead, msg.length);
}
if (this.isNullTerminated) { // If using XmlScriptInterpreter as parserClass, we finish each script with a null byte
oStream.write(0);
oStream.flush();
}
if (log.isLoggable(Level.FINE)) log.fine("TCP data is send");
}
if (listener != null) {
listener.progressWrite("", msg.length, msg.length);
}
}
catch (IOException ex) {
if (listener != null) {
listener.clearCurrentWrites();
listener.clearCurrentReads();
}
throw ex;
}
catch (XmlBlasterException ex) {
if (listener != null) {
listener.clearCurrentWrites();
listener.clearCurrentReads();
}
throw ex;
}
}