MBeanHelper { public String invoke(ObjectName bean, String operation, String... params) throws InstanceNotFoundException, IntrospectionException, ReflectionException, IOException, MBeanException { MBeanInfo mbinfo = mserver.getMBeanInfo(bean); MBeanOperationInfo op = null; for(MBeanOperationInfo oi: mbinfo.getOperations()) { if (oi.getName().equalsIgnoreCase(operation) && oi.getSignature().length == params.length) { if (op != null) { throw new IllegalArgumentException("Ambiguous " + operation + "/" + params.length + " operatition signature for " + bean); } op = oi; } } if (op == null) { throw new IllegalArgumentException("Operation " + operation + "/" + params.length + " not found for " + bean); } Object[] args = new Object[params.length]; String[] sig = new String[params.length]; for(int i = 0; i != params.length; ++i) { args[i] = convert(params[i], op.getSignature()[i].getType()); sig[i] = op.getSignature()[i].getType(); } return format(mserver.invoke(bean, op.getName(), args, sig), op.getReturnType()); } 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_thread_dump() throws Exception { MBeanHelper helper = new MBeanHelper(ManagementFactory.getPlatformMBeanServer()); System.out.println(helper.invoke(threadMXBean(), "dumpAllThreads", "true", "true")); }
@Test public void test_find_deadlocked_threads() throws Exception { MBeanHelper helper = new MBeanHelper(ManagementFactory.getPlatformMBeanServer()); System.out.println(helper.invoke(threadMXBean(), "findMonitorDeadlockedThreads")); }