FileDocCategorySizeDatePackage
JVMMonitoringManager.javaAPI DocGlassfish v2 API21122Fri May 04 22:24:20 BST 2007com.sun.enterprise.admin.monitor.registry.spi

JVMMonitoringManager

public class JVMMonitoringManager extends Object implements com.sun.enterprise.admin.monitor.registry.MonitoringLevelListener
Manager class responsible for registration/unregistration of all the JVM1.5 Stats. In addition, this class is responsible for handling the monitoring level change events pertaining to the JVM

Fields Summary
private static final Logger
logger
private static final JVMMonitoringManager
jmm
private final int
STACK_DEPTH
private final String
THREAD_NODE_NAME
Constructors Summary
private JVMMonitoringManager()
Creates a new instance of JVMMonitoringManager

    
           
      
    
Methods Summary
public voidchangeLevel(com.sun.enterprise.admin.monitor.registry.MonitoringLevel from, com.sun.enterprise.admin.monitor.registry.MonitoringLevel to, com.sun.enterprise.admin.monitor.registry.MonitoredObjectType type)

        
        logger.finest("changeLevel being invoked on the JVM");
        final MonitoringRegistrationHelper registryImpl	= 
			(MonitoringRegistrationHelper) MonitoringRegistrationHelper.getInstance();
        
        StatsHolder root = registryImpl.getRootStatsHolder();
        boolean includeThreadInfo = false;
        
        if(to == MonitoringLevel.OFF) {
            if(from == MonitoringLevel.HIGH)
                includeThreadInfo = true;
            try {
                unregisterStats(root, includeThreadInfo);
            } catch(MonitoringRegistrationException mre) {
                logger.finest("MonitoringRegistrationException in the unregistration of JVM 1.5 Stats: "+ mre.getLocalizedMessage());
            } catch(Exception e) {
                logger.finest("Exception in the unregistration of JVM 1.5 Stats: "+ e.getLocalizedMessage());
            }
        }
        
        if(from == MonitoringLevel.OFF) {
            if(to == MonitoringLevel.HIGH)
                includeThreadInfo = true;
            registerAllStats(root, includeThreadInfo);
        }
        
        if(from == MonitoringLevel.LOW && to == MonitoringLevel.HIGH) {
            try {
                registerJVMThreadInfoStats(root);
            } catch(MonitoringRegistrationException mre) {
                logger.finest("MonitoringRegistrationException in the registration of JVM ThreadInfoStats: "+ mre.getLocalizedMessage());
            } catch(Exception e) {
                logger.finest("Exception in the registration of JVM ThreadInfo Stats: "+ e.getLocalizedMessage());
            }
        }
        
        if(from == MonitoringLevel.HIGH && to == MonitoringLevel.LOW) {
            try{
                unregisterJVMThreadInfoStats(root);
            } catch(MonitoringRegistrationException mre) {
                logger.finest("MonitoringRegistrationException in the unregistration of JVM ThreadInfoStats: "+ mre.getLocalizedMessage());
            } catch(Exception e) {
                logger.finest("Exception in the unregistration of JVM ThreadInfo Stats: "+ e.getLocalizedMessage());
            }
        }
            
    
public voidchangeLevel(com.sun.enterprise.admin.monitor.registry.MonitoringLevel from, com.sun.enterprise.admin.monitor.registry.MonitoringLevel to, javax.management.j2ee.statistics.Stats handback)

    
public static com.sun.enterprise.admin.monitor.registry.spi.JVMMonitoringManagergetInstance()

        return jmm;
    
private voidregisterAllStats(com.sun.enterprise.admin.monitor.registry.StatsHolder rootNode, boolean includeThreadInfo)

        try {
            registerJVMCompilationStats(rootNode);
            registerJVMClassLoadingStats(rootNode);
            registerJVMRuntimeStats(rootNode);
            registerJVMOperatingSystemStats(rootNode);
            registerJVMGarbageCollectorStats(rootNode);
            registerJVMMemoryStats(rootNode);
            registerJVMThreadStats(rootNode);
            if(includeThreadInfo)
                registerJVMThreadInfoStats(rootNode);
        } catch(MonitoringRegistrationException mre) {
            logger.finest("MonitoringRegistrationException in the registration of JVM1.5 Stats: "+ mre.getLocalizedMessage());
        } catch(Exception e) {
            logger.finest("Exception in the registration of JVM 1.5 Stats: "+ e.getLocalizedMessage());
        }
    
