1 10 11 package org.mule.util.counters.impl; 12 13 import org.mule.util.counters.CounterFactory.Type; 14 15 19 public class TimeAverage extends AggregateCounter 20 { 21 22 private double sum = 0.0; 23 private double lastValue = 0.0; 24 private long firstTime = System.currentTimeMillis(); 25 private long lastTime = firstTime; 26 27 public TimeAverage(String name, AbstractCounter base) 28 { 29 super(name, Type.AVERAGE, base); 30 } 31 32 public double nextValue() 33 { 34 long current = System.currentTimeMillis(); 35 return (sum + lastValue * (current - this.lastTime)) / (current - firstTime); 36 } 37 38 public void doCompute() 39 { 40 long current = System.currentTimeMillis(); 41 this.sum += this.lastValue * (current - this.lastTime); 42 this.lastValue = getBase().nextValue(); 43 this.lastTime = current; 44 } 45 } 46 | Popular Tags |