1 23 24 29 30 package com.sun.enterprise.server.stats; 31 import javax.management.j2ee.statistics.Statistic ; 32 import javax.management.j2ee.statistics.BoundedRangeStatistic ; 33 import javax.management.j2ee.statistics.CountStatistic ; 34 import javax.management.j2ee.statistics.JVMStats ; 35 import com.sun.enterprise.admin.monitor.stats.GenericStatsImpl; 36 import com.sun.enterprise.admin.monitor.stats.CountStatisticImpl; 37 import com.sun.enterprise.admin.monitor.stats.BoundedRangeStatisticImpl; 38 import com.sun.enterprise.admin.monitor.stats.MutableStatistic; 39 import com.sun.enterprise.admin.monitor.stats.MutableCountStatistic; 40 import com.sun.enterprise.admin.monitor.stats.MutableCountStatisticImpl; 41 import com.sun.enterprise.admin.monitor.stats.MutableBoundedRangeStatisticImpl; 42 import com.sun.enterprise.util.i18n.StringManager; 43 44 45 50 51 public class JVMStatsImpl implements JVMStats { 52 53 private final long initTime; 54 private GenericStatsImpl baseStatsImpl; 55 private MutableCountStatistic uptime; 56 private MutableBoundedRangeStatisticImpl heapSize; 57 private static final String STATS_INTERFACE_NAME = 58 "javax.management.j2ee.statistics.JVMStats"; 59 private static StringManager sm = 60 StringManager.getManager(JVMStatsImpl.class); 61 62 69 public JVMStatsImpl() { 70 71 initTime = System.currentTimeMillis(); 72 try { 73 baseStatsImpl = new GenericStatsImpl(STATS_INTERFACE_NAME, this); 74 }catch(ClassNotFoundException cnfe){ 75 } 77 78 CountStatistic u = new CountStatisticImpl( 80 sm.getString("jvmstats.jvm_uptime"), 81 sm.getString("jvmstats.milli_seconds"), 82 sm.getString("jvmstats.jvm_uptime_desc") ); 83 uptime = new MutableCountStatisticImpl(u); 84 85 86 long upper = Runtime.getRuntime().maxMemory(); 88 BoundedRangeStatistic h = new BoundedRangeStatisticImpl( 89 sm.getString("jvmstats.jvm_heapsize"), 90 sm.getString("jvmstats.bytes"), 91 sm.getString("jvmstats.jvm_heapsize_desc"), 92 0, upper, 0); 93 94 heapSize = new MutableBoundedRangeStatisticImpl(h); 95 } 96 97 101 public BoundedRangeStatistic getHeapSize() { 102 long heap = Runtime.getRuntime().totalMemory(); 103 heapSize.setCount(heap); 104 return (BoundedRangeStatistic ) heapSize.unmodifiableView(); 105 } 106 107 111 public CountStatistic getUpTime() { 112 long curTime = System.currentTimeMillis(); 113 long upTime = curTime - initTime; 114 uptime.setCount(upTime); 115 return (CountStatistic ) uptime.unmodifiableView(); 116 } 117 118 123 public Statistic [] getStatistics() { 124 return baseStatsImpl.getStatistics(); 125 } 126 127 131 public Statistic getStatistic(String str) { 132 return baseStatsImpl.getStatistic(str); 133 } 134 135 140 public String [] getStatisticNames() { 141 return baseStatsImpl.getStatisticNames(); 142 } 143 144 } 145 | Popular Tags |