public voidregisterJVMClassLoadingStats(com.sun.enterprise.admin.monitor.registry.StatsHolder rootNode)

               
        final StatsHolder jvmNode = rootNode.getChild(MonitoredObjectType.JVM.getTypeName());
        assert(jvmNode != null): "jvm node is null";
        StatsHolder childNode = jvmNode.addChild(MonitoredObjectType.JVM_CLASSLOADING.getTypeName(), 
                                                 MonitoredObjectType.JVM_CLASSLOADING);
        childNode.setStats(new JVMClassLoadingStatsImpl());
        childNode.setStatsClass(com.sun.enterprise.admin.monitor.stats.JVMClassLoadingStats.class);
        childNode.setDottedName(DottedNameFactory.getJVMClassLoadingDottedName());
        childNode.setObjectName(MonitoringObjectNames.getJVMClassLoadingObjectName());
        childNode.registerMBean();
    
public voidregisterJVMCompilationStats(com.sun.enterprise.admin.monitor.registry.StatsHolder rootNode)


        final StatsHolder jvmNode = rootNode.getChild(MonitoredObjectType.JVM.getTypeName());
        assert(jvmNode != null): "jvm node is null";
        StatsHolder childNode = jvmNode.addChild(MonitoredObjectType.JVM_COMPILATION.getTypeName(), 
                                                 MonitoredObjectType.JVM_COMPILATION);
        childNode.setStats(new JVMCompilationStatsImpl());
        childNode.setStatsClass(com.sun.enterprise.admin.monitor.stats.JVMCompilationStats.class);
        childNode.setDottedName(DottedNameFactory.getJVMCompilationDottedName());
        childNode.setObjectName(MonitoringObjectNames.getJVMCompilationObjectName());
        childNode.registerMBean();
    
public voidregisterJVMGarbageCollectorStats(com.sun.enterprise.admin.monitor.registry.StatsHolder rootNode)
Register the JVMGarbageCollectorStats with the monitoring registry

param
rootNode the root node of the monitoring hierarchy
throws
MonitoringRegistrationException

               
        StatsHolder jvmNode = rootNode.getChild(MonitoredObjectType.JVM.getTypeName());
        assert(jvmNode != null):"jvm node is null";
        // setup the parent node for all garbage collectors
        StatsHolder gcsNode = jvmNode.addChild(MonitoredObjectType.JVM_GCS.getTypeName(), 
                                               MonitoredObjectType.JVM_GCS);
        gcsNode.setDottedName(DottedNameFactory.getJVMGCSDottedName());
        gcsNode.setObjectName(MonitoringObjectNames.getJVMGCSSObjectName());
        gcsNode.registerMBean();
        // now register stats for each garbage colelctor
        List beanList = ManagementFactory.getGarbageCollectorMXBeans();
        Iterator iter = beanList.iterator();
        while(iter.hasNext()) {
            GarbageCollectorMXBean bean = (GarbageCollectorMXBean) iter.next();
            StatsHolder gcNode = gcsNode.addChild(bean.getName(), MonitoredObjectType.JVM_GC);
            gcNode.setStats(new JVMGarbageCollectorStatsImpl(bean));
            gcNode.setStatsClass(com.sun.enterprise.admin.monitor.stats.JVMGarbageCollectorStats.class);
            gcNode.setDottedName(DottedNameFactory.getJVMGCDottedName(bean.getName()));
            gcNode.setObjectName(MonitoringObjectNames.getJVMGCObjectName(bean.getName()));
            gcNode.registerMBean();
        }
    
public voidregisterJVMMemoryStats(com.sun.enterprise.admin.monitor.registry.StatsHolder rootNode)
Register the JVMMemoryStats with the monitoring registry

