KickJava   Java API By Example, From Geeks To Geeks.

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


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

34
35 package com.sun.enterprise.admin.monitor.stats;
36 import javax.management.j2ee.statistics.TimeStatistic JavaDoc;
37 import com.sun.enterprise.util.i18n.StringManager;
38
39 /** An implementation of a TimeStatistic. 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  */

45
46 public class TimeStatisticImpl extends StatisticImpl implements TimeStatistic JavaDoc {
47     
48     private final long count;
49     private final long maxTime;
50     private final long minTime;
51     private final long totTime;
52     private static final StringManager localStrMgr =
53                 StringManager.getManager(TimeStatisticImpl.class);
54
55     
56     public TimeStatisticImpl(String JavaDoc name) {
57         this(name, StatisticImpl.DEFAULT_UNIT);
58     }
59     public TimeStatisticImpl(String JavaDoc name, String JavaDoc unit) {
60         this(StatisticImpl.DEFAULT_VALUE, StatisticImpl.DEFAULT_VALUE,
61             StatisticImpl.DEFAULT_VALUE, StatisticImpl.DEFAULT_VALUE, name, unit,
62             Util.getDescriptionFromName(name), Util.getInitTime()[0], Util.getInitTime()[1]);
63     }
64
65         /** Constructs an immutable instance of TimeStatistic.
66      * @param name The name of the statistic
67      * @param unit The unit of measurement for this statistic
68      * @param desc A brief description of the statistic
69      */

70     public TimeStatisticImpl(String JavaDoc name, String JavaDoc unit, String JavaDoc desc) {
71         this(StatisticImpl.DEFAULT_VALUE, StatisticImpl.DEFAULT_VALUE,
72             StatisticImpl.DEFAULT_VALUE, StatisticImpl.DEFAULT_VALUE, name, unit,
73             desc, Util.getInitTime()[0], Util.getInitTime()[1]);
74         
75     }
76
77     /** Constructs an immutable instance of TimeStatistic.
78      * @deprecated use the other TimeStatisticImpl constructors.
79      * Counter, maxtime, mintime, totaltime, starttime
80      * last sampletime are automatically calculated
81      * at the first measurement.
82      * @param counter The number of times an operation has been invoked since
83      * measurement started
84      * @param maximumTime The maximum time it took to complete one invocation
85      * of an operation, since the measurement started
86      * @param minimumTime The minimum time it took to complete one invocation
87      * of an opeation, since the measurement started
88      * @param totalTime The total amount of time spent in all invocations,
89      * over the duration of the measurement
90      * @param name The name of the statistic
91      * @param unit The unit of measurement for this statistic
92      * @param desc A brief description of the statistic
93      * @param startTime Time in milliseconds at which the measurement was started
94      * @param sampleTime Time at which the last measurement was done.
95      */

96      public TimeStatisticImpl(long counter, long maximumTime, long minimumTime,
97                               long totalTime, String JavaDoc name, String JavaDoc unit,
98                              String JavaDoc desc, long startTime, long sampleTime) {
99         
100         super(name, unit, desc, startTime, sampleTime);
101         count = counter;
102         maxTime = maximumTime;
103         minTime = minimumTime;
104         totTime = totalTime;
105     }
106     
107     /**
108      * Returns the number of times an operation was invoked
109      * @return long indicating the number of invocations
110      */

111     public long getCount() {
112         return count;
113     }
114     
115     /**
116      * Returns the maximum amount of time that it took for one invocation of an
117      * operation, since measurement started.
118      * @return long indicating the maximum time for one invocation
119      */

120     public long getMaxTime() {
121         return maxTime;
122     }
123     
124     /**
125      * Returns the minimum amount of time that it took for one invocation of an
126      * operation, since measurement started.
127      * @return long indicating the minimum time for one invocation
128      */

129     public long getMinTime() {
130         return minTime;
131     }
132
133     /**
134      * Returns the amount of time that it took for all invocations,
135      * since measurement started.
136      * @return long indicating the total time for all invocation
137      */

138     public long getTotalTime() {
139         return totTime;
140     }
141     
142     private static class Util {
143         /** A method to get the description from a name. Can be simple property file
144          * pair reader. Note that name is invariant, whereas the descriptions are
145          * localizable.
146          */

147         private static String JavaDoc getDescriptionFromName(String JavaDoc name) {
148             return (localStrMgr.getString("describes_string") + name);
149         }
150
151         /** Returns an array of two longs, that represent the times at the time of call.
152          * The idea is not to call expensive System#currentTimeMillis twice for two
153          * successive operations.
154          */

155         private static long[] getInitTime() {
156             final long time = System.currentTimeMillis();
157             return ( new long[]{time, time} );
158         }
159     }
160 }
161
Popular Tags