FileDocCategorySizeDatePackage
BaseMonitorMBean.javaAPI DocGlassfish v2 API33484Fri May 04 22:33:44 BST 2007com.sun.enterprise.admin.monitor

BaseMonitorMBean

public abstract class BaseMonitorMBean extends Object implements DynamicMBean, IMonitorable
Monitoring MBean in iAS. This is the superclass of all monitoring MBeans.

All monitoring MBeans are registered to MBeanServer. Even though MBeanServer does not enforce any hierarchy of MBeans, the implementation within iAS is of a monitoring MBean hierarchy (tree). Therefore, MonitoringMBean for a j2ee application contains monitoring MBeans for all ejb modules and web modules; a monitoring MBean for a ejb module contains monitoring MBeans for all beans (stateless and stateful session beans, entity beans and message driven beans).

A monitoring MBean is fully identified within its context by a type and a name. A monitoring MBean exposed by the method getRootMonitorMBean in com.sun.enterprise.admin.server.AdminService is the root of the monitoring MBean hierarchy.

The methods getNodeName, setNodeName, getNodeType and setNodeType, addChild, removeChild, getChild can be used to manage/access heirarchy of MBeans. However, the properties and operations represented by those methods is not available in mBeanInfo, so the heirarchy can not be managed/accessed through MBeanServer interface.

Fields Summary
static Logger
logger
A reference to logger object
static final HashMap
objectNameMap
A map of object names and MBean instance
private String[]
attrNames
Names of all attributes exposed by this MBean
private ObjectName
objectName
Object name of this MBean as registered in MBean server
private String
nodeName
Name of this MBean at its level in MBean heirarchy.
private String
nodeType
Type of this MBean as registered in MBean heirarchy.
protected Vector
childList
List of child.
private static com.sun.enterprise.util.i18n.StringManager
localStrings
protected static final String
UNSUPPORTED_ERRCODE
protected static final String
UNSUPPORTED_ERRMSG
private static final String
MON_OBJTYPE
private static final String
MON_OBJNAME
private static final String
NON_COMPLIANT_MBEAN
private static final String
MBS_INIT_ERROR
Constructors Summary
Methods Summary
public synchronized javax.management.ObjectNameaddChild(java.lang.String name, MonitoredObjectType type, com.sun.enterprise.admin.monitor.BaseMonitorMBean mBean)
Add an MBean to the MBean tree below this MBean. This method also adds the specified child MBean to the MBeanServer. Adding monitoring MBean to MBeanServer requires object name and can be derived for the child, if this MBean (parent) was already added to MBeanServer.

param
name name of the MBean
param
type type of the MBean
param
mBean the new MBean
throws
InstanceAlreadyExistsException if an MBean of this name and type already exists or if this type is a singleton and one instance already exists.
throws
MBeanRegistrationException preRegister (MBeanRegistration interface) method of the MBean has thrown an exception.
throws
IllegalArgumentException if any of name, type or mBean is null
throws
IllegalStateException if this MBean has not yet been added to tree of monitoring MBeans.
return
name of the child MBean in MBeanServer.

        if (name == null || type == null || mBean == null) {
            String str1 = (name == null) ? "Child Name (name); " : "";
            String str2 = (type == null) ? "Child Type (type); " : "";
            String str3 = (mBean == null) ? "MBean (mBean); " : "";

			String msg = localStrings.getString( "admin.monitor.null_arguments", str1, str2, str3 );
            throw new IllegalArgumentException( msg );
        }
        if (objectName == null || nodeName == null || nodeType == null) {
			String msg = localStrings.getString( "admin.monitor.monitoring_mbean_not_added_to_mbeantree" );
            throw new IllegalStateException( msg );
        }
        boolean exists = false;
        int size = childList.size();
        for (int i = 0; i < size; i++) {
            BaseMonitorMBean m = (BaseMonitorMBean)childList.elementAt(i);
            if (type.isSingleton()) {
                if (m.nodeType.equals(type.getTypeName())) {
                    exists = true;
                    break;
                }
            } else {
                if (m.nodeType.equals(type.getTypeName())
                        && m.nodeName.equals(name)) {
                    exists = true;
                    break;
                }
            }
        }
        if (exists) {
			String msg = localStrings.getString( "admin.monitor.mbean_already_exists", type, name );
            throw new InstanceAlreadyExistsException( msg );
        }
        if (type.isSingleton()) {
            name = type.getTypeName();
        }
        childList.add(mBean);
        mBean.setNodeName(name);
        mBean.setNodeType(type.getTypeName());
        ObjectName childObjName = getChildObjectName(objectName, type, name);
        mBean.setObjectName(childObjName);
        MBeanServer mbs = getMBeanServer();
       /**
        * Commenting this block for now
        try {
            mbs.registerMBean(mBean, childObjName);
        } catch (NotCompliantMBeanException ncme) {
            logger.log(Level.WARNING, NON_COMPLIANT_MBEAN, childObjName);
            throw new MBeanRegistrationException(ncme);
        }
        */
        objectNameMap.put(childObjName, mBean);
        if (type.isMonitoringEnabled()) {
            mBean.startMonitoring();
        }
        return childObjName;
    
