KickJava   Java API By Example, From Geeks To Geeks.

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


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.Statistic JavaDoc;
25 import java.io.Serializable JavaDoc;
26
27 /**
28  * JBoss Implementation of the base Model for a Statistic Information
29  *
30  * @author Marc Fleury
31  * @author Scott.Stark@jboss.org
32  * @version $Revision: 37459 $
33  */

34 public abstract class StatisticImpl
35         implements Statistic JavaDoc, Serializable JavaDoc
36 {
37    // Constants -----------------------------------------------------
38

39    /** @since 4.0.2 */
40    private static final long serialVersionUID = -3427364348020739916L;
41    
42    // Attributes ----------------------------------------------------
43
protected String JavaDoc name;
44    protected String JavaDoc units;
45    protected String JavaDoc description;
46    protected long startTime;
47    protected long lastSampleTime;
48
49    // Static --------------------------------------------------------
50

51    // Constructors --------------------------------------------------
52

53    /**
54     * Create a named Statistic.
55     *
56     * @param name Name of the statistic
57     * @param units Unit description used in this statistic
58     * @param description Human description of the statistic
59     */

60    public StatisticImpl(String JavaDoc name, String JavaDoc units, String JavaDoc description)
61    {
62       this.name = name;
63       this.units = units;
64       this.description = description;
65       this.startTime = System.currentTimeMillis();
66    }
67
68    // Public --------------------------------------------------------
69

70    // javax.management.j2ee.Statistics implementation ---------------
71

72    public String JavaDoc getName()
73    {
74       return name;
75    }
76
77    public String JavaDoc getUnit()
78    {
79       return units;
80    }
81
82    public String JavaDoc getDescription()
83    {
84       return description;
85    }
86
87    public long getStartTime()
88    {
89       return startTime;
90    }
91
92    public long getLastSampleTime()
93    {
94       return lastSampleTime;
95    }
96
97    /**
98     * Reset the lastSampleTime and startTime to the current time
99     */

100    public void reset()
101    {
102       startTime = System.currentTimeMillis();
103       lastSampleTime = startTime;
104    }
105
106    /**
107     * Update the lastSampleTime and startTime on first call
108     */

109    public void set()
110    {
111       lastSampleTime = System.currentTimeMillis();
112    }
113
114    public String JavaDoc toString()
115    {
116       StringBuffer JavaDoc tmp = new StringBuffer JavaDoc(name);
117       tmp.append('(');
118       tmp.append("description: ");
119       tmp.append(description);
120       tmp.append(", units: ");
121       tmp.append(units);
122       tmp.append(", startTime: ");
123       tmp.append(startTime);
124       tmp.append(", lastSampleTime: ");
125       tmp.append(lastSampleTime);
126       tmp.append(')');
127       return tmp.toString();
128    }
129 }
130
Popular Tags