MBeanHelper { public Map<String, String> get(ObjectName bean, Collection<String> attrs) throws Exception { Map<String, MBeanAttributeInfo> attrInfos = getAttributeInfos(bean, attrs, true, false); Map<String, Object> attrRawValues = getAttributes(bean, attrs); Map<String, String> attrValues = new HashMap<String, String>(attrs.size()); for(String attr: attrs) { String attrValue = format(attrRawValues.get(attr), attrInfos.get(attr).getType()); attrValues.put(attr, attrValue); } return attrValues; } MBeanHelper(MBeanServerConnection connection); void setFormatingOption(String name, Object value); Map<String, String> get(ObjectName bean, Collection<String> attrs); void getAsTable(ObjectName bean, Collection<String> attrs, MTable table); void set(ObjectName bean, String attr, String value); String invoke(ObjectName bean, String operation, String... params); String describe(ObjectName bean); static String FORMAT_TABLE_COLUMN_WIDTH_THRESHOLD; static String FORMAT_COMPOSITE_FIELD_WIDTH_THRESHODL; }
@Test public void test_get_vm_spec_infos() throws Exception { MBeanHelper helper = new MBeanHelper(ManagementFactory.getPlatformMBeanServer()); Map<String, String> attrs = helper.get(runtimeMXBean(), Arrays.asList("SpecName", "SpecVendor", "SpecVersion")); System.out.println(attrs); assertThat(attrs).containsKeys("SpecName", "SpecVendor", "SpecVersion"); }
@Test public void test_get_sys_props() throws Exception { MBeanHelper helper = new MBeanHelper(ManagementFactory.getPlatformMBeanServer()); System.out.println(helper.get(runtimeMXBean(), Collections.singletonList("SystemProperties"))); }
@Test public void test_get_mem_heap() throws Exception { MBeanHelper helper = new MBeanHelper(ManagementFactory.getPlatformMBeanServer()); System.out.println(helper.get(memoryMXBean(), Collections.singletonList("HeapMemoryUsage"))); }