MBeanHelper { public String describe(ObjectName bean) throws Exception { MBeanInfo mbinfo = mserver.getMBeanInfo(bean); StringBuilder sb = new StringBuilder(); sb.append(bean); sb.append('\n'); sb.append(mbinfo.getClassName()); sb.append('\n'); sb.append(" - " + mbinfo.getDescription()); sb.append('\n'); for(MBeanAttributeInfo ai: mbinfo.getAttributes()) { sb.append(" (A) "); sb.append(ai.getName()).append(" : ").append(toPrintableType(ai.getType())).append(""); if (!ai.isReadable()) { sb.append(" - WRITEONLY"); } else if (ai.isWritable()) { sb.append(" - WRITEABLE"); } sb.append('\n'); if (!ai.getName().equals(ai.getDescription())) { sb.append(" - " + ai.getDescription()); sb.append('\n'); } } for (MBeanOperationInfo oi: mbinfo.getOperations()) { sb.append(" (O) "); sb.append(oi.getName()).append("("); for(MBeanParameterInfo pi: oi.getSignature()) { String name = pi.getName(); String type = toPrintableType(pi.getType()); sb.append(type).append(' ').append(name).append(", "); } if (oi.getSignature().length > 0) { sb.setLength(sb.length() - 2); } sb.append(") : ").append(toPrintableType(oi.getReturnType())); sb.append('\n'); if (!oi.getName().equals(oi.getDescription())) { sb.append(" - " + oi.getDescription()); sb.append('\n'); } } return sb.toString(); } 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_thread_bean_describer() throws Exception { MBeanHelper helper = new MBeanHelper(ManagementFactory.getPlatformMBeanServer()); System.out.println(helper.describe(threadMXBean())); }
@Test public void test_os_bean_describer() throws Exception { MBeanHelper helper = new MBeanHelper(ManagementFactory.getPlatformMBeanServer()); System.out.println(helper.describe(osMXBean())); }
@Test public void test_memory_bean_describer() throws Exception { MBeanHelper helper = new MBeanHelper(ManagementFactory.getPlatformMBeanServer()); System.out.println(helper.describe(memoryMXBean())); }
@Test public void test_runtime_bean_describer() throws Exception { MBeanHelper helper = new MBeanHelper(ManagementFactory.getPlatformMBeanServer()); System.out.println(helper.describe(runtimeMXBean())); }
@Test public void test_management_bean_describer() throws Exception { MBeanHelper helper = new MBeanHelper(ManagementFactory.getPlatformMBeanServer()); System.out.println(helper.describe(managementMXBean())); }