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

MonitorGetCommand

public class MonitorGetCommand extends MonitorCommand
Get command for monitoring.

Fields Summary
private static final int
GET_ATTR
Constant to denote - get specified attribute value from specified MBean
private static final int
GET_ALL_ATTR
Constant to denote - get all attribute values from specified MBean
private static final int
GET_ATTR_FOR_TYPE
Constant to denote - get specified attribute value from all child MBeans of specified type.
private static final int
GET_ALL_ATTR_FOR_TYPE
Constant to denote - get all attribute values from all child MBeans of specified type.
private String
attrName
Name of the attribute. This is either an attribute name or wildcard character (*) denoting all attributes. Partial wildcard is not supported, so num-invocation can be used but num* can not be.
private static final String
WILDCARD
Constant to denote wildcard character (addresses all attributes)
Constructors Summary
MonitorGetCommand(ObjectName mbeanName, String attrName)
Create a new get command that gets specified attribute from specified MBean.

param
mbeanName object name of the MBean
param
attrName name of the attribute. This can be wildcard character


                                        
        
        this.objectName = mbeanName;
        this.attrName = attrName;
        if (WILDCARD.equals(attrName)) {
            actionCode = GET_ALL_ATTR;
        } else {
            actionCode = GET_ATTR;
        }
    
MonitorGetCommand(ObjectName mbeanName, MonitoredObjectType type, String attrName)
Create a new get command that gets specified attribute from all child of specified type from the specified MBean.

param
mbeanName object name of the MBean
param
type the type of child MBeans to search
param
attrName name of the attribute. This can be wildcard character

        this.objectName = mbeanName;
        this.monitoredObjectType = type.getTypeName();
        this.attrName = attrName;
        if (WILDCARD.equals(attrName)) {
            actionCode = GET_ALL_ATTR_FOR_TYPE;
        } else {
            actionCode = GET_ATTR_FOR_TYPE;
        }
    
Methods Summary
private java.lang.StringgetQualifiedName(BaseMonitorMBean mbean, MonitoredObjectType type, java.lang.String attrName)
Get qualified name of an attribute. It is possible to get attributes from more than one MBean in same command invocation. In these cases, the attribute names are prefixed with child MBean type and optionally child MBean name to scope the attribute name properly.

param
mbean the child mbean
param
type type of the child mbean
param
attrName name of the attribute in child mbean

        StringBuffer fullName = new StringBuffer();
        fullName.append(mbean.getNodeType());
        if (!type.isSingleton()) {
            fullName.append("." + mbean.getNodeName());
        }
        fullName.append("." + attrName);
        return fullName.toString();
    
java.lang.ObjectrunCommand()
Run get command. This method returns an instance of jmx AttributeList.

throws
InstanceNotFoundException if the MBean is not found
throws
AttributeNotFoundException if the attribute is not found
return
list of attributes

        BaseMonitorMBean mbean = MonitoringHelper.getMonitorMBean(objectName);
        MonitoredObjectType type = null;
        if (monitoredObjectType != null) {
            type = MonitoredObjectType.getMonitoredObjectType(monitoredObjectType);
        }
        ArrayList mbeanList = null;
        if (actionCode == GET_ATTR_FOR_TYPE
                || actionCode == GET_ALL_ATTR_FOR_TYPE) {
            mbeanList = mbean.getChildList(type);
        } else {
            mbeanList = new ArrayList();
            mbeanList.add(mbean);
        }
        AttributeList result = new AttributeList();
        Iterator iter = mbeanList.iterator();
        while (iter.hasNext()) {
            BaseMonitorMBean bmb = (BaseMonitorMBean)iter.next();
            if (actionCode == GET_ATTR || actionCode == GET_ATTR_FOR_TYPE) {
                Object val = bmb.getAttribute(attrName);
                Attribute attr = null;
                if (actionCode == GET_ATTR_FOR_TYPE) {
                    attr = new Attribute(getQualifiedName(bmb, type, attrName),
                            val);
                } else {
                    attr = new Attribute(attrName, val);
                }
                result.add(attr);
            } else if (actionCode == GET_ALL_ATTR
                    || actionCode == GET_ALL_ATTR_FOR_TYPE) {
                String[] attrNames = bmb.getAllAttributeNames();
                AttributeList attrList = bmb.getAttributes(attrNames);
                if (actionCode == GET_ALL_ATTR_FOR_TYPE) {
                    AttributeList newAttrList = new AttributeList();
                    int numAttr = attrList.size();
                    for (int i = 0; i < numAttr; i++) {
                        Attribute attr = (Attribute)attrList.get(i);
                        attr = new Attribute(
                                getQualifiedName(bmb, type, attr.getName()),
                                attr.getValue());
                        newAttrList.add(attr);
                    }
                    attrList = newAttrList;
                }
                result.addAll(attrList);
            }
        }
        return result;