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

GeneratedMonitoringMBeanImpl

public class GeneratedMonitoringMBeanImpl extends Object implements DynamicMBean
A generic dynamic mbean implementation for Monitoring which instruments a JSR77 compliant Stats object to be managed by this JMX managed object.
author
Shreedhar Ganapathy

Fields Summary
volatile MBeanInfo
mbeanInfo
final javax.management.j2ee.statistics.Stats
resourceInstance
public static final String
LOGGER_NAME
final Logger
logger
final HashSet
attributeSet
Constructors Summary
public GeneratedMonitoringMBeanImpl(javax.management.j2ee.statistics.Stats stats)
constructs a monitoring mbean that manages an underlying Stats resource

    //StatsHolder statsHolder = null;
                   
       
        logger = Logger.getLogger(LOGGER_NAME);
        this.resourceInstance=stats;
        attributeSet=new HashSet<String>();
    
Methods Summary
public java.lang.ObjectgetAttribute(java.lang.String str)
Implementation of DynamicMBean interface's method. Parses the passed in attribute into two portions. One portion invokes the corresponding method in the Stats object and the second portion is used to invoke the underlying method in the Statistic object returned by the Stats object in the first invocation. Example of an attribute pattern: For JVMStats, HeapSize_UpperBound would translate into JVMStats.getHeapSize() which returns a BoundedRangeStatistic object. The BoundedRangeStatistic.getUpperBound() method is invoked to return the value of the attribute to the client.

param
java.lang.String
return
java.lang.Object
throws
javax.management.AttributeNotFoundException
throws
javax.management.MBeanException
throws
javax.management.ReflectionException

        if(str == null){
            throw new NullPointerException("An attribute needs to be specified to get value");
        }
        
        introspect();

        if(!isValidAttribute(str)){
            throw new AttributeNotFoundException("The requested attribute is not recognized");
        }
        Statistic a = null;
        Object retval=null;
        String[] attrParts = AttributeStringHelper.splitAttribute(str);
        logger.log(Level.INFO,"accessing the Stats object with attr="+attrParts[0]);
        a = (Statistic)resourceInstance.getStatistic(attrParts[0]);
        if(a == null){
            try{
                a = (Statistic)resourceInstance.getClass().
                getMethod("get"+str).
                invoke(resourceInstance);
            }
            catch(Exception e){
                logger.log(Level.INFO,e.getLocalizedMessage());
            }
        }
        //note: do not change this to an "else{ }" block
        if(a != null){
            try{
                retval = a.getClass().getMethod("get"+attrParts[1]).invoke(a);
            }
            catch(Exception e){
                logger.log(Level.INFO,e.getLocalizedMessage());
                logger.log(Level.FINE,e.getStackTrace().toString());
            }
        }
        return retval;
    
public javax.management.AttributeListgetAttributes(java.lang.String[] str)
Implementation of DynamicMBean interface's method. Loops through the passed in String[] and calls getAttribute(str) for each element.

param
java.lang.String[]
return
javax.management.AttributeList

        introspect();
        
        AttributeList list = new AttributeList();
        try{
            for(int i=0; i<str.length;i++){
                list.add(i, new Attribute(str[i],getAttribute(str[i])));
            }
        }
        catch(Exception e){
            logger.log(Level.INFO,e.getMessage()+"\n"+e.getCause().toString());
        }
        return list;
    
public javax.management.MBeanInfogetMBeanInfo()
Implementation of DynamicMBean interface's method. Returns the MBeanInfo object that was generated during introspection of the underlying Stats resource.

return
javax.management.MBeanInfo

        introspect();
        return mbeanInfo;
    
final javax.management.MBeanInfointrospect()
introspects the underlying Stats resource and generates an MBeanInfo object and populates attributes internally for later use culled from the Statistic objects returned by the Stats object.

param
javax.management.j2ee.statistics.Stats
param
javax.management.MBeanInfo

        // !!! 'mbeanInfo' must be 'volatile' !!!
        // this is thread-safe, not the double-null-check idiom so long as
        // 'mbeanInfo' is 'volatile'
        if ( mbeanInfo != null ) {
            return mbeanInfo;
        }
        
        synchronized( this ) {
            if ( mbeanInfo == null ) {
                ManagedResourceIntrospector mri = new ManagedResourceIntrospector(this);
                mbeanInfo = mri.introspect(this.resourceInstance);
                setUpAttributeSet();
            }
        }
        
        return mbeanInfo;
    
public java.lang.Objectinvoke(java.lang.String str, java.lang.Object[] obj, java.lang.String[] str2)

        introspect();
        Object a =null;
        Class[] c = new Class[]{};
        for(int i=0; i<str2.length;i++){
            c[i] = str2[i].getClass();
        }
        try{
            a = (Object) resourceInstance.getClass().getMethod(str, c).invoke(resourceInstance, obj);
        }
        catch(Exception e){
            logger.log(Level.INFO,e.getLocalizedMessage());
            logger.log(Level.FINE,e.getStackTrace().toString());
        }
        return a;
    
private booleanisValidAttribute(java.lang.String str)
checks if the passed in string is a recognized attribute

param
java.lang.String
return
boolean

        if(attributeSet.contains(str))
            return true;
        return false;
    
public java.lang.String[]listAttributes()
Returns String[] of attribute names.

return
String[]

        String[] array = new String[attributeSet.size()];
        attributeSet.toArray(array);
        return array;
    
public voidsetAttribute(javax.management.Attribute attribute)
Implementation of DynamicMBean interface's method - NO-OP.

param
javax.management.Attribute
throws
javax.management.AttributeNotFoundException
throws
javax.management.InvalidAttributeValueException
throws
javax.management.MBeanException
throws
javax.management.ReflectionException

   
public javax.management.AttributeListsetAttributes(javax.management.AttributeList attributeList)
Implementation of DynamicMBean interface's method. Sets a list of attributes. Iterates through the list and calls setAttribute() for each element.

param
javax.management.AttributeList
return
javax.management.AttributeList

        return new AttributeList();
    
private voidsetUpAttributeSet()
sets up the internal data structure to hold attributes derived from Statistic objects returned by the Stats object.

        MBeanAttributeInfo[] attrInfo = mbeanInfo.getAttributes();
        String attr =null;
        for(int i=0;i<attrInfo.length;i++){
            attr = attrInfo[i].getName();
            attributeSet.add(attr);
        }