public static void copyAllAttributes(ObjectName on, JsonObject targetObject) {
try {
MBeanInfo mbi = mbs.getMBeanInfo(on);
for (MBeanAttributeInfo mbai : mbi.getAttributes()) {
Object attValue = mbs.getAttribute(on, mbai.getName());
if (attValue instanceof Boolean) {
targetObject.addProperty(mbai.getName(), (Boolean) attValue);
} else if (attValue instanceof Character) {
targetObject.addProperty(mbai.getName(), (Character) attValue);
} else if (attValue instanceof Number) {
targetObject.addProperty(mbai.getName(), (Number) attValue);
} else if (attValue instanceof String) {
targetObject.addProperty(mbai.getName(), (String) attValue);
} else {
targetObject.addProperty("OBJECT:" + mbai.getName(), attValue != null ? attValue.toString() : "null");
}
}
} catch (InstanceNotFoundException | IntrospectionException | ReflectionException | AttributeNotFoundException
| MBeanException e) {
log.error("Failed to query mbean", e);
}
}
MBeanService.java 文件源码
java
阅读 26
收藏 0
点赞 0
评论 0
项目:lunchy
作者:
评论列表
文章目录