KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > management > j2ee > statistics > CountStatisticImpl


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.management.j2ee.statistics;
23
24 import javax.management.j2ee.statistics.CountStatistic JavaDoc;
25
26 /**
27  * This class is the JBoss specific Counter Statistics class
28  *
29  * @author <a HREF="mailto:marc.fleury@jboss.org">Marc Fleury</a>
30  * @author <a HREF="mailto:andreas@jboss.com">Andreas Schaefer</a>
31  * @version $Revision: 37459 $
32  */

33 public class CountStatisticImpl
34         extends StatisticImpl
35         implements CountStatistic JavaDoc
36 {
37    // -------------------------------------------------------------------------
38
// Constants
39
// -------------------------------------------------------------------------
40

41    /** @since 4.0.2 */
42    private static final long serialVersionUID = 8087661344599547469L;
43    
44    // -------------------------------------------------------------------------
45
// Members
46
// -------------------------------------------------------------------------
47
protected long count;
48
49    // -------------------------------------------------------------------------
50
// Constructors
51
// -------------------------------------------------------------------------
52

53    /**
54     * Create a CountStatistic
55     *
56     * @param name the name of the state
57     * @param units the units of the stat
58     * @param description a description of the stat
59     */

60    public CountStatisticImpl(String JavaDoc name, String JavaDoc units, String JavaDoc description)
61    {
62       super(name, units, description);
63    }
64
65    // -------------------------------------------------------------------------
66
// CountStatistic Implementation
67
// -------------------------------------------------------------------------
68

69    /**
70     * @return The value of Count
71     */

72    public long getCount()
73    {
74       return count;
75    }
76
77    /**
78     * @return Debug Information about this Instance
79     */

80    public String JavaDoc toString()
81    {
82       return "[ " + getCount() + ":" + super.toString() + " ]";
83    }
84
85    // -------------------------------------------------------------------------
86
// Methods
87
// -------------------------------------------------------------------------
88

89    /**
90     * Adds a hit to this counter
91     */

92    public void add()
93    {
94       set(++count);
95    }
96
97    /**
98     * Removes a hit to this counter
99     */

100    public void remove()
101    {
102       if (count > 0)
103       {
104          set(--count);
105       }
106    }
107
108    /**
109     * Resets the statistics to the initial values
110     */

111    public void reset()
112    {
113       count = 0;
114       super.reset();
115    }
116
117    /**
118     * Set the current value of the count
119     *
120     * @param count the new count
121     */

122    public void set(long count)
123    {
124       this.count = count;
125       super.set();
126    }
127 }
128
Popular Tags