private static java.util.MapconvertKeysToCamelCase(java.util.Map attrNameTypeMap)
Converts the keys in the passed map into camel-case strings. The given map must not be null.

return
Map that contains keys as valid java identifiers.
param
attrNameTypeMap a map with keys being invalid java-identifiers, an empty map in case of empty map passed.

        Iterator keys = attrNameTypeMap.keySet().iterator();
        Iterator values = attrNameTypeMap.values().iterator();
        Map newMap = new HashMap();
        while(keys.hasNext()) {
            String key = (String)keys.next();
            String camelCaseKey = toCamelCase(key);
            newMap.put(camelCaseKey, values.next());
        }
        return newMap;
    
protected static java.util.MapcreateAttrNameTypeMap(java.lang.Object[][] attrNameTypeArray)
Convenience method to create a map of monitorable attribute names and their types from a 2-d array of attribute names and attribute types. Attribute types are instances of class MonitoredAttributeType in the package com.sun.enterprise.admin.monitor.types. This method can be called from static initializer of sub-classes to initialize a static variable with a Map of attribute names and types (which can then be returned by the method getMonitoringMetaData)

param
attrNameTypeArray 2-d array of objects containing lists of atttribute names (instances of String) and their corresponding types (instances of MonitoredAttributeTypes)
return
map of attribute names and their corresponding types.

        HashMap map = new HashMap();
        for (int i = attrNameTypeArray.length; i > 0; i--) {
            map.put(attrNameTypeArray[i-1][0], attrNameTypeArray[i-1][1]);
        }
        return map;
    
protected static javax.management.MBeanInfocreateMBeanInfo(java.util.Map attrNameTypeMap)
Convenience method to create MBeanInfo from a HashMap of attribute names and attribute types. This method can be called from static initializer of sub-classes to initialize a static variable with MBeanInfo (which can then be returned by the method getMBeanInfo). This method assumes that sub-classes of BaseMonitorMBean do not implement any additional JMX operations or notifications. If the sub-classes need to implement their own operations and/or notifications the MBeanInfo returned from this method should be updated to add those.

param
map of attribute names (instances of String) and attribute types (instances of MonitoredAttributeTypes)
return
info for this MBean.

        return (createMBeanInfo(attrNameTypeMap, new MBeanOperationInfo[0]));
    
protected static javax.management.MBeanInfocreateMBeanInfo(java.util.Map attrNameTypeMap, javax.management.MBeanOperationInfo[] operationInfoArray)
Convenience method to create MBeanInfo from a HashMap of attribute names and attribute types. This method can be called from static initializer of sub-classes to initialize a static variable with MBeanInfo (which can then be returned by the method getMBeanInfo). This method assumes that sub-classes of BaseMonitorMBean do not implement any additional JMX operations or notifications. If the sub-classes need to implement their own operations and/or notifications the MBeanInfo returned from this method should be updated to add those.

