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.CountStatistic;
025:
026: /**
027: * This class is the JBoss specific Counter Statistics class
028: *
029: * @author <a href="mailto:marc.fleury@jboss.org">Marc Fleury</a>
030: * @author <a href="mailto:andreas@jboss.com">Andreas Schaefer</a>
031: * @version $Revision: 57197 $
032: */
033: public class CountStatisticImpl extends StatisticImpl implements
034: CountStatistic {
035: // -------------------------------------------------------------------------
036: // Constants
037: // -------------------------------------------------------------------------
038:
039: /** @since 4.0.2 */
040: private static final long serialVersionUID = 8087661344599547469L;
041:
042: // -------------------------------------------------------------------------
043: // Members
044: // -------------------------------------------------------------------------
045: protected long count;
046:
047: // -------------------------------------------------------------------------
048: // Constructors
049: // -------------------------------------------------------------------------
050:
051: /**
052: * Create a CountStatistic
053: *
054: * @param name the name of the state
055: * @param units the units of the stat
056: * @param description a description of the stat
057: */
058: public CountStatisticImpl(String name, String units,
059: String description) {
060: super (name, units, description);
061: }
062:
063: // -------------------------------------------------------------------------
064: // CountStatistic Implementation
065: // -------------------------------------------------------------------------
066:
067: /**
068: * @return The value of Count
069: */
070: public long getCount() {
071: return count;
072: }
073:
074: /**
075: * @return Debug Information about this Instance
076: */
077: public String toString() {
078: return "[ " + getCount() + ":" + super .toString() + " ]";
079: }
080:
081: // -------------------------------------------------------------------------
082: // Methods
083: // -------------------------------------------------------------------------
084:
085: /**
086: * Adds a hit to this counter
087: */
088: public void add() {
089: set(++count);
090: }
091:
092: /**
093: * Removes a hit to this counter
094: */
095: public void remove() {
096: if (count > 0) {
097: set(--count);
098: }
099: }
100:
101: /**
102: * Resets the statistics to the initial values
103: */
104: public void reset() {
105: count = 0;
106: super .reset();
107: }
108:
109: /**
110: * Set the current value of the count
111: *
112: * @param count the new count
113: */
114: public void set(long count) {
115: this.count = count;
116: super.set();
117: }
118: }
|