use of javax.management.MBeanInfo in project tomcat by apache.
the class JMXAccessorSetTask method getMBeanAttributeType.
/**
* Get MBean Attribute from Mbean Server
*
* @param jmxServerConnection The JMX connection name
* @param name The MBean name
* @param attribute The attribute name
* @return The type of the attribute
* @throws Exception An error occurred
*/
protected String getMBeanAttributeType(MBeanServerConnection jmxServerConnection, String name, String attribute) throws Exception {
ObjectName oname = new ObjectName(name);
String mattrType = null;
MBeanInfo minfo = jmxServerConnection.getMBeanInfo(oname);
MBeanAttributeInfo[] attrs = minfo.getAttributes();
for (int i = 0; mattrType == null && i < attrs.length; i++) {
if (attribute.equals(attrs[i].getName()))
mattrType = attrs[i].getType();
}
return mattrType;
}
use of javax.management.MBeanInfo in project tomcat by apache.
the class Registry method getMethodInfo.
/**
* Find the operation info for a method
*
* @param oname The bean name
* @param opName The operation name
* @return the operation info for the specified operation
*/
public MBeanOperationInfo getMethodInfo(ObjectName oname, String opName) {
MBeanInfo info = null;
try {
info = server.getMBeanInfo(oname);
} catch (Exception e) {
log.info("Can't find metadata " + oname);
return null;
}
MBeanOperationInfo[] attInfo = info.getOperations();
for (int i = 0; i < attInfo.length; i++) {
if (opName.equals(attInfo[i].getName())) {
return attInfo[i];
}
}
return null;
}
use of javax.management.MBeanInfo in project hive by apache.
the class TestLegacyMetrics method testMetricsMBean.
@Test
public void testMetricsMBean() throws Exception {
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
final ObjectName oname = new ObjectName("org.apache.hadoop.hive.common.metrics:type=MetricsMBean");
MBeanInfo mBeanInfo = mbs.getMBeanInfo(oname);
// check implementation class:
assertEquals(MetricsMBeanImpl.class.getName(), mBeanInfo.getClassName());
// check reset operation:
MBeanOperationInfo[] oops = mBeanInfo.getOperations();
boolean resetFound = false;
for (MBeanOperationInfo op : oops) {
if ("reset".equals(op.getName())) {
resetFound = true;
break;
}
}
assertTrue(resetFound);
// add metric with a non-null value:
Attribute attr = new Attribute("fooMetric", Long.valueOf(-77));
mbs.setAttribute(oname, attr);
mBeanInfo = mbs.getMBeanInfo(oname);
MBeanAttributeInfo[] attrinuteInfos = mBeanInfo.getAttributes();
assertEquals(1, attrinuteInfos.length);
boolean attrFound = false;
for (MBeanAttributeInfo info : attrinuteInfos) {
if ("fooMetric".equals(info.getName())) {
assertEquals("java.lang.Long", info.getType());
assertTrue(info.isReadable());
assertTrue(info.isWritable());
assertFalse(info.isIs());
attrFound = true;
break;
}
}
assertTrue(attrFound);
// check metric value:
Object v = mbs.getAttribute(oname, "fooMetric");
assertEquals(Long.valueOf(-77), v);
// reset the bean:
Object result = mbs.invoke(oname, "reset", new Object[0], new String[0]);
assertNull(result);
// the metric value must be zeroed:
v = mbs.getAttribute(oname, "fooMetric");
assertEquals(Long.valueOf(0), v);
}
use of javax.management.MBeanInfo in project hive by apache.
the class MetricsMBeanImpl method getMBeanInfo.
@Override
public MBeanInfo getMBeanInfo() {
if (dirtyAttributeInfoCache) {
synchronized (metricsMap) {
attributeInfos = new MBeanAttributeInfo[metricsMap.size()];
int i = 0;
for (String key : metricsMap.keySet()) {
attributeInfos[i] = new MBeanAttributeInfo(key, metricsMap.get(key).getClass().getName(), key, true, true, /*writable*/
false);
i++;
}
dirtyAttributeInfoCache = false;
}
}
return new MBeanInfo(this.getClass().getName(), "metrics information", attributeInfos, ctors, ops, notifs);
}
use of javax.management.MBeanInfo in project jcollectd by collectd.
the class MBeanCollector method collect.
public void collect(MBeanQuery query, ObjectName name) throws Exception {
MBeanServerConnection conn = _sender.getMBeanServerConnection();
String plugin = query.getPlugin();
if (plugin == null) {
plugin = name.getDomain();
}
Map<String, MBeanAttributeInfo> attrInfo = null;
if (_useDescriptors) {
MBeanInfo info = conn.getMBeanInfo(name);
attrInfo = new HashMap<String, MBeanAttributeInfo>();
for (MBeanAttributeInfo ainfo : info.getAttributes()) {
attrInfo.put(ainfo.getName(), ainfo);
}
}
for (MBeanAttribute attr : query.getAttributes()) {
String attrName = attr.getAttributeName();
Object obj;
try {
obj = conn.getAttribute(name, attrName);
} catch (Exception e) {
//XXX remove attr for future collection e.g. UnsupportedOperation
continue;
}
if (_useDescriptors) {
//e.g. spring @ManagedMetric(metricType = MetricType.COUNTER)
try {
Descriptor descriptor = (Descriptor) _getDescriptor.invoke(attrInfo.get(attrName), (Object[]) null);
Object type = descriptor.getFieldValue(_metricTypeField);
if (TypesDB.NAME_COUNTER.equals(type)) {
if (attr.getTypeName().equals(TypesDB.NAME_GAUGE)) {
attr.setTypeName(TypesDB.NAME_COUNTER);
}
attr.setDataType(Network.DS_TYPE_COUNTER);
}
} catch (Exception e) {
}
}
if (obj instanceof CompositeData) {
CompositeData data = (CompositeData) obj;
String key = attr.getCompositeKey();
if (key == null) {
//no key specified; collect all
Set<String> keys = data.getCompositeType().keySet();
for (String ckey : keys) {
obj = data.get(ckey);
if (!isNumber(obj)) {
continue;
}
dispatch(query, plugin, attrName + "." + ckey, name, attr, (Number) obj);
}
continue;
} else {
obj = data.get(key);
}
}
if (!isNumber(obj)) {
continue;
}
dispatch(query, plugin, attr.getName(), name, attr, (Number) obj);
}
_sender.flush();
}
Aggregations