Search in sources :

Example 41 with MBeanInfo

use of javax.management.MBeanInfo in project spring-framework by spring-projects.

the class MBeanExporterOperationsTests method testRegisterExistingMBeanWithUserSuppliedObjectName.

@Test
public void testRegisterExistingMBeanWithUserSuppliedObjectName() throws Exception {
    ObjectName objectName = ObjectNameManager.getInstance("spring:name=Foo");
    ModelMBeanInfo info = new ModelMBeanInfoSupport("myClass", "myDescription", null, null, null, null);
    RequiredModelMBean bean = new RequiredModelMBean(info);
    MBeanExporter exporter = new MBeanExporter();
    exporter.setServer(getServer());
    exporter.registerManagedResource(bean, objectName);
    MBeanInfo infoFromServer = getServer().getMBeanInfo(objectName);
    assertEquals(info, infoFromServer);
}
Also used : ModelMBeanInfo(javax.management.modelmbean.ModelMBeanInfo) MBeanInfo(javax.management.MBeanInfo) ModelMBeanInfoSupport(javax.management.modelmbean.ModelMBeanInfoSupport) ModelMBeanInfo(javax.management.modelmbean.ModelMBeanInfo) ObjectName(javax.management.ObjectName) RequiredModelMBean(javax.management.modelmbean.RequiredModelMBean) Test(org.junit.Test)

Example 42 with MBeanInfo

use of javax.management.MBeanInfo in project cdap by caskdata.

the class OperationalStatsHttpHandler method getStats.

/**
   * Reads operational stats collected using the {@link OperationalStats} extension mechanism with the specified
   * property key and value, grouped by the specified groupByKey.
   *
   * @param propertyKey the key that must be contained with the specified value in the stat to be returned
   * @param propertyValue the value that the specified key must have in the stat to be returned
   * @param groupByKey an additional key in the stat's property to group the stats by
   * @return a {@link Map} of the group to a {@link Map} of stats of that group
   * @throws Exception when there are errors reading stats using JMX
   */
@VisibleForTesting
Map<String, Map<String, Object>> getStats(String propertyKey, String propertyValue, String groupByKey) throws Exception {
    Preconditions.checkArgument(!Strings.isNullOrEmpty(propertyKey), "Property should not be null or empty.");
    Preconditions.checkArgument(!Strings.isNullOrEmpty(propertyValue), "Property value should not be null or empty.");
    Hashtable<String, String> properties = new Hashtable<>();
    // we want stats with the specified value for the specified key, so set them in the properties
    properties.put(propertyKey, propertyValue);
    // since we want to group by the groupKey, we want to fetch all groups
    properties.put(groupByKey, "*");
    ObjectName objectName = new ObjectName(OperationalStatsUtils.JMX_DOMAIN, properties);
    Map<String, Map<String, Object>> result = new HashMap<>();
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    for (ObjectName name : mbs.queryNames(objectName, null)) {
        String group = name.getKeyProperty(groupByKey);
        MBeanInfo mBeanInfo = mbs.getMBeanInfo(name);
        Map<String, Object> stats = new HashMap<>();
        for (MBeanAttributeInfo attributeInfo : mBeanInfo.getAttributes()) {
            stats.put(attributeInfo.getName(), mbs.getAttribute(name, attributeInfo.getName()));
        }
        result.put(group, stats);
        LOG.trace("Found stats of group {} as {}", group, stats);
    }
    return result;
}
Also used : MBeanInfo(javax.management.MBeanInfo) HashMap(java.util.HashMap) Hashtable(java.util.Hashtable) HashMap(java.util.HashMap) Map(java.util.Map) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) ObjectName(javax.management.ObjectName) MBeanServer(javax.management.MBeanServer) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 43 with MBeanInfo

use of javax.management.MBeanInfo in project jdk8u_jdk by JetBrains.

the class XSheet method displayMBeanAttributesNode.

