01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.servicemix.jbi.monitoring.stats;
18:
19: import javax.management.j2ee.statistics.Statistic;
20:
21: /**
22: * Base class for a Statistic implementation
23: *
24: * @version $Revision: 482795 $
25: */
26: public class StatisticImpl implements Statistic, Resettable {
27: private String name;
28: private String unit;
29: private String description;
30: private long startTime;
31: private long lastSampleTime;
32:
33: public StatisticImpl(String name, String unit, String description) {
34: this .name = name;
35: this .unit = unit;
36: this .description = description;
37: startTime = System.currentTimeMillis();
38: lastSampleTime = startTime;
39: }
40:
41: public synchronized void reset() {
42: startTime = System.currentTimeMillis();
43: lastSampleTime = startTime;
44: }
45:
46: protected synchronized void updateSampleTime() {
47: lastSampleTime = System.currentTimeMillis();
48: }
49:
50: public synchronized String toString() {
51: StringBuffer buffer = new StringBuffer();
52: buffer.append(name);
53: buffer.append("{");
54: appendFieldDescription(buffer);
55: buffer.append(" }");
56: return buffer.toString();
57: }
58:
59: public String getName() {
60: return name;
61: }
62:
63: public String getUnit() {
64: return unit;
65: }
66:
67: public String getDescription() {
68: return description;
69: }
70:
71: public synchronized long getStartTime() {
72: return startTime;
73: }
74:
75: public synchronized long getLastSampleTime() {
76: return lastSampleTime;
77: }
78:
79: protected synchronized void appendFieldDescription(
80: StringBuffer buffer) {
81: buffer.append(" unit: ");
82: buffer.append(unit);
83: buffer.append(" startTime: ");
84: //buffer.append(new Date(startTime));
85: buffer.append(startTime);
86: buffer.append(" lastSampleTime: ");
87: //buffer.append(new Date(lastSampleTime));
88: buffer.append(lastSampleTime);
89: buffer.append(" description: ");
90: buffer.append(description);
91: }
92: }
|