Java MBean getMBeanAttributes(final MBeanServer mBeanServer, final String objectNameString)

Here you can find the source of getMBeanAttributes(final MBeanServer mBeanServer, final String objectNameString)

Description

get M Bean Attributes

License

Apache License

Declaration

@SuppressWarnings("unchecked")
    public static Map<String, MBeanAttributeInfo[]> getMBeanAttributes(final MBeanServer mBeanServer,
            final String objectNameString) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.IOException;

import java.util.Map;
import java.util.Set;
import java.util.TreeMap;

import javax.management.InstanceNotFoundException;
import javax.management.IntrospectionException;
import javax.management.MBeanAttributeInfo;

import javax.management.MBeanInfo;
import javax.management.MBeanServer;
import javax.management.MBeanServerConnection;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
import javax.management.ReflectionException;

public class Main {
    @SuppressWarnings("unchecked")
    public static Map<String, MBeanAttributeInfo[]> getMBeanAttributes(final MBeanServer mBeanServer,
            final String objectNameString) {
        Map<String, MBeanAttributeInfo[]> attributesMap = null;
        Set<ObjectName> objectNames;
        try {/*from   w  w  w .j a v  a2s.  com*/
            objectNames = mBeanServer.queryNames(new ObjectName(objectNameString), null);
            attributesMap = new TreeMap<>();
            for (final ObjectName objectName : objectNames) {
                MBeanInfo mBeanInfo;
                mBeanInfo = mBeanServer.getMBeanInfo(objectName);
                final MBeanAttributeInfo[] attributes = mBeanInfo.getAttributes();
                attributesMap.put(objectName.getCanonicalName(), attributes);
            }
        } catch (final InstanceNotFoundException e) {
            e.printStackTrace();
        } catch (final IntrospectionException e) {
            e.printStackTrace();
        } catch (final ReflectionException e) {
            e.printStackTrace();
        } catch (final MalformedObjectNameException e) {
            e.printStackTrace();
        } catch (final NullPointerException e) {
            e.printStackTrace();
        }
        return attributesMap;
    }

    @SuppressWarnings("unchecked")
    public static Map<String, MBeanAttributeInfo[]> getMBeanAttributes(final MBeanServerConnection connection,
            final String objectNameString) {
        Map<String, MBeanAttributeInfo[]> attributesMap = null;
        Set<ObjectName> objectNames;
        try {
            objectNames = connection.queryNames(new ObjectName(objectNameString), null);
            attributesMap = new TreeMap<>();
            for (final ObjectName objectName : objectNames) {
                MBeanInfo mBeanInfo;
                mBeanInfo = connection.getMBeanInfo(objectName);
                final MBeanAttributeInfo[] attributes = mBeanInfo.getAttributes();
                attributesMap.put(objectName.getCanonicalName(), attributes);
            }
        } catch (final InstanceNotFoundException e) {
            e.printStackTrace();
        } catch (final IntrospectionException e) {
            e.printStackTrace();
        } catch (final ReflectionException e) {
            e.printStackTrace();
        } catch (final MalformedObjectNameException e) {
            e.printStackTrace();
        } catch (final NullPointerException e) {
            e.printStackTrace();
        } catch (final IOException e) {
            e.printStackTrace();
        }
        return attributesMap;
    }
}

Related

  1. getDynamicMBean(String mbeanName)
  2. getJmxNameInternal(final Class mBeanClass, final String name)
  3. getMatchingObjectNames(CharSequence wildcardEq, CharSequence wildcardWc, MBeanServerConnection conn)
  4. getMBeanAttribute(final MBeanServerConnection connection, final String nameString, final String attributeName)
  5. getMBeanAttributeMap(MBeanServerConnection server, ObjectName objectName, String delimeter, String... attributeNames)
  6. getMBeanAttributeValue(final MBeanServerConnection connection, final ObjectName objName, final String attributeName)
  7. getMBeanConnections(final Map connectors)
  8. getMBeanName(final String serviceName, final String nameName)
  9. getMbeans( final MBeanServerConnection mBeanServerConnection)