KickJava   Java API By Example, From Geeks To Geeks.

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


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.BoundedRangeStatistic JavaDoc;
25 import javax.management.j2ee.statistics.CountStatistic JavaDoc;
26 import javax.management.j2ee.statistics.JVMStats JavaDoc;
27
28 /**
29  * The JSR77.6.32 JMVStats implementation
30  *
31  * @author Scott.Stark@jboss.org
32  * @version $Revision: 37459 $
33  */

34 public class JVMStatsImpl extends StatsBase
35         implements JVMStats JavaDoc
36 {
37    // Constants -----------------------------------------------------
38

39    /** @since 4.0.2 */
40    private static final long serialVersionUID = -7842397217562728796L;
41    
42    // Constructors --------------------------------------------------
43

44    public JVMStatsImpl()
45    {
46       this(new CountStatisticImpl("UpTime", "MILLISECOND", "Time the VM has been running"),
47               new BoundedRangeStatisticImpl("HeapSize", "Bytes", "Size of the VM's heap", 0, 0));
48    }
49
50    public JVMStatsImpl(CountStatistic JavaDoc upTime, BoundedRangeStatistic JavaDoc heapSize)
51    {
52       addStatistic("UpTime", upTime);
53       addStatistic("HeapSize", heapSize);
54    }
55
56 // Begin javax.management.j2ee.statistics.JVMStats interface methods
57
public CountStatistic JavaDoc getUpTime()
58    {
59       CountStatisticImpl upTime = (CountStatisticImpl) getStatistic("UpTime");
60       long now = System.currentTimeMillis();
61       long elapsed = now - upTime.getStartTime();
62       upTime.set(elapsed);
63       return upTime;
64    }
65
66    public BoundedRangeStatistic JavaDoc getHeapSize()
67    {
68       BoundedRangeStatisticImpl heapSize = (BoundedRangeStatisticImpl) getStatistic("HeapSize");
69       long totalMemory = Runtime.getRuntime().totalMemory();
70       heapSize.set(totalMemory);
71       return heapSize;
72    }
73 // End javax.management.j2ee.statistics.JVMStats interface methods
74
}
75
Popular Tags