1 22 package org.jboss.management.j2ee.statistics; 23 24 import javax.management.j2ee.statistics.BoundedRangeStatistic ; 25 import javax.management.j2ee.statistics.CountStatistic ; 26 import javax.management.j2ee.statistics.JVMStats ; 27 28 34 public class JVMStatsImpl extends StatsBase 35 implements JVMStats 36 { 37 39 40 private static final long serialVersionUID = -7842397217562728796L; 41 42 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 upTime, BoundedRangeStatistic heapSize) 51 { 52 addStatistic("UpTime", upTime); 53 addStatistic("HeapSize", heapSize); 54 } 55 56 public CountStatistic 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 getHeapSize() 67 { 68 BoundedRangeStatisticImpl heapSize = (BoundedRangeStatisticImpl) getStatistic("HeapSize"); 69 long totalMemory = Runtime.getRuntime().totalMemory(); 70 heapSize.set(totalMemory); 71 return heapSize; 72 } 73 } 75 | Popular Tags |