KickJava   Java API By Example, From Geeks To Geeks.

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


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: CountStatisticImpl.java,v 1.2 2005/12/25 03:52:12 tcfujii Exp $
31  * $Date: 2005/12/25 03:52:12 $
32  * $Revision: 1.2 $
33 */

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

46
47 public class CountStatisticImpl extends StatisticImpl implements CountStatistic JavaDoc {
48     
49     private long count;
50     private static final StringManager localStrMgr =
51                 StringManager.getManager(CountStatisticImpl.class);
52
53     /**
54      * Constructs an instance of this class with following default values:
55      * <ul>
56      * <li> Unit is empty string. </li>
57      * <li> Current Value is StatisticImpl#DEFAULT_VALUE. </li>
58      * <li> Description is calculated from the name passed in. This may well be read from a properties file to address i18n. </li>
59      * <li> LastSampleTime is time at the time of calling this method.</li>
60      * <li> StartTime is the same as LastSampleTime. </li>
61      * </ul>
62      * @param name String indicating the name of the statistic
63      */

64     public CountStatisticImpl(String JavaDoc name) {
65         this(name, DEFAULT_UNIT);
66     }
67     /**
68      * Constructs an instance of this class with following default values:
69      * <ul>
70      * <li> Current Value is StatisticImpl#DEFAULT_VALUE. </li>
71      * <li> Description is calculated from the name passed in. This may well be read from a properties file to address i18n. </li>
72      * <li> LastSampleTime is time at the time of calling this method.</li>
73      * <li> StartTime is the same as LastSampleTime. </li>
74      * </ul>
75      * @param name String indicating the name of the statistic
76      * @param unit String indicating the unit of the statistic
77      */

78     public CountStatisticImpl(String JavaDoc name, String JavaDoc unit) {
79         this(name, unit, DEFAULT_VALUE);
80     }
81     /**
82      * Constructs an instance of this class with following default values:
83      * <ul>
84      * <li> Description is calculated from the name passed in. This may well be read from a properties file to address i18n. </li>
85      * <li> LastSampleTime is time at the time of calling this method.</li>
86      * <li> StartTime is the same as LastSampleTime. </li>
87      * </ul>
88      * @param name String indicating the name of the statistic
89      * @param unit String indicating the unit of the statistic
90      * @param desc A brief description of the statistic
91      */

92     public CountStatisticImpl(String JavaDoc name, String JavaDoc unit, String JavaDoc desc) {
93         this(DEFAULT_VALUE, name, unit, desc, Util.getInitTime()[0], Util.getInitTime()[1]);
94     }
95     /**
96      * Constructs an instance of this class with following default values:
97      * <ul>
98      * <li> Description is calculated from the name passed in. This may well be read from a properties file to address i18n. </li>
99      * <li> LastSampleTime is time at the time of calling this method.</li>
100      * <li> StartTime is the same as LastSampleTime. </li>
101      * </ul>
102      * @param name String indicating the name of the statistic
103      * @param unit String indicating the unit of the statistic
104      * @param value long indicating the unit of the statistic
105      */

106     public CountStatisticImpl(String JavaDoc name, String JavaDoc unit, long value) {
107         this(value, name, unit, Util.getDescriptionFromName(name), Util.getInitTime()[0], Util.getInitTime()[1]);
108     }
109
110     /** Constructs an immutable instance of CountStatistic with given parameters.
111      * @param curVal The current value of this statistic
112      * @param name The name of the statistic
113      * @param unit The unit of measurement for this statistic
114      * @param desc A brief description of the statistic
115      * @param startTime Time in milliseconds at which the measurement was started
116      * @param sampleTime Time at which the last measurement was done.
117      **/

118     public CountStatisticImpl(long countVal, String JavaDoc name, String JavaDoc unit,
119                               String JavaDoc desc, long sampleTime, long startTime) {
120         
121         super(name, unit, desc, startTime, sampleTime);
122         count = countVal;
123     }
124
125     /**
126      * Returns the current value of this statistic.
127      * @return long indicating current value
128      */

129     public long getCount() {
130         return count;
131     }
132     
133     private static class Util {
134         /** A method to get the description from a name. Can be simple property file
135          * pair reader. Note that name is invariant, whereas the descriptions are
136          * localizable.
137          */

138         private static String JavaDoc getDescriptionFromName(String JavaDoc name) {
139             return (localStrMgr.getString("describes_string") + name);
140         }
141
142         /** Returns an array of two longs, that represent the times at the time of call.
143          * The idea is not to call expensive System#currentTimeMillis twice for two
144          * successive operations.
145          */

146         private static long[] getInitTime() {
147             final long time = System.currentTimeMillis();
148             return ( new long[]{time, time} );
149         }
150     }
151 }
152
Popular Tags