2004-11-22 jrandom

* Update to the SAM bridge to reduce some unnecessary memory allocation.
    * New stat to keep track of slow jobs (ones that take more than a second
      to excute).  This is published in the netDb as jobQueue.jobRunSlow
This commit is contained in:
jrandom
2004-11-23 01:12:34 +00:00
committed by zzz
parent 6d5fc8ca21
commit 608d713dca
7 changed files with 45 additions and 16 deletions

View File

@ -100,6 +100,14 @@ public abstract class SAMHandler implements Runnable {
socketOS.flush();
}
}
/**
* If you're crazy enough to write to the raw socket, grab the write lock
* with getWriteLock(), synchronize against it, and write to the getOut()
*
*/
protected Object getWriteLock() { return socketWLock; }
protected OutputStream getOut() { return socketOS; }
/**
* Write a string to the handler's socket. This method must

View File

@ -14,6 +14,7 @@ import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InterruptedIOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.ConnectException;
import java.net.NoRouteToHostException;
@ -765,15 +766,24 @@ public class SAMv1Handler extends SAMHandler implements SAMRawReceiver, SAMDatag
throw new NullPointerException("BUG! STREAM session is null!");
}
ByteArrayOutputStream msg = new ByteArrayOutputStream();
String msgText = "STREAM RECEIVED ID=" + id +" SIZE=" + len + "\n";
if (_log.shouldLog(Log.DEBUG))
_log.debug("sending to client: " + msgText);
msg.write(msgText.getBytes("ISO-8859-1"));
msg.write(data, 0, len);
writeBytes(msg.toByteArray());
byte prefix[] = msgText.getBytes("ISO-8859-1");
// dont waste so much memory
//ByteArrayOutputStream msg = new ByteArrayOutputStream();
//msg.write(msgText.getBytes("ISO-8859-1"));
//msg.write(data, 0, len);
// writeBytes(msg.toByteArray());
Object writeLock = getWriteLock();
OutputStream out = getOut();
synchronized (writeLock) {
out.write(prefix);
out.write(data, 0, len);
out.flush();
}
}
public void notifyStreamDisconnection(int id, String result, String msg) throws IOException {