1 23 24 29 30 package com.sun.enterprise.admin.mbeans.jvm; 31 32 import com.sun.enterprise.util.i18n.StringManager; 33 import java.lang.management.ManagementFactory ; 34 import java.lang.management.OperatingSystemMXBean ; 35 import java.lang.management.RuntimeMXBean ; 36 import java.util.Map ; 37 import java.util.TreeMap ; 38 import javax.management.MBeanServerConnection ; 39 40 42 class SummaryReporter { 43 44 private final MBeanServerConnection mbsc; 45 private final StringManager sm = StringManager.getManager(SummaryReporter.class); 46 private final static String secretProperty = "module.core.status"; 47 48 public SummaryReporter(final MBeanServerConnection mbsc) { 49 this.mbsc = mbsc; 50 } 51 public String getSummaryReport() throws RuntimeException { 52 try { 53 final StringBuilderNewLineAppender sb = new StringBuilderNewLineAppender(new StringBuilder ()); 54 final OperatingSystemMXBean os = ManagementFactory.newPlatformMXBeanProxy(mbsc, 55 ManagementFactory.OPERATING_SYSTEM_MXBEAN_NAME, OperatingSystemMXBean .class); 56 sb.append(getOSInfo(os)); 57 final RuntimeMXBean rt = ManagementFactory.newPlatformMXBeanProxy(mbsc, 58 ManagementFactory.RUNTIME_MXBEAN_NAME, RuntimeMXBean .class); 59 sb.append(getVMInfo(rt)); 60 return ( sb.toString(secretProperty) ); 61 } catch(final Exception e) { 62 throw new RuntimeException (e); 63 } 64 } 65 66 private String getOSInfo(final OperatingSystemMXBean os) { 67 final StringBuilderNewLineAppender sb = new StringBuilderNewLineAppender(new StringBuilder ()); 68 sb.append(sm.getString("os.info")); 69 sb.append(sm.getString("os.name", os.getName())); 70 sb.append(sm.getString("os.arch", os.getArch(), os.getVersion())); 71 sb.append(sm.getString("os.nproc", os.getAvailableProcessors())); 72 return ( sb.toString() ); 73 } 74 private String getVMInfo(final RuntimeMXBean rt) { 75 final StringBuilderNewLineAppender sb = new StringBuilderNewLineAppender(new StringBuilder ()); 76 sb.append(sm.getString("rt.info", rt.getName())); 77 sb.append(sm.getString("rt.bcp", rt.getBootClassPath())); 78 sb.append(sm.getString("rt.cp", rt.getClassPath())); 79 sb.append(sm.getString("rt.libpath", rt.getLibraryPath())); 80 sb.append(sm.getString("rt.nvv", rt.getVmName(), rt.getVmVendor(), rt.getVmVersion())); 81 sb.append(getProperties(rt)); 82 return ( sb.toString() ); 83 } 84 private String getProperties(final RuntimeMXBean rt) { 85 final StringBuilderNewLineAppender sb = new StringBuilderNewLineAppender(new StringBuilder ()); 86 final Map <String , String > unsorted = rt.getSystemProperties(); 87 final TreeMap <String , String > props = new TreeMap <String , String >(unsorted); 89 sb.append(sm.getString("rt.sysprops")); 90 for (final String n : props.keySet()) { 91 sb.append(n + " = " + props.get(n)); 92 } 93 return ( sb.toString() ); 94 } 95 } 96 | Popular Tags |