1
14
15 package com.liferay.portal.monitoring.statistics;
16
17
25 public class AverageStatistics extends BaseStatistics {
26
27 public AverageStatistics(String name) {
28 super(name);
29
30 _countStatistics = new CountStatistics(name);
31 }
32
33 public void addDuration(long duration) {
34 _countStatistics.incrementCount();
35
36 setLastTime(duration);
37
38 if (getMaxTime() < duration) {
39 setMaxTime(duration);
40 }
41 else if ((getMinTime() == 0) || (getMinTime() > duration)) {
42 setMinTime(duration);
43 }
44
45 if (_averageTime == 0) {
46 _averageTime = duration;
47 }
48 else {
49 long span = 0;
50
51 if (_countStatistics.getCount() < getLowerBound()) {
52 span = getLowerBound();
53 }
54 else if ((_countStatistics.getCount() > getUpperBound())) {
55 span = getUpperBound();
56 }
57 else {
58 span = _countStatistics.getCount();
59 }
60
61 _averageTime = (_averageTime * span + duration) / (span + 1);
62 }
63
64 setLastSampleTime(System.currentTimeMillis());
65 }
66
67 public long getAverageTime() {
68 return _averageTime;
69 }
70
71 public long getCount() {
72 return _countStatistics.getCount();
73 }
74
75 public void reset() {
76 super.reset();
77
78 _averageTime = 0;
79 }
80
81 private long _averageTime;
82 private CountStatistics _countStatistics;
83
84 }