1 23 24 29 30 31 package com.sun.enterprise.admin.mbeans.jvm; 32 33 import com.sun.enterprise.admin.server.core.AdminService; 34 import com.sun.enterprise.admin.target.Target; 35 import com.sun.enterprise.admin.target.TargetBuilder; 36 import com.sun.enterprise.admin.target.TargetType; 37 import com.sun.enterprise.config.ConfigContext; 38 import com.sun.enterprise.util.SystemPropertyConstants; 39 import com.sun.enterprise.util.i18n.StringManager; 40 import java.text.NumberFormat ; 41 import java.util.Hashtable ; 42 import javax.management.MBeanRegistration ; 43 import javax.management.MBeanServer ; 44 import javax.management.MBeanServerConnection ; 45 import javax.management.NotCompliantMBeanException ; 46 import javax.management.ObjectName ; 47 import javax.management.StandardMBean ; 48 49 51 public class JVMInformationCollector extends StandardMBean implements JVMInformationMBean, MBeanRegistration { 52 53 private MBeanServerConnection mbsc; 54 private static final StringManager sm = StringManager.getManager(JVMInformationCollector.class); 55 public JVMInformationCollector() throws NotCompliantMBeanException { 56 super(JVMInformationMBean.class); 57 } 58 public String getThreadDump(final String processName) { 59 final ObjectName on = processTarget(processName); 60 final String td = invokeMBean(on, "getThreadDump"); 61 return ( td ); 62 } 63 64 public String getSummary(final String processName) { 65 final ObjectName on = processTarget(processName); 66 final String s = invokeMBean(on, "getSummary"); 67 return ( s ); 68 } 69 70 public String getMemoryInformation(final String processName) { 71 final ObjectName on = processTarget(processName); 72 final String mi = invokeMBean(on, "getMemoryInformation"); 73 return ( mi ); 74 } 75 76 public String getClassInformation(final String processName) { 77 final ObjectName on = processTarget(processName); 78 final String ci = invokeMBean(on, "getClassInformation"); 79 return ( ci ); 80 } 81 82 private ObjectName processTarget(final String processName) throws RuntimeException { 83 try { 84 final TargetType[] vts = {TargetType.DAS, TargetType.SERVER}; 85 final ConfigContext acc = AdminService.getAdminService().getAdminContext().getAdminConfigContext(); 86 final Target t = TargetBuilder.INSTANCE.createTarget(null, vts, processName, acc); final String sn = t.getName(); 89 final String cn = JVMInformation.class.getSimpleName(); 90 final ObjectName on = formObjectName(sn, cn); 91 if (! this.mbsc.isRegistered(on)) { 92 final String msg = sm.getString("server.unreachable", sn); 93 throw new RuntimeException (msg); 94 } 95 return (on); 96 } catch (final RuntimeException re) { 97 throw(re); 98 } catch (final Exception e) { 99 throw new RuntimeException (e); 100 } 101 } 102 103 private String invokeMBean(final ObjectName jvm, final String method) throws RuntimeException { 104 try { 105 final Object [] params = {null}; 108 final String [] sign = {"java.lang.String"}; 109 final Object ret = this.mbsc.invoke(jvm, method, params, sign); 110 111 return ( (String ) ret ); 112 113 } catch (final Exception e) { 114 throw new RuntimeException (e); 115 } 116 } 117 public void postRegister(Boolean registrationDone) { 118 } 119 120 public ObjectName preRegister(final MBeanServer server, final ObjectName name) throws Exception { 121 this.mbsc = server; 122 final String sn = System.getProperty(SystemPropertyConstants.SERVER_NAME); 123 final ObjectName on = formObjectName(sn, JVMInformationCollector.class.getSimpleName()); 124 return ( on ); 125 } 126 127 public void preDeregister() throws Exception { 128 } 129 130 public void postDeregister() { 131 } 132 133 static ObjectName formObjectName(final String sn, final String cName) throws Exception { 134 135 final String domain = AdminService.PRIVATE_MBEAN_DOMAIN_NAME; 136 final Hashtable <String , String > props = new Hashtable <String , String > (); 137 props.put("type", cName); 138 props.put("category", "monitor"); 139 final String snk = "server"; 140 props.put(snk, sn); 141 return ( new ObjectName (domain, props) ); 142 } 143 144 static String millis2HoursMinutesSeconds(final long millis) { 145 final long secmin = millis / (long) 1000; 146 final long sec = secmin % 60; 147 final long minhr = secmin / 60; 148 final long min = minhr % 60; 149 final long hr = minhr / 60; 150 final String msg = sm.getString("m2hms", hr, min, sec); 151 152 return ( msg ); 153 } 154 static String millis2SecondsMillis(final long millis) { 155 final long sec = millis / (long) 1000; 156 final long ms = millis % 1000; 157 final String msg = sm.getString("m2sms", sec, ms); 158 return ( msg ); 159 } 160 static String formatLong(final long sayBytes) { 161 final NumberFormat n = NumberFormat.getInstance(); 162 return ( n.format(sayBytes) ); 163 } 164 } 165 | Popular Tags |