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.Statistic;
025: import java.io.Serializable;
026:
027: /**
028: * JBoss Implementation of the base Model for a Statistic Information
029: *
030: * @author Marc Fleury
031: * @author Scott.Stark@jboss.org
032: * @version $Revision: 57197 $
033: */
034: public abstract class StatisticImpl implements Statistic, Serializable {
035: // Constants -----------------------------------------------------
036:
037: /** @since 4.0.2 */
038: private static final long serialVersionUID = -3427364348020739916L;
039:
040: // Attributes ----------------------------------------------------
041: protected String name;
042: protected String units;
043: protected String description;
044: protected long startTime;
045: protected long lastSampleTime;
046:
047: // Static --------------------------------------------------------
048:
049: // Constructors --------------------------------------------------
050:
051: /**
052: * Create a named Statistic.
053: *
054: * @param name Name of the statistic
055: * @param units Unit description used in this statistic
056: * @param description Human description of the statistic
057: */
058: public StatisticImpl(String name, String units, String description) {
059: this .name = name;
060: this .units = units;
061: this .description = description;
062: this .startTime = System.currentTimeMillis();
063: }
064:
065: // Public --------------------------------------------------------
066:
067: // javax.management.j2ee.Statistics implementation ---------------
068:
069: public String getName() {
070: return name;
071: }
072:
073: public String getUnit() {
074: return units;
075: }
076:
077: public String getDescription() {
078: return description;
079: }
080:
081: public long getStartTime() {
082: return startTime;
083: }
084:
085: public long getLastSampleTime() {
086: return lastSampleTime;
087: }
088:
089: /**
090: * Reset the lastSampleTime and startTime to the current time
091: */
092: public void reset() {
093: startTime = System.currentTimeMillis();
094: lastSampleTime = startTime;
095: }
096:
097: /**
098: * Update the lastSampleTime and startTime on first call
099: */
100: public void set() {
101: lastSampleTime = System.currentTimeMillis();
102: }
103:
104: public String toString() {
105: StringBuffer tmp = new StringBuffer(name);
106: tmp.append('(');
107: tmp.append("description: ");
108: tmp.append(description);
109: tmp.append(", units: ");
110: tmp.append(units);
111: tmp.append(", startTime: ");
112: tmp.append(startTime);
113: tmp.append(", lastSampleTime: ");
114: tmp.append(lastSampleTime);
115: tmp.append(')');
116: return tmp.toString();
117: }
118: }
|