// Call on EDT
private void displayMBeanAttributesNode(final DefaultMutableTreeNode node) {
    final XNodeInfo uo = (XNodeInfo) node.getUserObject();
    if (!uo.getType().equals(Type.ATTRIBUTES)) {
        return;
    }
    mbean = (XMBean) uo.getData();
    final XMBean xmb = mbean;
    SwingWorker<MBeanInfo, Void> sw = new SwingWorker<MBeanInfo, Void>() {

        @Override
        public MBeanInfo doInBackground() throws InstanceNotFoundException, IntrospectionException, ReflectionException, IOException {
            MBeanInfo mbi = xmb.getMBeanInfo();
            return mbi;
        }

        @Override
        protected void done() {
            try {
                MBeanInfo mbi = get();
                if (mbi != null && mbi.getAttributes() != null && mbi.getAttributes().length > 0) {
                    mbeanAttributes.loadAttributes(xmb, mbi);
                    if (!isSelectedNode(node, currentNode)) {
                        return;
                    }
                    invalidate();
                    mainPanel.removeAll();
                    JPanel borderPanel = new JPanel(new BorderLayout());
                    borderPanel.setBorder(BorderFactory.createTitledBorder(Messages.ATTRIBUTE_VALUES));
                    borderPanel.add(new JScrollPane(mbeanAttributes));
                    mainPanel.add(borderPanel, BorderLayout.CENTER);
                    // add the refresh button to the south panel
                    southPanel.removeAll();
                    southPanel.add(refreshButton, BorderLayout.SOUTH);
                    southPanel.setVisible(true);
                    refreshButton.setEnabled(true);
                    validate();
                    repaint();
                }
            } catch (Exception e) {
                Throwable t = Utils.getActualException(e);
                if (JConsole.isDebug()) {
                    System.err.println("Problem displaying MBean " + "attributes for MBean [" + mbean.getObjectName() + "]");
                    t.printStackTrace();
                }
                showErrorDialog(t.toString(), Messages.PROBLEM_DISPLAYING_MBEAN);
            }
        }
    };
    sw.execute();
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) MBeanInfo(javax.management.MBeanInfo) BorderLayout(java.awt.BorderLayout) SwingWorker(javax.swing.SwingWorker) IntrospectionException(javax.management.IntrospectionException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ReflectionException(javax.management.ReflectionException) IOException(java.io.IOException)

Example 44 with MBeanInfo

use of javax.management.MBeanInfo in project jdk8u_jdk by JetBrains.

the class XSheet method displayMBeanNode.

// Call on EDT
private void displayMBeanNode(final DefaultMutableTreeNode node) {
    final XNodeInfo uo = (XNodeInfo) node.getUserObject();
    if (!uo.getType().equals(Type.MBEAN)) {
        return;
    }
    mbean = (XMBean) uo.getData();
    SwingWorker<MBeanInfo, Void> sw = new SwingWorker<MBeanInfo, Void>() {

        @Override
        public MBeanInfo doInBackground() throws InstanceNotFoundException, IntrospectionException, ReflectionException, IOException {
            return mbean.getMBeanInfo();
        }

        @Override
        protected void done() {
            try {
                MBeanInfo mbi = get();
                if (mbi != null) {
                    if (!isSelectedNode(node, currentNode)) {
                        return;
                    }
                    mbeanInfo.addMBeanInfo(mbean, mbi);
                    invalidate();
                    mainPanel.removeAll();
                    mainPanel.add(mbeanInfo, BorderLayout.CENTER);
                    southPanel.setVisible(false);
                    southPanel.removeAll();
                    validate();
                    repaint();
                }
            } catch (Exception e) {
                Throwable t = Utils.getActualException(e);
                if (JConsole.isDebug()) {
                    System.err.println("Couldn't get MBeanInfo for MBean [" + mbean.getObjectName() + "]");
                    t.printStackTrace();
                }
                showErrorDialog(t.toString(), Messages.PROBLEM_DISPLAYING_MBEAN);
            }
        }
    };
    sw.execute();
}
Also used : MBeanInfo(javax.management.MBeanInfo) SwingWorker(javax.swing.SwingWorker) IntrospectionException(javax.management.IntrospectionException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ReflectionException(javax.management.ReflectionException) IOException(java.io.IOException)

Example 45 with MBeanInfo

use of javax.management.MBeanInfo in project jdk8u_jdk by JetBrains.

the class StandardMBeanSupport method getMBeanInfo.

/* Standard MBeans that are NotificationBroadcasters can return a different
     * MBeanNotificationInfo[] every time getMBeanInfo() is called, so we have
     * to reconstruct this MBeanInfo if necessary.
     */
@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());
}
Also used : MBeanInfo(javax.management.MBeanInfo)

Aggregations

MBeanInfo (javax.management.MBeanInfo)154 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)87 ObjectName (javax.management.ObjectName)79 MBeanOperationInfo (javax.management.MBeanOperationInfo)38 MBeanServer (javax.management.MBeanServer)27 Test (org.junit.Test)27 Attribute (javax.management.Attribute)19 ArrayList (java.util.ArrayList)17 IntrospectionException (javax.management.IntrospectionException)16 ReflectionException (javax.management.ReflectionException)16 HashMap (java.util.HashMap)15 InstanceNotFoundException (javax.management.InstanceNotFoundException)15 IOException (java.io.IOException)12 MBeanNotificationInfo (javax.management.MBeanNotificationInfo)12 MBeanParameterInfo (javax.management.MBeanParameterInfo)12 MBeanServerConnection (javax.management.MBeanServerConnection)10 MalformedObjectNameException (javax.management.MalformedObjectNameException)10 AttributeList (javax.management.AttributeList)9 AttributeNotFoundException (javax.management.AttributeNotFoundException)9 Descriptor (javax.management.Descriptor)8