more refactoring

This commit is contained in:
zab
2012-11-17 18:36:55 +00:00
parent 836620c375
commit 82e4244473
2 changed files with 22 additions and 19 deletions

View File

@@ -287,6 +287,15 @@ public class Rate {
return 0.0D;
}
/**
* @return the average or lifetime average depending on last event count
*/
public synchronized double getAvgOrLifetimeAvg() {
if (getLastEventCount() > 0)
return getAverageValue();
return getLifetimeAverageValue();
}
/**
* During the last period, how much of the time was spent actually processing events in proportion
* to how many events could have occurred if there were no intervals?
@@ -407,12 +416,15 @@ public class Rate {
/**
* @param out where to store the computed averages.
* @param useLifetime whether the lifetime average should be used if
* there are no events.
*/
public synchronized void computeAverages(RateAverages out) {
public synchronized void computeAverages(RateAverages out, boolean useLifetime) {
final long total = _currentEventCount + _lastEventCount;
if (total <= 0) {
out.setAverage(getAverageValue());
final double avg = useLifetime ? getAvgOrLifetimeAvg() : getAverageValue();
out.setAverage(avg);
return;
}