param
map of attribute names (instances of String) and attribute types (instances of MonitoredAttributeTypes)
return
info for this MBean.

        String className = GenericMonitorMBean.class.getName();
        String description = "Generic Monitoring MBean";
        attrNameTypeMap = convertKeysToCamelCase(attrNameTypeMap);
        Set keys = attrNameTypeMap.keySet();
        Iterator names = keys.iterator();
        MBeanAttributeInfo[] attrList = new MBeanAttributeInfo[keys.size()];
        int i = 0;
        while (names.hasNext()) {
            String name = (String)names.next();
            String type = ((MonitoredAttributeType)attrNameTypeMap.get(name)).getJavaTypeName();
            String desc = "Monitored attribute " + name;
            attrList[i] = new MBeanAttributeInfo(name, type, desc, true, false, false);
            i++;
        }
        MBeanConstructorInfo[] constructorList = new MBeanConstructorInfo[0];
        //MBeanOperationInfo[] operationList = new MBeanOperationInfo[0];
        MBeanNotificationInfo[] notificationList = new MBeanNotificationInfo[0];
        return new MBeanInfo(className, description, attrList, constructorList,
               operationInfoArray, notificationList);
    
public java.lang.String[]getAllAttributeNames()
Get name of all attributes exposed by this MBean. The method returns a string array of length zero or more. The default implementation uses MBeanInfo to derive list of attribute names and throws an IllegalStateException if MBeanInfo is null.

return
a string array containing names of all exposed attributes.

        return getAllAttributeNamesFromMBeanInfo();
    
private java.lang.String[]getAllAttributeNamesFromMBeanInfo()
Get name of all attributes exposed by this MBean. This method uses MBeanInfo to derive list of all attributes and caches it. Therefore, if MBeanInfo is changed after a call to this method it will not affect the return value of this method. JMX specification requires that MBeanInfo returned by DynamicMBean implementation does not change once the MBean has been registered.

throws
IllegalStateException if MBeanInfo returned by the method getMBeanInfo is null.

        if (attrNames == null) {
            MBeanInfo info = this.getMBeanInfo();
            if (info == null) {
				String msg = localStrings.getString( "admin.monitor.null_mbean_info", this.getClass() );
                throw new IllegalStateException( msg );
            }
            MBeanAttributeInfo[] attrInfoList = info.getAttributes();
            if (attrInfoList == null) {
				String msg = localStrings.getString( "admin.monitor.null_attribute_info_in_mbeaninfo", this.getClass() );
                throw new IllegalStateException( msg );
            }
            int size = attrInfoList.length;
            attrNames = new String[size];
            for (int i = 0; i < size; i++) {
                attrNames[i] = attrInfoList[i].getName();
            }
        }
        return attrNames;
    
public abstract java.lang.ObjectgetAttribute(java.lang.String attribute)
Obtains the value of a specific monitored attribute.

param
attribute The name of the attribute to be retrieved
returns
The value of the attribute retrieved.
throws
AttributeNotFoundException if attribute name is not valid

public abstract com.sun.enterprise.admin.monitor.types.MonitoredAttributeTypegetAttributeType(java.lang.String attrName)
Get type of the specified monitored attribute.

public abstract javax.management.AttributeListgetAttributes(java.lang.String[] attributes)
Get the values of several attributes of the monitoring MBean.

param
attributes A list of the attributes to be retrieved.
returns
The list of attributes retrieved.

public com.sun.enterprise.admin.monitor.BaseMonitorMBeangetChild(MonitoredObjectType type, java.lang.String name)
Get specified child MBean. If type is singleton, then name parameter is not used for searching.

param
type type of the child MBean
param
name name of the child MBean
return
the child MBean
throws
InstanceNotFoundException if child MBean of specified type and name is not found.
throws
IllegalArgumentException if specified type is null.

        BaseMonitorMBean found = getChildOrNull(type, name);
        if (found == null) {
			String msg = localStrings.getString( "admin.monitor.mbean_not_found", type, name );
            throw new InstanceNotFoundException( msg );
        }
        return found;
    
