01: /*
02: * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
03: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
04: */
05: package com.sun.portal.monitoring.statistics;
06:
07: public class RollingAvgTimeStatisticImpl extends BoundaryStatisticImpl
08: implements RollingAvgTimeStatistic {
09: public long getCount() {
10: return count;
11: }
12:
13: public void setCount(long count) {
14: this .count = count;
15: }
16:
17: public long getMaxTime() {
18: return maxTime;
19: }
20:
21: public void setMaxTime(long maxTime) {
22: this .maxTime = maxTime;
23: }
24:
25: public long getMinTime() {
26: return minTime;
27: }
28:
29: public void setMinTime(long minTime) {
30: this .minTime = minTime;
31: }
32:
33: public long getLastTime() {
34: return lastTime;
35: }
36:
37: public void setLastTime(long lastTime) {
38: this .lastTime = lastTime;
39: }
40:
41: public long getRollingAvgTime() {
42: return rollingAvgTime;
43: }
44:
45: public void setRollingAvgTime(long rollingAvgTime) {
46: this .rollingAvgTime = rollingAvgTime;
47: }
48:
49: public long getTotalTime() {
50: return totalTime;
51: }
52:
53: public void setTotalTime(long totalTime) {
54: this .totalTime = totalTime;
55: }
56:
57: private long count;
58: private long lastTime;
59: private long maxTime;
60: private long minTime;
61: private long rollingAvgTime;
62: private long totalTime;
63:
64: public void reset() {
65: count = maxTime = minTime = totalTime = lastTime = 0;
66: rollingAvgTime = 0;
67: super .reset();
68: }
69:
70: public void setTime(long currentTime) {
71: count++;
72: lastTime = currentTime;
73:
74: if (maxTime < currentTime) {
75: maxTime = currentTime;
76: } else if ((minTime == 0) || (minTime > currentTime)) {
77: minTime = currentTime;
78: }
79:
80: totalTime += currentTime;
81:
82: if (rollingAvgTime == 0) {
83: rollingAvgTime = currentTime;
84: } else {
85: long span;
86: span = (getCount() < getLowerBound()) ? getLowerBound()
87: : getCount(); // span should be at least LowerBound
88: span = (getCount() > getUpperBound()) ? getUpperBound()
89: : getCount(); // span can be max UpperBound
90: rollingAvgTime = (rollingAvgTime * span + currentTime)
91: / (span + 1);
92: }
93:
94: setLastSampleTime(System.currentTimeMillis());
95: }
96: }
|