param
rootNode the root node of the monitoring hierarchy
throws
MonitoringRegistrationException

        
        final StatsHolder jvmNode = rootNode.getChild(MonitoredObjectType.JVM.getTypeName());
        assert(jvmNode != null): "jvm node is null";
        StatsHolder childNode = jvmNode.addChild(MonitoredObjectType.JVM_MEMORY.getTypeName(), 
                                                 MonitoredObjectType.JVM_MEMORY);
        childNode.setStats(new JVMMemoryStatsImpl());
        childNode.setStatsClass(com.sun.enterprise.admin.monitor.stats.JVMMemoryStats.class);
        childNode.setDottedName(DottedNameFactory.getJVMMemoryDottedName());
        childNode.setObjectName(MonitoringObjectNames.getJVMMemoryObjectName());
        childNode.registerMBean();
    
public voidregisterJVMOperatingSystemStats(com.sun.enterprise.admin.monitor.registry.StatsHolder rootNode)

    
        final StatsHolder jvmNode = rootNode.getChild(MonitoredObjectType.JVM.getTypeName());
        assert(jvmNode != null): "jvm node is null";
        StatsHolder childNode = jvmNode.addChild(MonitoredObjectType.JVM_OS.getTypeName(), 
                                                 MonitoredObjectType.JVM_OS);
        childNode.setStats(new JVMOperatingSystemStatsImpl());
        childNode.setStatsClass(com.sun.enterprise.admin.monitor.stats.JVMOperatingSystemStats.class);
        childNode.setDottedName(DottedNameFactory.getJVMOSDottedName());
        childNode.setObjectName(MonitoringObjectNames.getJVMOSObjectName());
        childNode.registerMBean();
    
public voidregisterJVMRuntimeStats(com.sun.enterprise.admin.monitor.registry.StatsHolder rootNode)

     
        final StatsHolder jvmNode = rootNode.getChild(MonitoredObjectType.JVM.getTypeName());
        assert(jvmNode != null): "jvm node is null";
        StatsHolder childNode = jvmNode.addChild(MonitoredObjectType.JVM_RUNTIME.getTypeName(), 
                                                 MonitoredObjectType.JVM_RUNTIME);
        childNode.setStats(new JVMRuntimeStatsImpl());
        childNode.setStatsClass(com.sun.enterprise.admin.monitor.stats.JVMRuntimeStats.class);
        childNode.setDottedName(DottedNameFactory.getJVMRuntimeDottedName());
        childNode.setObjectName(MonitoringObjectNames.getJVMRuntimeObjectName());
        childNode.registerMBean();
    
public voidregisterJVMThreadInfoStats(com.sun.enterprise.admin.monitor.registry.StatsHolder rootNode)

        
        final StatsHolder jvmNode = rootNode.getChild(MonitoredObjectType.JVM.getTypeName());
        assert(jvmNode != null): "jvm node is null";
        final StatsHolder threadSystemNode = jvmNode.getChild(MonitoredObjectType.JVM_THREAD.getTypeName());
        assert(threadSystemNode != null): "thread-system node is null";
        ThreadMXBean bean = ManagementFactory.getThreadMXBean();
        long ids[] = bean.getAllThreadIds();
        for(int i=0; i < ids.length; i++) {
            ThreadInfo info = bean.getThreadInfo(ids[i], STACK_DEPTH);
            String threadName = THREAD_NODE_NAME + "-" + ids[i];
            StatsHolder childNode = threadSystemNode.addChild(threadName, MonitoredObjectType.JVM_THREAD_INFO);
            childNode.setStats(new JVMThreadInfoStatsImpl(info));
            childNode.setStatsClass(com.sun.enterprise.admin.monitor.stats.JVMThreadInfoStats.class);
            childNode.setDottedName(DottedNameFactory.getJVMThreadInfoDottedName(threadName));
            childNode.setObjectName(MonitoringObjectNames.getJVMThreadInfoObjectName(threadName));
            childNode.registerMBean();
        }
    
