1 23 24 package com.sun.enterprise.admin.monitor.stats.spi; 25 import java.lang.management.ManagementFactory ; 26 import java.lang.management.MemoryMXBean ; 27 import java.lang.management.MemoryUsage ; 28 import javax.management.ObjectName ; 29 import javax.management.MBeanServerFactory ; 30 import javax.management.MBeanServer ; 31 import javax.management.j2ee.statistics.Statistic ; 32 import javax.management.j2ee.statistics.CountStatistic ; 33 import com.sun.enterprise.admin.monitor.stats.MutableCountStatistic; 34 import com.sun.enterprise.admin.monitor.stats.MutableCountStatisticImpl; 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.StatisticImpl; 38 import com.sun.enterprise.admin.monitor.stats.JVMMemoryStats; 39 import com.sun.enterprise.util.i18n.StringManager; 40 41 public class JVMMemoryStatsImpl implements JVMMemoryStats { 42 43 private GenericStatsImpl baseStatsImpl; 44 private static final String STATS_INTERFACE_NAME = 45 "com.sun.enterprise.admin.monitor.stats.JVMMemoryStats"; 46 private MutableCountStatistic initHeapSize; 47 private MutableCountStatistic usedHeapSize; 48 private MutableCountStatistic maxHeapSize; 49 private MutableCountStatistic commitHeapSize; 50 private MutableCountStatistic initNonHeapSize; 51 private MutableCountStatistic maxNonHeapSize; 52 private MutableCountStatistic usedNonHeapSize; 53 private MutableCountStatistic commitNonHeapSize; 54 private MutableCountStatistic objPendingCount; 55 private MemoryUsage heapUsage; 56 private MemoryUsage nonheapUsage; 57 private MemoryMXBean bean; 58 private static final String BYTE_UNITS = "monitor.stats.byte_units"; 59 private static final StringManager localStrMgr = 60 StringManager.getManager(JVMMemoryStatsImpl.class); 61 62 63 64 public JVMMemoryStatsImpl() { 65 66 try { 67 baseStatsImpl = new GenericStatsImpl(STATS_INTERFACE_NAME, this); 68 } catch(Exception e) { 69 70 } 71 bean = ManagementFactory.getMemoryMXBean(); 72 heapUsage = bean.getHeapMemoryUsage(); 73 nonheapUsage = bean.getNonHeapMemoryUsage(); 74 75 initializeStatistics(); 77 } 78 79 80 private void initializeStatistics() { 81 String bytes_str = localStrMgr.getString(BYTE_UNITS); 82 83 CountStatistic c = new CountStatisticImpl( 85 localStrMgr.getString("monitor.stats.initial_heap_size"), bytes_str, 86 localStrMgr.getString("monitor.stats.initial_heap_size_desc")); 87 initHeapSize = new MutableCountStatisticImpl(c); 88 89 c = new CountStatisticImpl( 91 localStrMgr.getString("monitor.stats.max_heap_size"), bytes_str, 92 localStrMgr.getString("monitor.stats.max_heap_size_desc")); 93 maxHeapSize = new MutableCountStatisticImpl(c); 94 95 c = new CountStatisticImpl( 97 localStrMgr.getString("monitor.stats.used_heap_size"), bytes_str, 98 localStrMgr.getString("monitor.stats.used_heap_size_desc")); 99 usedHeapSize = new MutableCountStatisticImpl(c); 100 101 c = new CountStatisticImpl( 103 localStrMgr.getString("monitor.stats.committed_heap_size"), bytes_str, 104 localStrMgr.getString("monitor.stats.committed_heap_size_desc")); 105 commitHeapSize = new MutableCountStatisticImpl(c); 106 107 c = new CountStatisticImpl( 109 localStrMgr.getString("monitor.stats.initial_non_heap_size"), bytes_str, 110 localStrMgr.getString("monitor.stats.initial_non_heap_size_desc")); 111 initNonHeapSize = new MutableCountStatisticImpl(c); 112 113 c = new CountStatisticImpl( 115 localStrMgr.getString("monitor.stats.max_non_heap_size"),bytes_str, 116 localStrMgr.getString("monitor.stats.max_non_heap_size_desc")); 117 maxNonHeapSize = new MutableCountStatisticImpl(c); 118 119 c = new CountStatisticImpl( 121 localStrMgr.getString("monitor.stats.used_non_heap_size") ,bytes_str, 122 localStrMgr.getString("monitor.stats.used_non_heap_size_desc")); 123 usedNonHeapSize = new MutableCountStatisticImpl(c); 124 125 c = new CountStatisticImpl( 127 localStrMgr.getString("monitor.stats.committed_non_heap_size"), 128 bytes_str, 129 localStrMgr.getString("monitor.stats.committed_non_heap_size_desc")); 130 commitNonHeapSize = new MutableCountStatisticImpl(c); 131 132 c = new CountStatisticImpl( 134 localStrMgr.getString("monitor.stats.objs_pending_serialization"), 135 StatisticImpl.DEFAULT_UNIT, 136 localStrMgr.getString("monitor.stats.objs_pending_serialization_desc")); 137 objPendingCount = new MutableCountStatisticImpl(c); 138 } 139 140 141 public CountStatistic getCommittedHeapSize() { 142 commitHeapSize.setCount(heapUsage.getCommitted()); 143 return (CountStatistic )commitHeapSize.unmodifiableView(); 144 } 145 146 public CountStatistic getCommittedNonHeapSize() { 147 commitNonHeapSize.setCount(nonheapUsage.getCommitted()); 148 return (CountStatistic )commitNonHeapSize.unmodifiableView(); 149 } 150 151 public CountStatistic getInitHeapSize() { 152 initHeapSize.setCount(heapUsage.getInit()); 153 return (CountStatistic )initHeapSize.unmodifiableView(); 154 } 155 156 public CountStatistic getInitNonHeapSize() { 157 initNonHeapSize.setCount(nonheapUsage.getCommitted()); 158 return (CountStatistic )initNonHeapSize.unmodifiableView(); 159 } 160 161 public CountStatistic getMaxHeapSize() { 162 maxHeapSize.setCount(heapUsage.getMax()); 163 return (CountStatistic )maxHeapSize.unmodifiableView(); 164 } 165 166 public CountStatistic getMaxNonHeapSize() { 167 maxNonHeapSize.setCount(nonheapUsage.getInit()); 168 return (CountStatistic )maxNonHeapSize.unmodifiableView(); 169 } 170 171 public CountStatistic getObjectPendingFinalizationCount() { 172 objPendingCount.setCount(bean.getObjectPendingFinalizationCount()); 173 return (CountStatistic )objPendingCount.unmodifiableView(); 174 } 175 176 public CountStatistic getUsedHeapSize() { 177 usedHeapSize.setCount(heapUsage.getUsed()); 178 return (CountStatistic )usedHeapSize.unmodifiableView(); 179 } 180 181 public CountStatistic getUsedNonHeapSize() { 182 usedNonHeapSize.setCount(nonheapUsage.getUsed()); 183 return (CountStatistic )usedNonHeapSize.unmodifiableView(); 184 } 185 186 187 192 public Statistic [] getStatistics() { 193 return baseStatsImpl.getStatistics(); 194 } 195 196 200 public Statistic getStatistic(String str) { 201 return baseStatsImpl.getStatistic(str); 202 } 203 204 209 public String [] getStatisticNames() { 210 return baseStatsImpl.getStatisticNames(); 211 } 212 } 213 | Popular Tags |