2004-11-27 jrandom

* Fix for a fast loop caused by a race in the new streaming library (thanks
      DrWoo, frontier, pwk_, and thetower!)
    * Minor updates to the SimpleTimer and Connection to help track down a
      high CPU usage problem (dumping debug info to stdout/wrapper.log if too
      many events/tasks fire in a second)
    * Minor fixes for races on client disconnects (causing NPEs)
This commit is contained in:
jrandom
2004-11-27 03:54:17 +00:00
committed by zzz
parent 64b5089909
commit 0b5a640896
7 changed files with 77 additions and 9 deletions

View File

@ -313,8 +313,26 @@ public class Connection {
return acked;
}
private long _occurredTime;
private long _occurredEventCount;
void eventOccurred() {
_chooser.getScheduler(this).eventOccurred(this);
long now = System.currentTimeMillis();
TaskScheduler sched = _chooser.getScheduler(this);
now = now - now % 1000;
if (_occurredTime == now) {
_occurredEventCount++;
} else {
_occurredTime = now;
if (_occurredEventCount > 5) {
_log.log(Log.CRIT, "More than 5 events (" + _occurredEventCount + ") in a second on "
+ toString() + ": scheduler = " + sched);
}
_occurredEventCount = 0;
}
sched.eventOccurred(this);
}
void resetReceived() {
@ -376,10 +394,8 @@ public class Connection {
_outputStream.destroy();
_outputStream = null;
_outboundQueue = null;
_handler = null;
if (_receiver != null)
_receiver.destroy();
_receiver = null;
if (_activityTimer != null)
SimpleTimer.getInstance().addEvent(_activityTimer, 1);
_activityTimer = null;

View File

@ -79,6 +79,10 @@ public class MessageOutputStream extends OutputStream {
remaining -= toWrite;
cur += toWrite;
_valid = _buf.length;
if (_dataReceiver == null) {
throwAnyError();
return;
}
ws = _dataReceiver.writeData(_buf, 0, _valid);
_written += _valid;
_valid = 0;
@ -117,6 +121,10 @@ public class MessageOutputStream extends OutputStream {
WriteStatus ws = null;
synchronized (_dataLock) {
if (_buf == null) throw new IOException("closed (buffer went away)");
if (_dataReceiver == null) {
throwAnyError();
return;
}
ws = _dataReceiver.writeData(_buf, 0, _valid);
_written += _valid;
_valid = 0;
@ -164,7 +172,8 @@ public class MessageOutputStream extends OutputStream {
ByteArray ba = null;
synchronized (_dataLock) {
// flush any data, but don't wait for it
_dataReceiver.writeData(_buf, 0, _valid);
if (_dataReceiver != null)
_dataReceiver.writeData(_buf, 0, _valid);
_written += _valid;
_valid = 0;

View File

@ -47,7 +47,8 @@ class SchedulerClosed extends SchedulerImpl {
}
public void eventOccurred(Connection con) {
long timeLeft = con.getCloseSentOn() + Connection.DISCONNECT_TIMEOUT - _context.clock().now();
reschedule(timeLeft, con);
// noop. we do the timeout through the simpleTimer anyway
//long timeLeft = con.getCloseSentOn() + Connection.DISCONNECT_TIMEOUT - _context.clock().now();
//reschedule(timeLeft, con);
}
}