001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.management.j2ee.statistics;
023:
024: import javax.management.j2ee.statistics.RangeStatistic;
025:
026: /**
027: * This class is the JBoss specific Range Statistics class allowing
028: * just to increase and resetStats the instance.
029: *
030: * @author <a href="mailto:mclaugs@comcast.net">Scott McLaughlin</a>
031: * @version $Revision: 57197 $
032: */
033: public class RangeStatisticImpl extends StatisticImpl implements
034: RangeStatistic {
035: // -------------------------------------------------------------------------
036: // Constants
037: // -------------------------------------------------------------------------
038:
039: /** @since 4.0.2 */
040: private static final long serialVersionUID = -7893492477598566197L;
041:
042: // -------------------------------------------------------------------------
043: // Members
044: // -------------------------------------------------------------------------
045:
046: protected long current;
047: protected long highWaterMark;
048: protected long lowWaterMark;
049:
050: // -------------------------------------------------------------------------
051: // Constructors
052: // -------------------------------------------------------------------------
053:
054: /**
055: * Default (no-args) constructor
056: */
057: public RangeStatisticImpl(String pName, String pUnit,
058: String pDescription) {
059: super (pName, pUnit, pDescription);
060: }
061:
062: // -------------------------------------------------------------------------
063: // RangeStatistic Implementation
064: // -------------------------------------------------------------------------
065:
066: /**
067: * @return The value of Current
068: */
069: public long getCurrent() {
070: return current;
071: }
072:
073: /**
074: * @return The value of HighWaterMark
075: */
076: public long getHighWaterMark() {
077: return highWaterMark;
078: }
079:
080: /**
081: * @return The value of LowWaterMark
082: */
083: public long getLowWaterMark() {
084: return lowWaterMark;
085: }
086:
087: /**
088: * @return Debug Information about this Instance
089: */
090: public String toString() {
091: StringBuffer tmp = new StringBuffer();
092: tmp.append('[');
093: tmp.append("low: ");
094: tmp.append(lowWaterMark);
095: tmp.append(", high: ");
096: tmp.append(highWaterMark);
097: tmp.append(", current: ");
098: tmp.append(current);
099: tmp.append(']');
100: tmp.append(super .toString());
101: return tmp.toString();
102: }
103:
104: // -------------------------------------------------------------------------
105: // Methods
106: // -------------------------------------------------------------------------
107:
108: /**
109: * Adds a hit to this counter
110: */
111: public void add() {
112: set(++current);
113: }
114:
115: /**
116: * Removes a hit to this counter
117: */
118: public void remove() {
119: if (current > 0) {
120: set(--current);
121: }
122: }
123:
124: /**
125: * Resets the statistics to the initial values
126: */
127: public void reset() {
128: current = 0;
129: highWaterMark = 0;
130: lowWaterMark = 0;
131: super .reset();
132: }
133:
134: public void set(long current) {
135: this.current = current;
136: if (current < lowWaterMark) {
137: lowWaterMark = current;
138: }
139: if (current > highWaterMark) {
140: highWaterMark = current;
141: }
142: super.set();
143: }
144: }
|