Author: toad
Date: 2006-09-22 14:06:41 +0000 (Fri, 22 Sep 2006)
New Revision: 10499
Modified:
trunk/freenet/src/freenet/support/math/TimeDecayingRunningAverage.java
Log:
Don't corrupt the average when the clock goes backwards.
Check current against min/max when reading in from a SimpleFieldSet.
Modified: trunk/freenet/src/freenet/support/math/TimeDecayingRunningAverage.java
===================================================================
--- trunk/freenet/src/freenet/support/math/TimeDecayingRunningAverage.java
2006-09-22 12:04:29 UTC (rev 10498)
+++ trunk/freenet/src/freenet/support/math/TimeDecayingRunningAverage.java
2006-09-22 14:06:41 UTC (rev 10499)
@@ -83,9 +83,15 @@
started = fs.getBoolean("Started", false);
if(started) {
curValue = fs.getDouble("CurrentValue", curValue);
- totalReports = fs.getLong("TotalReports", 0);
- long uptime = fs.getLong("Uptime", 0);
- createdTime = System.currentTimeMillis() - uptime;
+ if(curValue > maxReport || curValue < minReport) {
+ curValue = defaultValue;
+ totalReports = 0;
+ createdTime = System.currentTimeMillis();
+ } else {
+ totalReports = fs.getLong("TotalReports", 0);
+ long uptime = fs.getLong("Uptime", 0);
+ createdTime = System.currentTimeMillis() - uptime;
+ }
}
}
}
@@ -146,6 +152,10 @@
} else if(lastReportTime != -1) { // might be just
serialized in
long thisInterval =
now - lastReportTime;
+ if(thisInterval < 0) {
+ Logger.error(this, "Clock went back in
time, ignoring report: "+now+" was "+lastReportTime+" (back
"+(-thisInterval)+"ms");
+ return;
+ }
double thisHalfLife = halfLife;
long uptime = now - createdTime;
if((uptime / 4) < thisHalfLife) thisHalfLife =
(uptime / 4);