FileDocCategorySizeDatePackage
JVMInformationCollector.javaAPI DocGlassfish v2 API8257Wed Jul 18 19:40:46 BST 2007com.sun.enterprise.admin.mbeans.jvm

JVMInformationCollector

public class JVMInformationCollector extends StandardMBean implements JVMInformationMBean, MBeanRegistration

Fields Summary
private static final String
SERVER_NAME_KEY_IN_ON
private MBeanServerConnection
mbsc
private static final com.sun.enterprise.util.i18n.StringManager
sm
Constructors Summary
public JVMInformationCollector()

        
        super(JVMInformationMBean.class);
    
Methods Summary
static javax.management.ObjectNameformObjectName(java.lang.String sn, java.lang.String cName)

        /* domain:type=impl-class,server=target-server*/
        final String domain = AdminService.PRIVATE_MBEAN_DOMAIN_NAME;
        final Hashtable<String, String> props = new Hashtable<String, String> ();
        props.put("type", cName);
        props.put("category", "monitor");
        final String snk = SERVER_NAME_KEY_IN_ON;
        props.put(snk, sn);
        return ( new ObjectName(domain, props) );
    
static java.lang.StringformatLong(long sayBytes)

        final NumberFormat n = NumberFormat.getInstance();
        return ( n.format(sayBytes) );
    
public java.lang.StringgetClassInformation(java.lang.String processName)

        final ObjectName on = processTarget(processName);
        final String title = sm.getString("class.info.title", getInstanceNameFromObjectName(on));
        final String ci = title + "\n " + invokeMBean(on, "getClassInformation");
        return ( ci );
    
private java.lang.StringgetInstanceNameFromObjectName(javax.management.ObjectName on)

        return ( on.getKeyProperty(SERVER_NAME_KEY_IN_ON) );
    
public java.lang.StringgetMemoryInformation(java.lang.String processName)

        final ObjectName on = processTarget(processName);
        final String title = sm.getString("memory.info.title", getInstanceNameFromObjectName(on));
        final String mi = title + "\n" + invokeMBean(on, "getMemoryInformation");
        return ( mi );
    
public java.lang.StringgetSummary(java.lang.String processName)

        final ObjectName on = processTarget(processName);
        final String title = sm.getString("summary.title", getInstanceNameFromObjectName(on));
        final String s = title + "\n" + invokeMBean(on, "getSummary");
        return ( s );
    
public java.lang.StringgetThreadDump(java.lang.String processName)

        final ObjectName on = processTarget(processName);
        final String title = sm.getString("thread.dump.title", getInstanceNameFromObjectName(on));
        final String td = title + "\n" + invokeMBean(on, "getThreadDump");
        return ( td );
    
private java.lang.StringinvokeMBean(javax.management.ObjectName jvm, java.lang.String method)

        try {
            //though proxies work fine, for now (jul 2005), I am not going to use them because I am not sure how they work with cascading
            //it is okay to assume that the methods in this mbean take String as parameter
            final Object[] params   = {null};
            final String[] sign     = {"java.lang.String"};
            final Object ret        = this.mbsc.invoke(jvm, method, params, sign);
            
            return ( (String) ret );
            
        } catch (final Exception e) {
            throw new RuntimeException(e);
        }
    
static java.lang.Stringmillis2HoursMinutesSeconds(long millis)

        final long secmin = millis / (long) 1000;
        final long sec = secmin % 60;
        final long minhr = secmin / 60;
        final long min = minhr % 60;
        final long hr = minhr / 60;
        final String msg = sm.getString("m2hms", hr, min, sec);
        
        return ( msg );
    
static java.lang.Stringmillis2SecondsMillis(long millis)

        final long sec    = millis / (long) 1000;
        final long ms     = millis % 1000;
        final String msg  = sm.getString("m2sms", sec, ms);
        return ( msg );
    
public voidpostDeregister()

    
public voidpostRegister(java.lang.Boolean registrationDone)

    
public voidpreDeregister()

    
public javax.management.ObjectNamepreRegister(javax.management.MBeanServer server, javax.management.ObjectName name)

        this.mbsc = server;
        final String sn = System.getProperty(SystemPropertyConstants.SERVER_NAME);
        final ObjectName on = formObjectName(sn, JVMInformationCollector.class.getSimpleName());
        return ( on );
    
private javax.management.ObjectNameprocessTarget(java.lang.String processName)

        try {
            final TargetType[] vts = {TargetType.DAS, TargetType.SERVER};
            final ConfigContext acc = AdminService.getAdminService().getAdminContext().getAdminConfigContext();
            final Target t = TargetBuilder.INSTANCE.createTarget(null, vts, processName, acc); //DAS is the default target
            //get the object-name of the "other" real implementation of JVMInformationMBean interface :)
            final String sn = t.getName();
            final String cn = JVMInformation.class.getSimpleName();
            final ObjectName on = formObjectName(sn, cn);
            if (! this.mbsc.isRegistered(on)) {
                final String msg = sm.getString("server.unreachable", sn);
                throw new RuntimeException(msg);
            }
            return (on);
        } catch (final RuntimeException re) {
            throw(re);
        } catch (final Exception e) {
            throw new RuntimeException(e);
        }