public void sampleOccurred(SampleEvent e) {
SampleResult s = e.getResult();
long now = System.currentTimeMillis() / 1000;// in seconds
RunningSample myDelta = null;
RunningSample myTotal = null;
boolean reportNow = false;
/*
* Have we reached the reporting boundary?
* Need to allow for a margin of error, otherwise can miss the slot.
* Also need to check we've not hit the window already
*/
synchronized (myTotals) {
if (s != null) {
myTotals.delta.addSample(s);
}
if ((now > myTotals.last + INTERVAL_WINDOW) && (now % INTERVAL <= INTERVAL_WINDOW)) {
reportNow = true;
// copy the data to minimise the synch time
myDelta = new RunningSample(myTotals.delta);
myTotals.moveDelta();
myTotal = new RunningSample(myTotals.total);
myTotals.last = now; // stop double-reporting
}
}
if (reportNow) {
String str;
str = format(myName, myDelta, "+");
if (TOLOG) {
log.info(str);
}
if (TOOUT) {
System.out.println(str);
}
// Only if we have updated them
if (myTotal != null && myDelta != null &&myTotal.getNumSamples() != myDelta.getNumSamples()) {
str = format(myName, myTotal, "=");
if (TOLOG) {
log.info(str);
}
if (TOOUT) {