public java.util.ArrayListgetChildList(MonitoredObjectType type)
Get list of children of specified type for this MBean. This method returns all children of specified type for this MBean. If there is no child of specified type, the method returns an empty list.

param
type type of the child MBean
throws
IllegalArgumentException if type is null
return
an arraylist containing all children

        if (type == null) {
			String msg = localStrings.getString( "admin.monitor.null_argument_mbean_type" );
            throw new IllegalArgumentException( msg );
        }
        ArrayList list = new ArrayList();
        Iterator iter = childList.iterator();
        while (iter.hasNext()) {
            BaseMonitorMBean mBean = (BaseMonitorMBean)iter.next();
            if (mBean.nodeType.equals(type.getTypeName())) {
                list.add(mBean);
            }
        }
        return list;
    
public java.util.ArrayListgetChildList(java.lang.String name)
Get list of children of specified name for this MBean. This method returns all children of specified name for this MBean. If there is no child of specified name, the method returns an empty list.

param
name name of the child MBean
return
an arraylist containing all children

        ArrayList list = new ArrayList();
        Iterator iter = childList.iterator();
        while (iter.hasNext()) {
            BaseMonitorMBean mBean = (BaseMonitorMBean)iter.next();
            if (mBean.nodeName.equals(name)) {
                list.add(mBean);
            }
        }
        return list;
    
public java.util.ArrayListgetChildList()
Get list of children of this MBean. This method returns all children of this MBean. If there is no child, the method returns an empty list.

return
an arraylist containing all children

        ArrayList list = new ArrayList();
        list.addAll(childList);
        return list;
    
private static javax.management.ObjectNamegetChildObjectName(javax.management.ObjectName parent, MonitoredObjectType childType, java.lang.String childName)
Derive Object Name for the child MBean.

        Hashtable props = parent.getKeyPropertyList();
        Hashtable newProps = (Hashtable)props.clone();
        String type = (String)props.get(MON_OBJTYPE);
        String name = (String)props.get(MON_OBJNAME);
        newProps.put(type, name);
        newProps.put(MON_OBJTYPE, childType.getTypeName());
        newProps.put(MON_OBJNAME, childName);
        ObjectName newName = null;
        try {
            newName = new ObjectName(parent.getDomain(), newProps);
        } catch (MalformedObjectNameException mone) {
            throw new MBeanRegistrationException(mone, mone.getMessage());
        }
        return newName;
    
com.sun.enterprise.admin.monitor.BaseMonitorMBeangetChildOrNull(MonitoredObjectType type, java.lang.String name)
Get specified child mbean or null if there is no such child.

param
type type of the child MBean
param
name name of the child MBean
throws
IllegalArgumentException if specified type is null.
return
the child MBean if it exists, null otherwise

        if (type == null) {
			String msg = localStrings.getString( "admin.monitor.monitored_object_type_null" );
            throw new IllegalArgumentException( msg );
        }
        BaseMonitorMBean found = null;
        Iterator iter = childList.iterator();
        while (iter.hasNext()) {
            BaseMonitorMBean mBean = (BaseMonitorMBean)iter.next();
            if (type.isSingleton()) {
                if (mBean.nodeType.equals(type.getTypeName())) {
                    found = mBean;
                }
            } else {
                if (mBean.nodeType.equals(type.getTypeName())
                        && mBean.nodeName.equals(name)) {
                    found = mBean;
                }
            }
        }
        return found;
    
com.sun.enterprise.admin.monitor.BaseMonitorMBeangetFirstChildByName(java.lang.String name)
Get first child MBean with the specified name.

throws
InstanceNotFoundException if no child MBean of specified name exists.
return
child MBean with specified name

        ArrayList list = getChildList(name);
        if (list.isEmpty()) {
			String msg = localStrings.getString( "admin.monitor.child_mbean_not_available", name, objectName );
            throw new InstanceNotFoundException( msg );
        }
        return ((BaseMonitorMBean)list.get(0));
    
