MonitorGetCommandpublic class MonitorGetCommand extends MonitorCommand Get command for monitoring. |
Fields Summary |
---|
private static final int | GET_ATTRConstant to denote - get specified attribute value from specified MBean | private static final int | GET_ALL_ATTRConstant to denote - get all attribute values from specified MBean | private static final int | GET_ATTR_FOR_TYPEConstant to denote - get specified attribute value from all child MBeans
of specified type. | private static final int | GET_ALL_ATTR_FOR_TYPEConstant to denote - get all attribute values from all child MBeans of
specified type. | private String | attrNameName 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 | WILDCARDConstant 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.
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.
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.String | getQualifiedName(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.
StringBuffer fullName = new StringBuffer();
fullName.append(mbean.getNodeType());
if (!type.isSingleton()) {
fullName.append("." + mbean.getNodeName());
}
fullName.append("." + attrName);
return fullName.toString();
| java.lang.Object | runCommand()Run get command. This method returns an instance of jmx AttributeList.
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;
|
|