1 23 24 package com.sun.enterprise.admin.monitor.stats.spi; 25 import java.util.ArrayList ; 26 import java.lang.management.ManagementFactory ; 27 import java.lang.management.RuntimeMXBean ; 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.StringStatistic; 34 import com.sun.enterprise.admin.monitor.stats.JVMRuntimeStats; 35 import com.sun.enterprise.admin.monitor.stats.MutableCountStatistic; 36 import com.sun.enterprise.admin.monitor.stats.MutableCountStatisticImpl; 37 import com.sun.enterprise.admin.monitor.stats.GenericStatsImpl; 38 import com.sun.enterprise.admin.monitor.stats.CountStatisticImpl; 39 import com.sun.enterprise.admin.monitor.stats.StringStatisticImpl; 40 import com.sun.enterprise.util.i18n.StringManager; 41 42 public class JVMRuntimeStatsImpl implements JVMRuntimeStats { 43 44 private GenericStatsImpl baseStatsImpl; 45 private static final String STATS_INTERFACE_NAME = 46 "com.sun.enterprise.admin.monitor.stats.JVMRuntimeStats"; 47 private MBeanServer server; 48 private MutableCountStatistic upTime; 49 private StringStatistic name; 50 private RuntimeMXBean bean; 51 final long initTime; 52 private static final StringManager localStrMgr = 53 StringManager.getManager(JVMRuntimeStatsImpl.class); 54 55 56 57 public JVMRuntimeStatsImpl () { 58 59 initTime = System.currentTimeMillis (); 60 try { 61 baseStatsImpl = new GenericStatsImpl(STATS_INTERFACE_NAME, this); 62 } catch(Exception e) { 63 64 } 65 bean = ManagementFactory.getRuntimeMXBean(); 68 69 initializeStatistics(); 71 72 } 73 74 public StringStatistic getName() { 75 76 String name = bean.getName(); 77 78 return new StringStatisticImpl(name, 79 localStrMgr.getString("monitor.stats.name_string"), 80 localStrMgr.getString("monitor.stats.string_units"), 81 localStrMgr.getString("monitor.stats.name_of_vm"), 82 initTime, 83 System.currentTimeMillis()); 84 85 } 86 87 public StringStatistic getBootClasspath () { 88 89 String bclasspath = bean.getBootClassPath(); 90 91 return new StringStatisticImpl(bclasspath, 92 localStrMgr.getString("monitor.stats.boot_class_path_string"), 93 localStrMgr.getString("monitor.stats.string_units"), 94 localStrMgr.getString("monitor.stats.name_of_boot_class_path"), 95 initTime, 96 System.currentTimeMillis()); 97 } 98 99 public StringStatistic getClassPath () { 100 101 String cpath = bean.getClassPath(); 102 103 return new StringStatisticImpl(cpath, 104 localStrMgr.getString("monitor.stats.class_path_string"), 105 localStrMgr.getString("monitor.stats.string_units"), 106 localStrMgr.getString("monitor.stats.name_of_class_path"), 107 initTime, 108 System.currentTimeMillis()); 109 } 110 111 public StringStatistic getInputArguments () { 112 113 ArrayList inputArgs = new ArrayList (); 114 inputArgs.addAll(bean.getInputArguments()); 115 116 return new StringStatisticImpl(inputArgs.toString (), 117 localStrMgr.getString("monitor.stats.input_args_string"), 118 localStrMgr.getString("monitor.stats.string_units"), 119 localStrMgr.getString("monitor.stats.name_of_input_args"), 120 initTime, 121 System.currentTimeMillis()); 122 } 123 124 public StringStatistic getLibraryPath () { 125 126 String libpath = bean.getLibraryPath(); 127 128 return new StringStatisticImpl(libpath, 129 localStrMgr.getString("monitor.stats.lib_path_string"), 130 localStrMgr.getString("monitor.stats.string_units"), 131 localStrMgr.getString("monitor.stats.name_of_lib_path"), 132 initTime, 133 System.currentTimeMillis()); 134 } 135 136 public StringStatistic getManagementSpecVersion () { 137 138 String ver = bean.getManagementSpecVersion(); 139 140 return new StringStatisticImpl(ver, 141 localStrMgr.getString("monitor.stats.lib_mgmt_spec_ver"), 142 localStrMgr.getString("monitor.stats.string_units"), 143 localStrMgr.getString("monitor.stats.name_of_mgmt_spec_ver"), 144 initTime, 145 System.currentTimeMillis()); 146 } 147 148 public StringStatistic getSpecName () { 149 150 String specname = bean.getSpecName(); 151 152 return new StringStatisticImpl(specname, 153 localStrMgr.getString("monitor.stats.spec_name"), 154 localStrMgr.getString("monitor.stats.string_units"), 155 localStrMgr.getString("monitor.stats.name_of_spec"), 156 initTime, 157 System.currentTimeMillis()); 158 } 159 160 public StringStatistic getSpecVendor () { 161 162 String specvendor = bean.getSpecVendor(); 163 164 return new StringStatisticImpl(specvendor, 165 localStrMgr.getString("monitor.stats.spec_vendor"), 166 localStrMgr.getString("monitor.stats.string_units"), 167 localStrMgr.getString("monitor.stats.name_of_spec_vendor"), 168 initTime, 169 System.currentTimeMillis()); 170 } 171 172 public StringStatistic getSpecVersion () { 173 174 String specver = bean.getSpecVersion(); 175 176 return new StringStatisticImpl(specver, 177 localStrMgr.getString("monitor.stats.jvm_spec_vers"), 178 localStrMgr.getString("monitor.stats.string_units"), 179 localStrMgr.getString("monitor.stats.name_of_jvm_spec_vers"), 180 initTime, 181 System.currentTimeMillis()); 182 } 183 184 public CountStatistic getUptime () { 185 long u = bean.getUptime(); 186 upTime.setCount (u); 187 return (CountStatistic )upTime.unmodifiableView (); 188 } 189 190 public StringStatistic getVmName () { 191 192 String vmname = bean.getVmName(); 193 194 return new StringStatisticImpl(vmname, 195 localStrMgr.getString("monitor.stats.jvm_impl_name"), 196 localStrMgr.getString("monitor.stats.string_units"), 197 localStrMgr.getString("monitor.stats.name_of_jvm_impl"), 198 initTime, 199 System.currentTimeMillis()); 200 } 201 202 public StringStatistic getVmVendor () { 203 204 String vmvendor = bean.getVmVendor(); 205 206 return new StringStatisticImpl(vmvendor, 207 localStrMgr.getString("monitor.stats.jvm_vendor"), 208 localStrMgr.getString("monitor.stats.string_units"), 209 localStrMgr.getString("monitor.stats.name_of_jvm_vendor"), 210 initTime, 211 System.currentTimeMillis()); 212 } 213 214 public StringStatistic getVmVersion () { 215 216 String vmver = bean.getVmVersion(); 217 218 return new StringStatisticImpl(vmver, 219 localStrMgr.getString("monitor.stats.jvm_vers"), 220 localStrMgr.getString("monitor.stats.string_units"), 221 localStrMgr.getString("monitor.stats.name_of_jvm_vers"), 222 initTime, 223 System.currentTimeMillis()); 224 } 225 226 231 public Statistic [] getStatistics() { 232 return baseStatsImpl.getStatistics(); 233 } 234 235 239 public Statistic getStatistic(String str) { 240 return baseStatsImpl.getStatistic(str); 241 } 242 243 248 public String [] getStatisticNames() { 249 return baseStatsImpl.getStatisticNames(); 250 } 251 252 private void initializeStatistics() { 253 254 CountStatistic c = new CountStatisticImpl( 256 localStrMgr.getString("monitor.stats.total_compilation_time"), 257 localStrMgr.getString("monitor.stats.milli_sec_units"), 258 localStrMgr.getString("monitor.stats.milli_sec_units_desc")); 259 upTime = new MutableCountStatisticImpl(c); 260 } 261 262 } 263 | Popular Tags |