private static java.lang.StringgetLocalString(java.lang.String key, java.lang.String dflt)

        return dflt;
    
public abstract javax.management.MBeanInfogetMBeanInfo()
Provides the exposed attributes and actions of the monitoring MBean using an MBeanInfo object. The implementation for this method should ensure that the returned value is always same (not necessarily same reference, but same contained values).

returns
An instance of MBeanInfo with all attributes and actions exposed by this monitoring MBean.

private static javax.management.MBeanServergetMBeanServer()
Get MBeanServer. If MBeanServer is not found then this method throws RuntimeException.

throws
RuntimeException if there is any error in getting MBeanServer
return
an implementation of MBeanServer interface

        return MBeanServerFactory.getMBeanServer();
    
public final java.lang.ObjectgetMonitoredAttributeValue(java.lang.String monitorAttributeName)
Get value of specified monitored attribute. This method is from interface IMonitorable and is implemented to use method getAttribute from DynamicMBean interface.

param
monitorAttributeName name of the monitored attribute
return
value of the specified monitored attribute, if it exists, null otherwise.

        Object result = null;
        try {
            result = getAttribute(monitorAttributeName);
        } catch (AttributeNotFoundException anfe) {
        }
        return result;
    
public final java.util.MapgetMonitoredAttributeValues(java.util.Set monitorAttributeNameSet)
Get values of specified monitored attributes. This method returns a map of monitored attribute names and their corresponding values. This method is from interface IMonitorable and is implemented to use method getAttributes from DynamicMBean interface.

param
monitorAttributeNameSet set of monitored attribute names
return
map of attribute names and their values

        return null;
    
public abstract java.util.MapgetMonitoringMetaData()
Get a map of monitored attribute names and their types. The keys in the map are names of the attribute and the values are their types. The type value are instances of class com.iplanet.ias.monitor.type.MonitoredAttributeType (or its sub-classes)

return
map of names and types of all monitored attributes

public java.lang.StringgetNodeName()
Get name of this MBean. A typical example is - for a stateless session bean called fortune, this method will return fortune. The MBean has a fully qualified name in the MBeanServer, but this method only returns name from the current context.

return
name of the MBean within its context.

        return nodeName;
    
public java.lang.StringgetNodeType()
Get type of this MBean. This is the type used in the hierarchy of monitoring MBeans.

return
type of this MBean.

        return nodeType;
    
public javax.management.ObjectNamegetObjectName()
Get name of this MBean as registered in MBean server.

        return objectName;
    
public java.lang.Objectinvoke(java.lang.String str, java.lang.Object[] obj, java.lang.String[] str2)
Invoke a operation on this MBean.

        throw new UnsupportedOperationException(
                getLocalString(UNSUPPORTED_ERRCODE, UNSUPPORTED_ERRMSG));
    
private static voidremoveAllChild(com.sun.enterprise.admin.monitor.BaseMonitorMBean mbean)
Remove all child MBeans of specified mbean. This methos also unregisters all child Mbeans from MBean server. It recusrively calls itself if the child mbeans also have child(ren).

throws
InstanceNotFoundException if any of the child MBean is not registered to MBeanSever.
throws
MBeanRegistrationException preDeregister (MBeanRegistration interface) method of any of the child MBean throws an exception

        Iterator iter = mbean.childList.iterator();
        while (iter.hasNext()) {
            BaseMonitorMBean child = (BaseMonitorMBean)iter.next();
            removeAllChild(child);
            objectNameMap.remove(child.objectName);
            MBeanServer mbs = getMBeanServer();
            // Commenting this line for now
            // mbs.unregisterMBean(child.objectName);
        }
        mbean.childList.removeAllElements();
    
public synchronized voidremoveChild(MonitoredObjectType type, java.lang.String name)
Remove specified monitoring MBean from MBean tree. This method will remove the specified MBean from MBeanServer as well. If the specified MBean has any child(ren) they are also removed from the MBean tree and MBeanServer.

