KickJava   Java API By Example, From Geeks To Geeks.

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


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  * AverageRangeStatisticImpl.java
31  *
32  * Created on May 11, 2004, 3:06 PM
33  */

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

46
47 /**
48  *
49  * @author lwhite
50  */

51 public class AverageRangeStatisticImpl implements
52     AverageRangeStatistic /*BoundedRangeStatistic*/ {
53     
54     private BoundedRangeStatisticImpl boundedRangeStatistic = null;
55     private long numberOfSamples;
56     private long runningTotal;
57     
58     
59     /**
60      * Constructs an immutable instance of AverageRangeStatisticImpl.
61      * @param curVal The current value of this statistic
62      * @param highMark The highest value of this statistic, since measurement
63      * started
64      * @param lowMark The lowest value of this statistic, since measurement
65      * started
66      * @param upper The upper limit of this statistic
67      * @param lower The lower limit of this statistic
68      * @param name The name of the statistic
69      * @param unit The unit of measurement for this statistic
70      * @param desc A brief description of the statistic
71      * @param startTime Time in milliseconds at which the measurement was started
72      * @param sampleTime Time at which the last measurement was done.
73      * @param numberOfSamples number of samples at present
74      * @param runningTotal running total of sampled data at present
75      **/

76     public AverageRangeStatisticImpl(long curVal, long highMark, long lowMark,
77                                      long upper, long lower, String JavaDoc name,
78                                      String JavaDoc unit, String JavaDoc desc, long startTime,
79                                      long sampleTime, long numberOfSamples,
80                                      long runningTotal) {
81                                          
82         boundedRangeStatistic = new BoundedRangeStatisticImpl(curVal, highMark, lowMark,
83                                      upper, lower, name,
84                                      unit, desc, startTime,
85                                      sampleTime);
86                                          
87         this.numberOfSamples = numberOfSamples;
88         this.runningTotal = runningTotal;
89     }
90         
91     /**
92      * Constructs an immutable instance of AverageRangeStatisticImpl.
93      * @param stats a BoundedRangeStatisticImpl
94      * @param numberOfSamples number of samples at present
95      * @param runningTotal running total of sampled data at present
96      **/

97     public AverageRangeStatisticImpl(BoundedRangeStatisticImpl stats,
98                 long numberOfSamples, long runningTotal) {
99         boundedRangeStatistic = stats;
100         this.numberOfSamples = numberOfSamples;
101         this.runningTotal = runningTotal;
102     }
103    
104     public long getCurrent() {
105         return boundedRangeStatistic.getCurrent();
106     }
107
108     public String JavaDoc getDescription() {
109         return boundedRangeStatistic.getDescription();
110     }
111
112     public long getHighWaterMark() {
113         return boundedRangeStatistic.getHighWaterMark();
114     }
115
116     public long getLastSampleTime() {
117         return boundedRangeStatistic.getLastSampleTime();
118     }
119
120     public long getLowWaterMark() {
121         return boundedRangeStatistic.getLowWaterMark();
122     }
123 /*
124     public long getLowerBound() {
125         return boundedRangeStatistic.getLowerBound();
126     }
127      */

128
129     public String JavaDoc getName() {
130         return boundedRangeStatistic.getName();
131     }
132
133     public long getStartTime() {
134         return boundedRangeStatistic.getStartTime();
135     }
136
137     public String JavaDoc getUnit() {
138         return boundedRangeStatistic.getUnit();
139     }
140 /*
141     public long getUpperBound() {
142         return boundedRangeStatistic.getUpperBound();
143     }
144      */

145         
146     public long getAverage() {
147         if(numberOfSamples == 0) {
148             return -1;
149         } else {
150             return runningTotal / numberOfSamples;
151         }
152     }
153     /** This is a hack. This method allows us to internatinalize the descriptions.
154         See bug Id: 5045413
155     */

156     public void setDescription(final String JavaDoc desc) {
157         this.boundedRangeStatistic.setDescription(desc);
158     }
159     
160 }
161
Popular Tags