25 package com.sun.corba.se.spi.monitoring; |
25 package com.sun.corba.se.spi.monitoring; |
26 |
26 |
27 import java.util.*; |
27 import java.util.*; |
28 |
28 |
29 /** |
29 /** |
30 * <p> |
|
31 * |
|
32 * @author Hemanth Puttaswamy |
30 * @author Hemanth Puttaswamy |
33 * </p> |
31 * |
34 * <p> |
|
35 * StatisticsAccumulator accumulates the samples provided by the user and |
32 * StatisticsAccumulator accumulates the samples provided by the user and |
36 * computes the value of minimum, maximum, sum and sample square sum. When |
33 * computes the value of minimum, maximum, sum and sample square sum. When |
37 * the StatisticMonitoredAttribute calls getValue(), it will compute all |
34 * the StatisticMonitoredAttribute calls getValue(), it will compute all |
38 * the statistics for the collected samples (Which are Minimum, Maximum, |
35 * the statistics for the collected samples (Which are Minimum, Maximum, |
39 * Average, StandardDeviation) and provides a nice printable record as a |
36 * Average, StandardDeviation) and provides a nice printable record as a |
40 * String. |
37 * String. |
41 * |
38 * |
42 * Users can easily extend this class and provide the implementation of |
39 * Users can easily extend this class and provide the implementation of |
43 * toString() method to format the stats as desired. By default all the stats |
40 * toString() method to format the stats as desired. By default all the stats |
44 * are printed in a single line. |
41 * are printed in a single line. |
45 * </p> |
|
46 */ |
42 */ |
47 public class StatisticsAccumulator { |
43 public class StatisticsAccumulator { |
48 |
44 |
49 /////////////////////////////////////// |
45 /////////////////////////////////////// |
50 // attributes |
46 // attributes |
70 // operations |
66 // operations |
71 |
67 |
72 |
68 |
73 |
69 |
74 /** |
70 /** |
75 * <p> |
|
76 * User will use this method to just register a sample with the |
71 * User will use this method to just register a sample with the |
77 * StatisticsAccumulator. This is the only method that User will use to |
72 * StatisticsAccumulator. This is the only method that User will use to |
78 * expose the statistics, internally the StatisticMonitoredAttribute will |
73 * expose the statistics, internally the StatisticMonitoredAttribute will |
79 * collect the information when requested from the ASAdmin. |
74 * collect the information when requested from the ASAdmin. |
80 * </p> |
|
81 * <p> |
|
82 * |
|
83 * </p> |
|
84 * <p> |
|
85 * |
75 * |
86 * @param value a double value to make it more precise |
76 * @param value a double value to make it more precise |
87 * </p> |
|
88 */ |
77 */ |
89 public void sample(double value) { |
78 public void sample(double value) { |
90 sampleCount++; |
79 sampleCount++; |
91 if( value < min ) min = value; |
80 if( value < min ) min = value; |
92 if( value > max) max = value; |
81 if( value > max) max = value; |
135 return Math.sqrt( |
124 return Math.sqrt( |
136 (sampleSquareSum-((sampleSumSquare)/sampleCount))/(sampleCount-1)); |
125 (sampleSquareSum-((sampleSumSquare)/sampleCount))/(sampleCount-1)); |
137 } |
126 } |
138 |
127 |
139 /** |
128 /** |
140 * <p> |
|
141 * Construct the Statistics Accumulator by providing the unit as a String. |
129 * Construct the Statistics Accumulator by providing the unit as a String. |
142 * The examples of units are "Hours", "Minutes", |
130 * The examples of units are "Hours", "Minutes", |
143 * "Seconds", "MilliSeconds", "Micro Seconds" |
131 * "Seconds", "MilliSeconds", "Micro Seconds" etc. |
144 * etc., |
132 * |
145 * </p> |
|
146 * <p> |
|
147 * |
|
148 * @return a StatisticsAccumulator with ... |
|
149 * </p> |
|
150 * <p> |
|
151 * @param unit a String representing the units for the samples collected |
133 * @param unit a String representing the units for the samples collected |
152 * </p> |
|
153 */ |
134 */ |
154 public StatisticsAccumulator( String unit ) { |
135 public StatisticsAccumulator( String unit ) { |
155 this.unit = unit; |
136 this.unit = unit; |
156 sampleCount = 0; |
137 sampleCount = 0; |
157 sampleSum = 0; |
138 sampleSum = 0; |