Java Utililty Methods MBean

List of utility methods to do MBean

Description

The list of methods to do MBean are organized into topic(s).

Method

ClassgetClassFromInfo(MBeanAttributeInfo attributeInfo)
get Class From Info
return getClassFromInfo(attributeInfo.getType());
ObjectgetCompatibleData(Object object, MBeanParameterInfo beanParameterInfo)
get Compatible Data
return tryParseToType(object, getClassFromInfo(beanParameterInfo.getType()));
StringgetDescription(MBeanFeatureInfo element)
get Description
String desc = element.getDescription();
return desc != null && desc.equals(element.getName()) ? null : desc; 
ObjectNamegetDynamicMBean(String mbeanName)
get Dynamic M Bean
return new ObjectName(mbeanName);
ObjectNamegetJmxNameInternal(final Class mBeanClass, final String name)
get Jmx Name Internal
return new ObjectName(
        mBeanClass.getPackage().getName() + ":type=" + mBeanClass.getSimpleName() + ",name=" + name);
SetgetMatchingObjectNames(CharSequence wildcardEq, CharSequence wildcardWc, MBeanServerConnection conn)
Returns a set of ObjectNames matching the passed wildcard object names
ObjectName wildcardEquals = objectName(wildcardEq);
ObjectName wildcard = objectName(wildcardWc);
final String wc = new StringBuilder("(").append(wildcardEquals).append("$)").toString();
Set<ObjectName> names = new HashSet<ObjectName>();
Map<String, Pattern> wildcardQueryProps = new HashMap<String, Pattern>();
Hashtable<String, String> wildcardProps = objectName(wildcard).getKeyPropertyList();
Hashtable<String, String> queryProps = new Hashtable<String, String>();
queryProps.putAll(wildcardProps);
...
MBeanAttributeInfogetMBeanAttribute(final MBeanServerConnection connection, final String nameString, final String attributeName)
get M Bean Attribute
MBeanAttributeInfo attribute = null;
ObjectName objectName;
try {
    objectName = new ObjectName(nameString);
    MBeanInfo mBeanInfo;
    mBeanInfo = connection.getMBeanInfo(objectName);
    final MBeanAttributeInfo[] attributes = mBeanInfo.getAttributes();
    for (final MBeanAttributeInfo thisAttribute : attributes) {
...
Map>getMBeanAttributeMap(MBeanServerConnection server, ObjectName objectName, String delimeter, String... attributeNames)
Retrieves maps of attribute values keyed by attribute name, in turn keyed by the ObjectName of the MBean.
if (server == null)
    throw new RuntimeException("MBeanServerConnection was null", new Throwable());
if (objectName == null)
    throw new RuntimeException("ObjectName was null", new Throwable());
if (attributeNames == null || attributeNames.length < 1)
    throw new RuntimeException("Attribute names array was null or zero length", new Throwable());
String[] rootNames = new String[attributeNames.length];
Map<String, String> compoundNames = new HashMap<String, String>();
...
MapgetMBeanAttributes(final MBeanServer mBeanServer, final String objectNameString)
get M Bean Attributes
Map<String, MBeanAttributeInfo[]> attributesMap = null;
Set<ObjectName> objectNames;
try {
    objectNames = mBeanServer.queryNames(new ObjectName(objectNameString), null);
    attributesMap = new TreeMap<>();
    for (final ObjectName objectName : objectNames) {
        MBeanInfo mBeanInfo;
        mBeanInfo = mBeanServer.getMBeanInfo(objectName);
...
ObjectgetMBeanAttributeValue(final MBeanServerConnection connection, final ObjectName objName, final String attributeName)
get M Bean Attribute Value
Object attributeValue = "Unavailable";
try {
    attributeValue = connection.getAttribute(objName, attributeName);
} catch (final AttributeNotFoundException e) {
} catch (final MBeanException e) {
} catch (final InstanceNotFoundException e) {
} catch (final ReflectionException e) {
} catch (final IOException e) {
...