param
type the type of MBean
param
name the name of MBean
throws
InstanceNotFoundException if the specified MBean (name and type) is not a child of this MBean.
throws
MBeanRegistrationException preDeregister (MBeanRegistration interface) method of the MBean has thrown an exception
throws
IllegalArgumentException if specified type is null.

        BaseMonitorMBean mBean = getChild(type, name);
        removeChild(mBean);
    
synchronized voidremoveChild(com.sun.enterprise.admin.monitor.BaseMonitorMBean child)
Remove specified child MBean from MBean tree. This method will remove the specified MBean from MBeanServer as well. If the specified MBean has any child(ren) they are also removed from the MBean tree and MBeanServer.

param
child the child MBean
throws
InstanceNotFoundException if the specified MBean is not a child of this MBean.
throws
MBeanRegistrationException preDeregister (MBeanRegistration interface) method of the MBean has thrown an exception

        removeAllChild(child);
        childList.remove(child);
        objectNameMap.remove(child.objectName);
        MBeanServer mbs = getMBeanServer();
        // Commenting this line for now
        // mbs.unregisterMBean(child.objectName);
    
public final voidsetAttribute(javax.management.Attribute attribute)
Set an attribute on this MBean.

        throw new UnsupportedOperationException(
                getLocalString(UNSUPPORTED_ERRCODE, UNSUPPORTED_ERRMSG));
    
public final javax.management.AttributeListsetAttributes(javax.management.AttributeList attributeList)
Set specified attributes on this MBean

        throw new UnsupportedOperationException(
                getLocalString(UNSUPPORTED_ERRCODE, UNSUPPORTED_ERRMSG));
    
protected voidsetNodeName(java.lang.String name)
Set name of the node to specified value. Invoked from addChild method of the parent of this MBean. So, this method need not be called elsewhere. A call to this method does not affect the name in MBeanServer, so the caller of this method should also handle naming within MBeanServer.

param
name name of this MBean

        nodeName = name;
    
protected voidsetNodeType(java.lang.String type)
Set type of this MBean to specified value. This method is invoked from the method addChild of the parent of this MBean. A call to this method does not affect the naming within MBeanServer, so the caller of this method should also handle naming within MBeanServer.

param
type type of the MBean

        nodeType = type;
    
protected voidsetObjectName(javax.management.ObjectName objName)
Set object name for this MBean. This should be same as the name used to register this MBean to MBeanServer.

param
objName name of this MBean as registered in MBean Server


                                        
        
        objectName = objName;
    
public voidstartMonitoring()
Start monitoring on this component. This will be called when monitoring is enabled on this component (or the group containing this component) through user interface.

see
stopMonitoring

    
public voidstopMonitoring()
Stop monitoring on this component. Called when monitoring is disabled on user interface.

    
private static java.lang.StringtoCamelCase(java.lang.String illegalIdentifier)
Converts the given string with characters that are illegal identifier parts and converts it into a String with camel-case. The entire BNF is out of the scope. Following are the basic rules:
  • gets rid of all the illegal characters in given string.
  • all consecutive illegal characters are collapsed.
  • leading and trailing illegal characters are ignored.
  • given string should have no other illegal characters (that make it an illegal java-identifier). This is asserted.
  • The case of an already upper-case character is NOT changed.

    throws
    NullPointerException in case of null string.
    returns
    the String with camel-case version of passed string.

            final StringBuffer from = new StringBuffer(illegalIdentifier);
            final StringBuffer to = new StringBuffer();
            final int length = from.length();
    	    boolean illegalFound = false;
            for (int i = 0 ; i < length ; i++) {
    	    char currentChar = from.charAt(i);
    	    /* First char should be valid start and char at any other position
                 should be valid part, otherwise ignore it. */
                if (i == 0 && !Character.isJavaIdentifierStart(currentChar) ||
    		        i > 0  && !Character.isJavaIdentifierPart(currentChar)) {
                    illegalFound = true;
                    continue;
                }
                if (illegalFound) {
                    to.append(Character.toUpperCase(currentChar));
                    illegalFound = false;
                }
                else {
                    to.append(currentChar);
                }
            }
    	    return (to.toString());