KickJava   Java API By Example, From Geeks To Geeks.

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


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.RangeStatistic JavaDoc;
25
26 /**
27  * This class is the JBoss specific Range Statistics class allowing
28  * just to increase and resetStats the instance.
29  *
30  * @author <a HREF="mailto:mclaugs@comcast.net">Scott McLaughlin</a>
31  * @version $Revision: 37459 $
32  */

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

41    /** @since 4.0.2 */
42    private static final long serialVersionUID = -7893492477598566197L;
43       
44    // -------------------------------------------------------------------------
45
// Members
46
// -------------------------------------------------------------------------
47

48    protected long current;
49    protected long highWaterMark;
50    protected long lowWaterMark;
51
52    // -------------------------------------------------------------------------
53
// Constructors
54
// -------------------------------------------------------------------------
55

56    /**
57     * Default (no-args) constructor
58     */

59    public RangeStatisticImpl(String JavaDoc pName, String JavaDoc pUnit, String JavaDoc pDescription)
60    {
61       super(pName, pUnit, pDescription);
62    }
63
64    // -------------------------------------------------------------------------
65
// RangeStatistic Implementation
66
// -------------------------------------------------------------------------
67

68    /**
69     * @return The value of Current
70     */

71    public long getCurrent()
72    {
73       return current;
74    }
75
76    /**
77     * @return The value of HighWaterMark
78     */

79    public long getHighWaterMark()
80    {
81       return highWaterMark;
82    }
83
84    /**
85     * @return The value of LowWaterMark
86     */

87    public long getLowWaterMark()
88    {
89       return lowWaterMark;
90    }
91
92    /**
93     * @return Debug Information about this Instance
94     */

95    public String JavaDoc toString()
96    {
97       StringBuffer JavaDoc tmp = new StringBuffer JavaDoc();
98       tmp.append('[');
99       tmp.append("low: ");
100       tmp.append(lowWaterMark);
101       tmp.append(", high: ");
102       tmp.append(highWaterMark);
103       tmp.append(", current: ");
104       tmp.append(current);
105       tmp.append(']');
106       tmp.append(super.toString());
107       return tmp.toString();
108    }
109
110    // -------------------------------------------------------------------------
111
// Methods
112
// -------------------------------------------------------------------------
113

114    /**
115     * Adds a hit to this counter
116     */

117    public void add()
118    {
119       set(++current);
120    }
121
122    /**
123     * Removes a hit to this counter
124     */

125    public void remove()
126    {
127       if (current > 0)
128       {
129          set(--current);
130       }
131    }
132
133    /**
134     * Resets the statistics to the initial values
135     */

136    public void reset()
137    {
138       current = 0;
139       highWaterMark = 0;
140       lowWaterMark = 0;
141       super.reset();
142    }
143
144    public void set(long current)
145    {
146       this.current = current;
147       if (current < lowWaterMark)
148       {
149          lowWaterMark = current;
150       }
151       if (current > highWaterMark)
152       {
153          highWaterMark = current;
154       }
155       super.set();
156    }
157 }
158
Popular Tags