1
2
3
4
5
6
7
8
9
10
11 package org.mule.util.counters.impl;
12
13 import org.mule.util.counters.CounterFactory.Type;
14
15 public class InstantRate extends AggregateCounter
16 {
17
18 private double firstTime;
19 private double lastTime;
20 private double value;
21
22 public InstantRate(String name, AbstractCounter base)
23 {
24 super(name, Type.INSTANT_RATE, base);
25 }
26
27 public double nextValue()
28 {
29 if (firstTime == 0 || firstTime == lastTime)
30 {
31 return Double.NaN;
32 }
33 else
34 {
35 return value / (lastTime - firstTime) * 1000.0;
36 }
37 }
38
39 public void doCompute()
40 {
41 firstTime = lastTime;
42 lastTime = System.currentTimeMillis();
43 value = getBase().nextValue();
44 }
45
46 }