Java Code Examples for javax.management.MBeanInfo#getOperations()
The following examples show how to use
javax.management.MBeanInfo#getOperations() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MBeanIntrospector.java From jdk1.8-source-analysis with Apache License 2.0 | 6 votes |
/** * Return the MBeanInfo for the given resource, based on the given * per-interface data. */ final MBeanInfo getMBeanInfo(Object resource, PerInterface<M> perInterface) { MBeanInfo mbi = getClassMBeanInfo(resource.getClass(), perInterface); MBeanNotificationInfo[] notifs = findNotifications(resource); if (notifs == null || notifs.length == 0) return mbi; else { return new MBeanInfo(mbi.getClassName(), mbi.getDescription(), mbi.getAttributes(), mbi.getConstructors(), mbi.getOperations(), notifs, mbi.getDescriptor()); } }
Example 2
Source File: JmxSupport.java From visualvm with GNU General Public License v2.0 | 6 votes |
private boolean hasDumpAllThreads() { synchronized (hasDumpAllThreadsLock) { if (hasDumpAllThreads == null) { hasDumpAllThreads = Boolean.FALSE; try { ObjectName threadObjName = new ObjectName(ManagementFactory.THREAD_MXBEAN_NAME); MBeanInfo threadInfo = jmxModel.getMBeanServerConnection().getMBeanInfo(threadObjName); if (threadInfo != null) { for (MBeanOperationInfo op : threadInfo.getOperations()) { if ("dumpAllThreads".equals(op.getName())) { hasDumpAllThreads = Boolean.TRUE; } } } } catch (Exception ex) { LOGGER.log(Level.INFO,"hasDumpAllThreads", ex); // NOI18N } } return hasDumpAllThreads.booleanValue(); } }
Example 3
Source File: MXBeanInteropTest2.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
private void printMBeanInfo(MBeanInfo mbInfo) { System.out.println("Description " + mbInfo.getDescription()); for (MBeanConstructorInfo ctor : mbInfo.getConstructors()) { System.out.println("Constructor " + ctor.getName()); } for (MBeanAttributeInfo att : mbInfo.getAttributes()) { System.out.println("Attribute " + att.getName() + " [" + att.getType() + "]"); } for (MBeanOperationInfo oper : mbInfo.getOperations()) { System.out.println("Operation " + oper.getName()); } for (MBeanNotificationInfo notif : mbInfo.getNotifications()) { System.out.println("Notification " + notif.getName()); } }
Example 4
Source File: MXBeanInteropTest2.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
private void printMBeanInfo(MBeanInfo mbInfo) { System.out.println("Description " + mbInfo.getDescription()); for (MBeanConstructorInfo ctor : mbInfo.getConstructors()) { System.out.println("Constructor " + ctor.getName()); } for (MBeanAttributeInfo att : mbInfo.getAttributes()) { System.out.println("Attribute " + att.getName() + " [" + att.getType() + "]"); } for (MBeanOperationInfo oper : mbInfo.getOperations()) { System.out.println("Operation " + oper.getName()); } for (MBeanNotificationInfo notif : mbInfo.getNotifications()) { System.out.println("Notification " + notif.getName()); } }
Example 5
Source File: MBeanIntrospector.java From hottub with GNU General Public License v2.0 | 6 votes |
/** * Return the MBeanInfo for the given resource, based on the given * per-interface data. */ final MBeanInfo getMBeanInfo(Object resource, PerInterface<M> perInterface) { MBeanInfo mbi = getClassMBeanInfo(resource.getClass(), perInterface); MBeanNotificationInfo[] notifs = findNotifications(resource); if (notifs == null || notifs.length == 0) return mbi; else { return new MBeanInfo(mbi.getClassName(), mbi.getDescription(), mbi.getAttributes(), mbi.getConstructors(), mbi.getOperations(), notifs, mbi.getDescriptor()); } }
Example 6
Source File: MBeanIntrospector.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
/** * Return the MBeanInfo for the given resource, based on the given * per-interface data. */ final MBeanInfo getMBeanInfo(Object resource, PerInterface<M> perInterface) { MBeanInfo mbi = getClassMBeanInfo(resource.getClass(), perInterface); MBeanNotificationInfo[] notifs = findNotifications(resource); if (notifs == null || notifs.length == 0) return mbi; else { return new MBeanInfo(mbi.getClassName(), mbi.getDescription(), mbi.getAttributes(), mbi.getConstructors(), mbi.getOperations(), notifs, mbi.getDescriptor()); } }
Example 7
Source File: StandardMBeanSupport.java From JDKSourceCode1.8 with MIT License | 5 votes |
@Override public MBeanInfo getMBeanInfo() { MBeanInfo mbi = super.getMBeanInfo(); Class<?> resourceClass = getResource().getClass(); if (StandardMBeanIntrospector.isDefinitelyImmutableInfo(resourceClass)) return mbi; return new MBeanInfo(mbi.getClassName(), mbi.getDescription(), mbi.getAttributes(), mbi.getConstructors(), mbi.getOperations(), MBeanIntrospector.findNotifications(getResource()), mbi.getDescriptor()); }
Example 8
Source File: DynamicMBeanFactoryOperationsTest.java From datakernel with Apache License 2.0 | 5 votes |
@Test public void itShouldCollectInformationAbountJMXOperationsToMBeanInfo() { BeanStubWithOperations bean = new BeanStubWithOperations(); DynamicMBean mbean = DynamicMBeanFactory.create() .createDynamicMBean(singletonList(bean), defaultSettings(), false); MBeanInfo mBeanInfo = mbean.getMBeanInfo(); MBeanOperationInfo[] operations = mBeanInfo.getOperations(); Map<String, MBeanOperationInfo> nameToOperation = new HashMap<>(); for (MBeanOperationInfo operation : operations) { nameToOperation.put(operation.getName(), operation); } assertThat(nameToOperation, hasKey("increment")); assertThat(nameToOperation, hasKey("addInfo")); assertThat(nameToOperation, hasKey("multiplyAndAdd")); MBeanOperationInfo incrementOperation = nameToOperation.get("increment"); MBeanOperationInfo addInfoOperation = nameToOperation.get("addInfo"); MBeanOperationInfo multiplyAndAddOperation = nameToOperation.get("multiplyAndAdd"); assertThat(incrementOperation, hasReturnType("void")); assertThat(addInfoOperation, hasParameter("information", String.class.getName())); assertThat(addInfoOperation, hasReturnType("void")); // parameter names are not annotated assertThat(multiplyAndAddOperation, hasParameter("arg0", "long")); assertThat(multiplyAndAddOperation, hasParameter("arg1", "long")); assertThat(multiplyAndAddOperation, hasReturnType("void")); }
Example 9
Source File: StandardMBeanSupport.java From hottub with GNU General Public License v2.0 | 5 votes |
@Override public MBeanInfo getMBeanInfo() { MBeanInfo mbi = super.getMBeanInfo(); Class<?> resourceClass = getResource().getClass(); if (StandardMBeanIntrospector.isDefinitelyImmutableInfo(resourceClass)) return mbi; return new MBeanInfo(mbi.getClassName(), mbi.getDescription(), mbi.getAttributes(), mbi.getConstructors(), mbi.getOperations(), MBeanIntrospector.findNotifications(getResource()), mbi.getDescriptor()); }
Example 10
Source File: AnnotationTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private static void check(MBeanServer mbs, ObjectName on) throws Exception { MBeanInfo mbi = mbs.getMBeanInfo(on); // check the MBean itself check(mbi); // check attributes MBeanAttributeInfo[] attrs = mbi.getAttributes(); for (MBeanAttributeInfo attr : attrs) { check(attr); if (attr.getName().equals("ReadOnly")) check("@Full", attr.getDescriptor(), expectedFullDescriptor); } // check operations MBeanOperationInfo[] ops = mbi.getOperations(); for (MBeanOperationInfo op : ops) { check(op); check(op.getSignature()); } MBeanConstructorInfo[] constrs = mbi.getConstructors(); for (MBeanConstructorInfo constr : constrs) { check(constr); check(constr.getSignature()); } }
Example 11
Source File: StandardMBeanSupport.java From jdk1.8-source-analysis with Apache License 2.0 | 5 votes |
@Override public MBeanInfo getMBeanInfo() { MBeanInfo mbi = super.getMBeanInfo(); Class<?> resourceClass = getResource().getClass(); if (StandardMBeanIntrospector.isDefinitelyImmutableInfo(resourceClass)) return mbi; return new MBeanInfo(mbi.getClassName(), mbi.getDescription(), mbi.getAttributes(), mbi.getConstructors(), mbi.getOperations(), MBeanIntrospector.findNotifications(getResource()), mbi.getDescriptor()); }
Example 12
Source File: DcmdMBeanTest.java From hottub with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { System.out.println("--->JRCMD MBean Test: invocation on \"operation info\"..."); MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); JMXServiceURL url = new JMXServiceURL("rmi", null, 0); JMXConnectorServer cs = null; JMXConnector cc = null; try { cs = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs); cs.start(); JMXServiceURL addr = cs.getAddress(); cc = JMXConnectorFactory.connect(addr); MBeanServerConnection mbsc = cc.getMBeanServerConnection(); ObjectName name = new ObjectName(HOTSPOT_DIAGNOSTIC_MXBEAN_NAME); MBeanInfo info = mbsc.getMBeanInfo(name); // the test should check that the MBean doesn't have any // Attribute, notification or constructor. Current version only // check operations System.out.println("Class Name:" + info.getClassName()); System.out.println("Description:" + info.getDescription()); MBeanOperationInfo[] opInfo = info.getOperations(); System.out.println("Operations:"); for (int i = 0; i < opInfo.length; i++) { printOperation(opInfo[i]); System.out.println("\n@@@@@@\n"); } } finally { try { cc.close(); cs.stop(); } catch (Exception e) { } } System.out.println("Test passed"); }
Example 13
Source File: DcmdMBeanTest.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { System.out.println("--->JRCMD MBean Test: invocation on \"operation info\"..."); MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); JMXServiceURL url = new JMXServiceURL("rmi", null, 0); JMXConnectorServer cs = null; JMXConnector cc = null; try { cs = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs); cs.start(); JMXServiceURL addr = cs.getAddress(); cc = JMXConnectorFactory.connect(addr); MBeanServerConnection mbsc = cc.getMBeanServerConnection(); ObjectName name = new ObjectName(HOTSPOT_DIAGNOSTIC_MXBEAN_NAME); MBeanInfo info = mbsc.getMBeanInfo(name); // the test should check that the MBean doesn't have any // Attribute, notification or constructor. Current version only // check operations System.out.println("Class Name:" + info.getClassName()); System.out.println("Description:" + info.getDescription()); MBeanOperationInfo[] opInfo = info.getOperations(); System.out.println("Operations:"); for (int i = 0; i < opInfo.length; i++) { printOperation(opInfo[i]); System.out.println("\n@@@@@@\n"); } } finally { try { cc.close(); cs.stop(); } catch (Exception e) { } } System.out.println("Test passed"); }
Example 14
Source File: DcmdMBeanTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { System.out.println("--->JRCMD MBean Test: invocation on \"operation info\"..."); MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); JMXServiceURL url = new JMXServiceURL("rmi", null, 0); JMXConnectorServer cs = null; JMXConnector cc = null; try { cs = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs); cs.start(); JMXServiceURL addr = cs.getAddress(); cc = JMXConnectorFactory.connect(addr); MBeanServerConnection mbsc = cc.getMBeanServerConnection(); ObjectName name = new ObjectName(HOTSPOT_DIAGNOSTIC_MXBEAN_NAME); MBeanInfo info = mbsc.getMBeanInfo(name); // the test should check that the MBean doesn't have any // Attribute, notification or constructor. Current version only // check operations System.out.println("Class Name:" + info.getClassName()); System.out.println("Description:" + info.getDescription()); MBeanOperationInfo[] opInfo = info.getOperations(); System.out.println("Operations:"); for (int i = 0; i < opInfo.length; i++) { printOperation(opInfo[i]); System.out.println("\n@@@@@@\n"); } } finally { try { cc.close(); cs.stop(); } catch (Exception e) { } } System.out.println("Test passed"); }
Example 15
Source File: DcmdMBeanTest.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { System.out.println("--->JRCMD MBean Test: invocation on \"operation info\"..."); MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); JMXServiceURL url = new JMXServiceURL("rmi", null, 0); JMXConnectorServer cs = null; JMXConnector cc = null; try { cs = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs); cs.start(); JMXServiceURL addr = cs.getAddress(); cc = JMXConnectorFactory.connect(addr); MBeanServerConnection mbsc = cc.getMBeanServerConnection(); ObjectName name = new ObjectName(HOTSPOT_DIAGNOSTIC_MXBEAN_NAME); MBeanInfo info = mbsc.getMBeanInfo(name); // the test should check that the MBean doesn't have any // Attribute, notification or constructor. Current version only // check operations System.out.println("Class Name:" + info.getClassName()); System.out.println("Description:" + info.getDescription()); MBeanOperationInfo[] opInfo = info.getOperations(); System.out.println("Operations:"); for (int i = 0; i < opInfo.length; i++) { printOperation(opInfo[i]); System.out.println("\n@@@@@@\n"); } } finally { try { cc.close(); cs.stop(); } catch (Exception e) { } } System.out.println("Test passed"); }
Example 16
Source File: AnnotationTest.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
private static void check(MBeanServer mbs, ObjectName on) throws Exception { MBeanInfo mbi = mbs.getMBeanInfo(on); // check the MBean itself check(mbi); // check attributes MBeanAttributeInfo[] attrs = mbi.getAttributes(); for (MBeanAttributeInfo attr : attrs) { check(attr); if (attr.getName().equals("ReadOnly")) check("@Full", attr.getDescriptor(), expectedFullDescriptor); } // check operations MBeanOperationInfo[] ops = mbi.getOperations(); for (MBeanOperationInfo op : ops) { check(op); check(op.getSignature()); } MBeanConstructorInfo[] constrs = mbi.getConstructors(); for (MBeanConstructorInfo constr : constrs) { check(constr); check(constr.getSignature()); } }
Example 17
Source File: LocalProcessControllerJUnitTest.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
public void testProcessMBean() throws Exception { final String testName = "testProcessMBean"; final int pid = ProcessUtils.identifyPid(); final Process process = new Process(pid, true); final ObjectName objectName = ObjectName.getInstance( getClass().getSimpleName() + ":testName=" + testName); final MBeanServer server = ManagementFactory.getPlatformMBeanServer(); final ObjectInstance instance = server.registerMBean(process, objectName); assertNotNull(instance); try { // validate basics of the ProcessMBean Set<ObjectName> mbeanNames = server.queryNames(objectName, null); assertFalse("Zero matching mbeans", mbeanNames.isEmpty()); assertEquals(1, mbeanNames.size()); final ObjectName name = mbeanNames.iterator().next(); final MBeanInfo info = server.getMBeanInfo(name); final MBeanOperationInfo[] operInfo = info.getOperations(); assertEquals(1, operInfo.length); assertEquals("stop", operInfo[0].getName()); final MBeanAttributeInfo[] attrInfo = info.getAttributes(); assertEquals(2, attrInfo.length); // The order of these attributes is indeterminate // assertEquals("Pid", attrInfo[0].getName()); // assertEquals("Process", attrInfo[1].getName()); assertNotNull(server.getAttribute(name, "Pid")); assertNotNull(server.getAttribute(name, "Process")); assertEquals(pid, server.getAttribute(name, "Pid")); assertEquals(true, server.getAttribute(name, "Process")); // validate query using only Pid attribute QueryExp constraint = Query.eq( Query.attr("Pid"), Query.value(pid)); mbeanNames = server.queryNames(objectName, constraint); assertFalse("Zero matching mbeans", mbeanNames.isEmpty()); // validate query with wrong Pid finds nothing constraint = Query.eq( Query.attr("Pid"), Query.value(pid+1)); mbeanNames = server.queryNames(objectName, constraint); assertTrue("Found matching mbeans", mbeanNames.isEmpty()); // validate query using both attributes constraint = Query.and( Query.eq(Query.attr("Process"),Query.value(true)), Query.eq(Query.attr("Pid"),Query.value(pid))); mbeanNames = server.queryNames(objectName, constraint); assertFalse("Zero matching mbeans", mbeanNames.isEmpty()); // validate query with wrong attribute finds nothing constraint = Query.and( Query.eq(Query.attr("Process"),Query.value(false)), Query.eq(Query.attr("Pid"),Query.value(pid))); mbeanNames = server.queryNames(objectName, constraint); assertTrue("Found matching mbeans", mbeanNames.isEmpty()); } finally { try { server.unregisterMBean(objectName); } catch (Throwable t) { t.printStackTrace(); } } }
Example 18
Source File: TooManyFooTest.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
private static void test(Object child, String name, boolean mxbean) throws Exception { final ObjectName childName = new ObjectName("test:type=Child,name="+name); final MBeanServer server = ManagementFactory.getPlatformMBeanServer(); server.registerMBean(child,childName); try { final MBeanInfo info = server.getMBeanInfo(childName); System.out.println(name+": " + info.getDescriptor()); final int len = info.getOperations().length; if (len == OPCOUNT) { System.out.println(name+": OK, only "+OPCOUNT+ " operations here..."); } else { final String qual = (len>OPCOUNT)?"many":"few"; System.err.println(name+": Too "+qual+" foos! Found "+ len+", expected "+OPCOUNT); for (MBeanOperationInfo op : info.getOperations()) { System.err.println("public "+op.getReturnType()+" "+ op.getName()+"();"); } throw new RuntimeException("Too " + qual + " foos for "+name); } final Descriptor d = info.getDescriptor(); final String mxstr = String.valueOf(d.getFieldValue("mxbean")); final boolean mxb = (mxstr==null)?false:Boolean.valueOf(mxstr).booleanValue(); System.out.println(name+": mxbean="+mxb); if (mxbean && !mxb) throw new AssertionError("MXBean is not OpenMBean?"); for (MBeanOperationInfo mboi : info.getOperations()) { // Sanity check if (mxbean && !mboi.getName().equals("foo")) { // The spec doesn't guarantee that the MBeanOperationInfo // of an MXBean will be an OpenMBeanOperationInfo, and in // some circumstances in our implementation it will not. // However, in thsi tests, for all methods but foo(), // it should. // if (!(mboi instanceof OpenMBeanOperationInfo)) throw new AssertionError("Operation "+mboi.getName()+ "() is not Open?"); } final String exp = EXPECTED_TYPES.get(mboi.getName()); // For MXBeans, we need to compare 'exp' with the original // type - because mboi.getReturnType() returns the OpenType // String type = (String)mboi.getDescriptor(). getFieldValue("originalType"); if (type == null) type = mboi.getReturnType(); if (type.equals(exp)) continue; System.err.println("Bad return type for "+ mboi.getName()+"! Found "+type+ ", expected "+exp); throw new RuntimeException("Bad return type for "+ mboi.getName()); } } finally { server.unregisterMBean(childName); } }
Example 19
Source File: MBeanInfoRenderer.java From text-ui with GNU General Public License v3.0 | 4 votes |
@Override public LineRenderer renderer(Iterator<MBeanInfo> stream) { List<LineRenderer> renderers = new ArrayList<LineRenderer>(); while (stream.hasNext()) { MBeanInfo info = stream.next(); // TreeElement root = new TreeElement(info.getClassName()); // Descriptor TableElement descriptor = new TableElement(). overflow(Overflow.HIDDEN). rightCellPadding(1); Descriptor descriptorInfo = info.getDescriptor(); if (descriptorInfo != null) { for (String fieldName : descriptorInfo.getFieldNames()) { String fieldValue = String.valueOf(descriptorInfo.getFieldValue(fieldName)); descriptor.row(fieldName, fieldValue); } } // Attributes TableElement attributes = new TableElement(). overflow(Overflow.HIDDEN). rightCellPadding(1). add(new RowElement().style(Decoration.bold.fg(Color.black).bg(Color.white)).add("NAME", "TYPE", "DESCRIPTION")); for (MBeanAttributeInfo attributeInfo : info.getAttributes()) { attributes.row(attributeInfo.getName(), attributeInfo.getType(), attributeInfo.getDescription()); } // Operations TreeElement operations = new TreeElement("Operations"); for (MBeanOperationInfo operationInfo : info.getOperations()) { TableElement signature = new TableElement(). overflow(Overflow.HIDDEN). rightCellPadding(1); MBeanParameterInfo[] parameterInfos = operationInfo.getSignature(); for (MBeanParameterInfo parameterInfo : parameterInfos) { signature.row(parameterInfo.getName(), parameterInfo.getType(), parameterInfo.getDescription()); } TreeElement operation = new TreeElement(operationInfo.getName()); String impact; switch (operationInfo.getImpact()) { case MBeanOperationInfo.ACTION: impact = "ACTION"; break; case MBeanOperationInfo.INFO: impact = "INFO"; break; case MBeanOperationInfo.ACTION_INFO: impact = "ACTION_INFO"; break; default: impact = "UNKNOWN"; } operation.addChild(new TableElement(). add( new RowElement().add("Type: ", operationInfo.getReturnType()), new RowElement().add("Description: ", operationInfo.getDescription()), new RowElement().add("Impact: ", impact), new RowElement().add(new LabelElement("Signature: "), signature) ) ); operations.addChild(operation); } // root.addChild( new TableElement().leftCellPadding(1).overflow(Overflow.HIDDEN). row("ClassName", info.getClassName()). row("Description", info.getDescription() ) ); root.addChild(new TreeElement("Descriptor").addChild(descriptor)); root.addChild(new TreeElement("Attributes").addChild(attributes)); root.addChild(operations); // renderers.add(root.renderer()); } return LineRenderer.vertical(renderers); }
Example 20
Source File: JmxService.java From karyon with Apache License 2.0 | 2 votes |
/** * Return all operations for the specified mbean name * @param name * @return * @throws Exception */ public MBeanOperationInfo[] getMBeanOperations(String name) throws Exception { MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer(); MBeanInfo mBeanInfo = mBeanServer.getMBeanInfo(new ObjectName(name)); return mBeanInfo.getOperations(); }