KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > monitor > stats > BoundedRangeStatisticImpl


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * Copyright 2004-2005 Sun Microsystems, Inc. All rights reserved.
26  * Use is subject to license terms.
27  */

28
29 /*
30  * $Id: BoundedRangeStatisticImpl.java,v 1.2 2005/12/25 03:52:10 tcfujii Exp $
31  * $Date: 2005/12/25 03:52:10 $
32  * $Revision: 1.2 $
33  */

34
35
36 package com.sun.enterprise.admin.monitor.stats;
37 import javax.management.j2ee.statistics.BoundedRangeStatistic JavaDoc;
38 import com.sun.enterprise.util.i18n.StringManager;
39
40 /** An implementation of a BoundedRangeStatistic. All instances of this class are
41  * immutable. Provides all the necessary accessors for properties.
42  * @author Muralidhar Vempaty
43  * @author Kedar Mhaswade
44  * @since S1AS8.0
45  * @verison 1.0
46  */

47
48 public final class BoundedRangeStatisticImpl extends StatisticImpl implements
49     BoundedRangeStatistic JavaDoc {
50     
51     private final long currentVal;
52     private final long highWaterMark;
53     private final long lowWaterMark;
54     private final long upperBound;
55     private final long lowerBound;
56     private static final StringManager localStrMgr =
57                 StringManager.getManager(BoundedRangeStatisticImpl.class);
58     
59     /** DEFAULT_UPPER_BOUND is maximum value Long can attain */
60     public static final long DEFAULT_MAX_BOUND = java.lang.Long.MAX_VALUE;
61     /** DEFAULT_LOWER_BOUND is same as DEFAULT_VALUE i.e. 0 */
62     public static final long DEFAULT_MIN_BOUND = DEFAULT_VALUE;
63
64     /**
65      * A constructor that creates an instance of class. Following are the defaults:
66      * <ul>
67      * <li> Unit is defaulted to empty string. </li>
68      * <li> Description is calculated from the name passed in. This may well be read from a properties file to address i18n. </li>
69      * <li> LastSampleTime is time at the time of calling this method.</li>
70      * <li> StartTime is the same as LastSampleTime. </li>
71      * <li> Current Value is initialized to StatisticImpl#DEFAULT_VALUE.</li>
72      * <li> UpperBound is initialized to StatisticImpl#DEFAULT_MAX_BOUND. </li>
73      * <li> LowerBound is initialized to StatisticImpl#DEFAULT_MIN_BOUND. </li>
74      * <li> HighWaterMark is initialized to Current Value. </li>
75      * <li> LowWaterMark is initialized to Current Value. </li>
76      * </ul>
77      * @param name String that indicates the name of this statistic
78      */

79     public BoundedRangeStatisticImpl(String JavaDoc name) {
80         this(name, DEFAULT_UNIT);
81     }
82     
83     /**
84      * A constructor that creates an instance of class. Following are the defaults:
85      * <ul>
86      * <li> Description is calculated from the name passed in. This may well be read from a properties file to address i18n. </li>
87      * <li> LastSampleTime is time at the time of calling this method.</li>
88      * <li> StartTime is the same as LastSampleTime. </li>
89      * <li> Current Value is initialized to StatisticImpl#DEFAULT_VALUE.</li>
90      * <li> UpperBound is initialized to StatisticImpl#DEFAULT_MAX_BOUND. </li>
91      * <li> LowerBound is initialized to StatisticImpl#DEFAULT_MIN_BOUND. </li>
92      * <li> HighWaterMark is initialized to Current Value. </li>
93      * <li> LowWaterMark is initialized to Current Value. </li>
94      * </ul>
95      * @param name String that indicates the name of this statistic
96      * @param unit String that indicates the unit of this statistic
97      */

98     public BoundedRangeStatisticImpl(String JavaDoc name, String JavaDoc unit) {
99         this(name, unit, DEFAULT_VALUE);
100     }
101
102     /**
103      * A constructor that creates an instance of class. Following are the defaults:
104      * <ul>
105      * <li> Description is calculated from the name passed in. This may well be read from a properties file to address i18n. </li>
106      * <li> LastSampleTime is time at the time of calling this method.</li>
107      * <li> StartTime is the same as LastSampleTime. </li>
108      * <li> UpperBound is initialized to StatisticImpl#DEFAULT_MAX_BOUND. </li>
109      * <li> LowerBound is initialized to StatisticImpl#DEFAULT_MIN_BOUND. </li>
110      * <li> HighWaterMark is initialized to Current Value. </li>
111      * <li> LowWaterMark is initialized to Current Value. </li>
112      * </ul>
113      * @param name String that indicates the name of this statistic
114      * @param unit String that indicates the unit of this statistic
115      * @param desc A brief description of the statistic
116      */

117     public BoundedRangeStatisticImpl(String JavaDoc name, String JavaDoc unit, String JavaDoc desc, long value, long max, long min) {
118         this (value,
119                 value,
120                 value,
121                 max,
122                 min,
123                 name,
124                 unit,
125                 desc,
126                 Util.getInitTime()[0],
127                 Util.getInitTime()[1]
128                 );
129
130     }
131     
132         /**
133      * A constructor that creates an instance of class. Following are the defaults:
134      * <ul>
135      * <li> LastSampleTime is time at the time of calling this method.</li>
136      * <li> StartTime is the same as LastSampleTime. </li>
137      * <li> UpperBound is initialized to StatisticImpl#DEFAULT_MAX_BOUND. </li>
138      * <li> LowerBound is initialized to StatisticImpl#DEFAULT_MIN_BOUND. </li>
139      * <li> HighWaterMark is initialized to Current Value. </li>
140      * <li> LowWaterMark is initialized to Current Value. </li>
141      * </ul>
142      * @param name String that indicates the name of this statistic
143      * @param unit String that indicates the unit of this statistic
144      */

145     public BoundedRangeStatisticImpl(String JavaDoc name, String JavaDoc unit, long value) {
146         this(name, unit, value, DEFAULT_MAX_BOUND, DEFAULT_MIN_BOUND);
147     }
148
149     /**
150      * A constructor that creates an instance of class. Following are the defaults:
151      * <ul>
152      * <li> Description is calculated from the name passed in. This may well be read from a properties file to address i18n. </li>
153      * <li> LastSampleTime is time at the time of calling this method.</li>
154      * <li> StartTime is the same as LastSampleTime. </li>
155      * <li> HighWaterMark is initialized to Current Value. </li>
156      * <li> LowWaterMark is initialized to Current Value. </li>
157      * </ul>
158      * @param name String that indicates the name of this statistic
159      * @param unit String that indicates the unit of this statistic
160      * @param value long that indicates the initial value of this statistic
161      * @param max long that indicates the maximum permissible value of this statistic
162      * @param min long that indicates the minimum permissible value of this statistic
163      */

164     public BoundedRangeStatisticImpl(String JavaDoc name, String JavaDoc unit, long value,
165         long max, long min) {
166         this(name, unit, value, max, min, value, value);
167     }
168     
169     /**
170      * A constructor that creates an instance of class. Following are the defaults:
171      * <ul>
172      * <li> Description is calculated from the name passed in. This may well be read from a properties file to address i18n. </li>
173      * <li> LastSampleTime is time at the time of calling this method.</li>
174      * <li> StartTime is the same as LastSampleTime. </li>
175      * </ul>
176      * @param name String that indicates the name of this statistic
177      * @param unit String that indicates the unit of this statistic
178      * @param value long that indicates the initial value of this statistic
179      * @param max long that indicates the maximum permissible value of this statistic
180      * @param min long that indicates the minimum permissible value of this statistic
181      * @param highMark long that indicates the high watermark value of this statistic
182      * @param lowMark long that indicates the low watermark value of this statistic
183      */

184     public BoundedRangeStatisticImpl(String JavaDoc name, String JavaDoc unit, long value,
185         long max, long min, long highMark, long lowMark) {
186             this (value,
187                 highMark,
188                 lowMark,
189                 max,
190                 min,
191                 name,
192                 unit,
193                 Util.getDescriptionFromName(name),
194                 Util.getInitTime()[0],
195                 Util.getInitTime()[1]
196                 );
197     }
198
199     /**
200      * Constructs an immutable instance of BoundedRangeStatisticImpl.
201      * @param curVal The current value of this statistic
202      * @param highMark The highest value of this statistic, since measurement
203      * started
204      * @param lowMark The lowest value of this statistic, since measurement
205      * started
206      * @param upper The upper limit of this statistic
207      * @param lower The lower limit of this statistic
208      * @param name The name of the statistic
209      * @param unit The unit of measurement for this statistic
210      * @param desc A brief description of the statistic
211      * @param startTime Time in milliseconds at which the measurement was started
212      * @param sampleTime Time at which the last measurement was done.
213      **/

214     
215     public BoundedRangeStatisticImpl(long curVal, long highMark, long lowMark,
216                                      long upper, long lower, String JavaDoc name,
217                                      String JavaDoc unit, String JavaDoc desc, long startTime,
218                                      long sampleTime) {
219         super(name, unit, desc, startTime, sampleTime);
220         currentVal = curVal;
221         highWaterMark = highMark;
222         lowWaterMark = lowMark;
223         upperBound = upper;
224         lowerBound = lower;
225     }
226     
227     /**
228      * Returns the current value of this statistic.
229      * @return long indicating the current value
230      */

231     public long getCurrent() {
232         return currentVal;
233     }
234     
235     /**
236      * Returns the highest value of this statistic, since measurement started.
237      * @return long indicating high water mark
238      */

239      public long getHighWaterMark() {
240         return highWaterMark;
241     }
242     
243     /**
244      * Returns the lowest value of this statistic, since measurement started.
245      * @return long indicating low water mark
246      */

247     public long getLowWaterMark() {
248         return lowWaterMark;
249     }
250     
251     /**
252      * Return the lowest possible value, that this statistic is permitted to attain.
253      * @return long indicating the lower bound
254      */

255     public long getLowerBound() {
256         return lowerBound;
257     }
258     
259     /**
260      * Returns the highest possible value, that this statistic is permitted to attain.
261      * @return long indicating the higher bound
262      */

263     public long getUpperBound() {
264         return upperBound;
265     }
266     
267     private static class Util {
268         /** A method to get the description from a name. Can be simple property file
269          * pair reader. Note that name is invariant, whereas the descriptions are
270          * localizable.
271          */

272         private static String JavaDoc getDescriptionFromName(String JavaDoc name) {
273             return (localStrMgr.getString("describes_string") + name);
274         }
275
276         /** Returns an array of two longs, that represent the times at the time of call.
277          * The idea is not to call expensive System#currentTimeMillis twice for two
278          * successive operations.
279          */

280         private static long[] getInitTime() {
281             final long time = System.currentTimeMillis();
282             return ( new long[]{time, time} );
283         }
284     }
285 }
286
Popular Tags