public voidregisterJVMThreadStats(com.sun.enterprise.admin.monitor.registry.StatsHolder rootNode)

        
        final StatsHolder jvmNode = rootNode.getChild(MonitoredObjectType.JVM.getTypeName());
        assert(jvmNode != null): "jvm node is null";
        StatsHolder childNode = jvmNode.addChild(MonitoredObjectType.JVM_THREAD.getTypeName(),
                                                 MonitoredObjectType.JVM_THREAD);
        childNode.setStats(new JVMThreadStatsImpl());
        childNode.setStatsClass(com.sun.enterprise.admin.monitor.stats.JVMThreadStats.class);
        childNode.setDottedName(DottedNameFactory.getJVMThreadDottedName());
        childNode.setObjectName(MonitoringObjectNames.getJVMThreadObjectName());
        childNode.registerMBean();
    
public voidregisterStats(com.sun.enterprise.admin.monitor.registry.StatsHolder rootNode)
Method that handles the registration of all the stats for various subsystems of the JVM

        MonitoringLevel level = MonitoringConfigurationHandler.getLevel(MonitoredObjectType.JVM);
        // check monitoring level of JVM before registering
        if(level != MonitoringLevel.OFF) {
            try {
                registerJVMCompilationStats(rootNode);
                registerJVMClassLoadingStats(rootNode);
                registerJVMRuntimeStats(rootNode);
                registerJVMOperatingSystemStats(rootNode);
                registerJVMGarbageCollectorStats(rootNode);
                registerJVMMemoryStats(rootNode);
                registerJVMThreadStats(rootNode);
                if(level == MonitoringLevel.HIGH)
                    registerJVMThreadInfoStats(rootNode);
            } catch(MonitoringRegistrationException mre) {
                if (logger.isLoggable(Level.FINEST)) {
                    logger.finest("MonitoringRegistrationException in the registration of JVM1.5 Stats: "+ mre.getLocalizedMessage());
                }
            } catch(Exception e) {
                if (logger.isLoggable(Level.FINEST)) {
                    logger.finest("Exception in the registration of JVM 1.5 Stats: "+ e.getLocalizedMessage());
                }
            }
        }
    
public voidsetLevel(com.sun.enterprise.admin.monitor.registry.MonitoringLevel level)

        
    
public voidunregisterJVMThreadInfoStats(com.sun.enterprise.admin.monitor.registry.StatsHolder rootNode)

        
        final StatsHolder jvmNode = rootNode.getChild(MonitoredObjectType.JVM.getTypeName());
        assert(jvmNode != null): "jvm node is null";
        final StatsHolder threadSystemNode = jvmNode.getChild(MonitoredObjectType.JVM_THREAD.getTypeName());
        assert(threadSystemNode != null): "thread-system node is null";
        Collection c = new ArrayList();
        c.addAll(threadSystemNode.getAllChildren());
        Iterator iter = c.iterator();
        while(iter.hasNext()) {
            StatsHolder s = (StatsHolder)iter.next();
            s.unregisterMBean();
            threadSystemNode.removeChild(s.getName());
        }
    
public voidunregisterStats(com.sun.enterprise.admin.monitor.registry.StatsHolder rootNode, boolean includeThreadInfo)

        
        StatsHolder jvmNode = rootNode.getChild(MonitoredObjectType.JVM.getTypeName());
        assert(jvmNode != null):"jvm node is null";
        Collection c = new ArrayList();
        c.addAll(jvmNode.getAllChildren());
        Iterator iter = c.iterator();
        while(iter.hasNext()) {
            StatsHolder childNode = (StatsHolder)iter.next();
            
            if(childNode.getType() == MonitoredObjectType.JVM_GCS) {
                Collection c1 = new ArrayList();
                c1.addAll(childNode.getAllChildren());
                Iterator it = c1.iterator();
                while(it.hasNext()) {
                    StatsHolder s = (StatsHolder)it.next();
                    s.unregisterMBean();
                    childNode.removeChild(s.getName());
                }
            }
            
            if((childNode.getType() == MonitoredObjectType.JVM_THREAD) && includeThreadInfo) {
                Collection c1 = new ArrayList();
                c1.addAll(childNode.getAllChildren());
                Iterator it = c1.iterator();
                while(it.hasNext()) {
                    StatsHolder s = (StatsHolder)it.next();
                    s.unregisterMBean();
                    childNode.removeChild(s.getName());
                }
            }
            
            childNode.unregisterMBean();
            jvmNode.removeChild(childNode.getName());
        }