KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > management > StatisticImpl


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.apache.activemq.management;
19
20 import javax.management.j2ee.statistics.Statistic JavaDoc;
21 /**
22  * Base class for a Statistic implementation
23  *
24  * @version $Revision: 1.2 $
25  */

26 public class StatisticImpl implements Statistic JavaDoc, Resettable {
27     private String JavaDoc name;
28     private String JavaDoc unit;
29     private String JavaDoc description;
30     private long startTime;
31     private long lastSampleTime;
32     protected boolean enabled= false;
33
34     public StatisticImpl(String JavaDoc name, String JavaDoc unit, String JavaDoc description) {
35         this.name = name;
36         this.unit = unit;
37         this.description = description;
38         startTime = System.currentTimeMillis();
39         lastSampleTime = startTime;
40     }
41
42     public synchronized void reset() {
43         startTime = System.currentTimeMillis();
44         lastSampleTime = startTime;
45     }
46
47     protected synchronized void updateSampleTime() {
48         lastSampleTime = System.currentTimeMillis();
49     }
50
51     public synchronized String JavaDoc toString() {
52         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
53         buffer.append(name);
54         buffer.append("{");
55         appendFieldDescription(buffer);
56         buffer.append(" }");
57         return buffer.toString();
58     }
59
60     public String JavaDoc getName() {
61         return name;
62     }
63
64     public String JavaDoc getUnit() {
65         return unit;
66     }
67
68     public String JavaDoc getDescription() {
69         return description;
70     }
71
72     public synchronized long getStartTime() {
73         return startTime;
74     }
75
76     public synchronized long getLastSampleTime() {
77         return lastSampleTime;
78     }
79     
80     /**
81      * @return the enabled
82      */

83     public boolean isEnabled(){
84         return this.enabled;
85     }
86
87     /**
88      * @param enabled the enabled to set
89      */

90     public void setEnabled(boolean enabled){
91         this.enabled=enabled;
92     }
93
94     protected synchronized void appendFieldDescription(StringBuffer JavaDoc buffer) {
95         buffer.append(" unit: ");
96         buffer.append(unit);
97         buffer.append(" startTime: ");
98         //buffer.append(new Date(startTime));
99
buffer.append(startTime);
100         buffer.append(" lastSampleTime: ");
101         //buffer.append(new Date(lastSampleTime));
102
buffer.append(lastSampleTime);
103         buffer.append(" description: ");
104         buffer.append(description);
105     }
106
107     
108    
109 }
110
Popular Tags