1 23 24 package com.sun.enterprise.admin.monitor.stats.spi; 25 import java.lang.management.ManagementFactory ; 26 import java.lang.management.OperatingSystemMXBean ; 27 import javax.management.ObjectName ; 28 import javax.management.MBeanServerFactory ; 29 import javax.management.MBeanServer ; 30 import javax.management.j2ee.statistics.Statistic ; 31 import javax.management.j2ee.statistics.CountStatistic ; 32 import com.sun.enterprise.admin.monitor.stats.StringStatistic; 33 import com.sun.enterprise.admin.monitor.stats.JVMOperatingSystemStats; 34 import com.sun.enterprise.admin.monitor.stats.MutableCountStatistic; 35 import com.sun.enterprise.admin.monitor.stats.MutableCountStatisticImpl; 36 import com.sun.enterprise.admin.monitor.stats.GenericStatsImpl; 37 import com.sun.enterprise.admin.monitor.stats.CountStatisticImpl; 38 import com.sun.enterprise.admin.monitor.stats.StringStatisticImpl; 39 import com.sun.enterprise.admin.monitor.stats.StatisticImpl; 40 import com.sun.enterprise.util.i18n.StringManager; 41 42 public class JVMOperatingSystemStatsImpl implements JVMOperatingSystemStats { 43 44 private GenericStatsImpl baseStatsImpl; 45 private static final String STATS_INTERFACE_NAME = 46 "com.sun.enterprise.admin.monitor.stats.JVMOperatingSystemStats"; 47 private MBeanServer server; 48 private MutableCountStatistic availProcs; 49 private StringStatistic name; 50 private OperatingSystemMXBean bean; 51 final long initTime; 52 private static final StringManager localStrMgr = 53 StringManager.getManager(JVMOperatingSystemStatsImpl.class); 54 55 56 57 public JVMOperatingSystemStatsImpl () { 58 59 initTime = System.currentTimeMillis (); 60 try { 61 baseStatsImpl = new GenericStatsImpl(STATS_INTERFACE_NAME, this); 62 } catch(Exception e) { 63 64 } 65 bean = ManagementFactory.getOperatingSystemMXBean(); 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_os"), 82 initTime, 83 System.currentTimeMillis()); 84 } 85 86 public StringStatistic getArch () { 87 88 String arch = bean.getArch(); 89 90 return new StringStatisticImpl(arch, 91 localStrMgr.getString("monitor.stats.arch_string"), 92 localStrMgr.getString("monitor.stats.string_units"), 93 localStrMgr.getString("monitor.stats.arch_of_os"), 94 initTime, 95 System.currentTimeMillis()); 96 } 97 98 public CountStatistic getAvailableProcessors () { 99 long procs = bean.getAvailableProcessors(); 100 availProcs.setCount (procs); 101 return (CountStatistic )availProcs.unmodifiableView (); 102 } 103 104 public StringStatistic getVersion () { 105 106 String version = bean.getVersion(); 107 108 return new StringStatisticImpl(version, 109 localStrMgr.getString("monitor.stats.vers_string"), 110 localStrMgr.getString("monitor.stats.string_units"), 111 localStrMgr.getString("monitor.stats.vers_of_os"), 112 initTime, 113 System.currentTimeMillis()); 114 } 115 116 117 122 public Statistic [] getStatistics() { 123 return baseStatsImpl.getStatistics(); 124 } 125 126 130 public Statistic getStatistic(String str) { 131 return baseStatsImpl.getStatistic(str); 132 } 133 134 139 public String [] getStatisticNames() { 140 return baseStatsImpl.getStatisticNames(); 141 } 142 143 private void initializeStatistics() { 144 145 CountStatistic c = new CountStatisticImpl( 147 localStrMgr.getString("monitor.stats.avail_procs"), 148 StatisticImpl.DEFAULT_UNIT, 149 localStrMgr.getString("monitor.stats.avail_procs_desc")); 150 availProcs = new MutableCountStatisticImpl(c); 151 } 152 } 153 | Popular Tags |