1 /***
2 *
3 * Copyright 2004 Protique Ltd
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * 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 **/
18 package org.codehaus.activemq.management;
19
20 import javax.management.j2ee.statistics.CountStatistic;
21
22 /***
23 * A count statistic implementation
24 *
25 * @version $Revision: 1.3 $
26 */
27 public class CountStatisticImpl extends StatisticImpl implements CountStatistic {
28
29 private long count;
30 private CountStatisticImpl parent;
31
32 public CountStatisticImpl(CountStatisticImpl parent, String name, String description) {
33 this(name, description);
34 this.parent = parent;
35 }
36
37 public CountStatisticImpl(String name, String description) {
38 this(name, "count", description);
39 }
40
41 public CountStatisticImpl(String name, String unit, String description) {
42 super(name, unit, description);
43 }
44
45 public void reset() {
46 super.reset();
47 count = 0;
48 }
49
50 public long getCount() {
51 return count;
52 }
53
54 public void increment() {
55 ++count;
56 updateSampleTime();
57 if (parent != null) {
58 parent.increment();
59 }
60 }
61
62 public void decrement() {
63 --count;
64 updateSampleTime();
65 if (parent != null) {
66 parent.decrement();
67 }
68 }
69
70 public CountStatisticImpl getParent() {
71 return parent;
72 }
73
74 public void setParent(CountStatisticImpl parent) {
75 this.parent = parent;
76 }
77
78 protected void appendFieldDescription(StringBuffer buffer) {
79 buffer.append(" count: ");
80 buffer.append(Long.toString(count));
81 super.appendFieldDescription(buffer);
82 }
83 }