Search in sources :

Example 71 with MBeanInfo

use of javax.management.MBeanInfo in project Payara by payara.

the class ToolsImpl method info.

public String info(final Collection<ObjectName> objectNames) {
    final Set<String> alreadyDone = new HashSet<String>();
    final StringBuffer buf = new StringBuffer();
    if (objectNames.size() != 0) {
        final String NL = StringUtil.NEWLINE();
        for (final ObjectName objectName : objectNames) {
            final MBeanInfo mbeanInfo = getProxyFactory().getMBeanInfo(objectName);
            if (mbeanInfo == null) {
                continue;
            }
            // Don't generate info if we've seen that type/class combination already
            final String type = Util.getTypeProp(objectName);
            final String classname = mbeanInfo.getClassName();
            if (alreadyDone.contains(type) && alreadyDone.contains(classname)) {
                continue;
            }
            alreadyDone.add(type);
            alreadyDone.add(classname);
            buf.append("MBeanInfo for " + objectName + NL);
            // buf.append(JMXUtil.toString(mbeanInfo) + NL + NL );
            buf.append(java(objectName));
            buf.append(NL + NL + NL + NL);
        }
    }
    buf.append("Matched " + objectNames.size() + " mbean(s).");
    return buf.toString();
}
Also used : MBeanInfo(javax.management.MBeanInfo) HashSet(java.util.HashSet) ObjectName(javax.management.ObjectName)

Example 72 with MBeanInfo

use of javax.management.MBeanInfo in project Payara by payara.

the class MBeanInfoStringifier method stringify.

public String stringify(Object o) {
    String result = "";
    final MBeanInfo info = (MBeanInfo) o;
    final MBeanOperationInfo[] operations = info.getOperations();
    final MBeanAttributeInfo[] attributes = info.getAttributes();
    final MBeanConstructorInfo[] constructors = info.getConstructors();
    final MBeanNotificationInfo[] notifications = info.getNotifications();
    final String description = info.getDescription();
    result = "Summary: " + operations.length + " operations, " + attributes.length + " attributes, " + constructors.length + " constructors, " + notifications.length + " notifications" + (description == null ? "" : ", \"" + description + "\"");
    final MBeanFeatureInfoStringifierOptions options = new MBeanFeatureInfoStringifierOptions(true, ",");
    // Do formal terms like "Attributes" need to be I18n?
    // Probabably not as they are part of a specification.
    result = result + "\n\n- Attributes -" + stringifyArray(attributes, getMBeanAttributeInfoStringifier(options));
    result = result + "\n\n- Operations -" + stringifyArray(operations, getMBeanOperationInfoStringifier(options));
    result = result + "\n\n- Constructors -" + stringifyArray(constructors, getMBeanConstructorInfoStringifier(options));
    result = result + "\n\n- Notifications -" + stringifyArray(notifications, getMBeanNotificationInfoStringifier(options));
    return (result);
}
Also used : MBeanConstructorInfo(javax.management.MBeanConstructorInfo) MBeanNotificationInfo(javax.management.MBeanNotificationInfo) MBeanInfo(javax.management.MBeanInfo) MBeanOperationInfo(javax.management.MBeanOperationInfo) MBeanAttributeInfo(javax.management.MBeanAttributeInfo)

Example 73 with MBeanInfo

use of javax.management.MBeanInfo in project Payara by payara.

the class ConfigBeanJMXSupport method getDefaultValues.

public Map<String, String> getDefaultValues(final boolean useAttributeNames) {
    final Map<String, String> m = new HashMap<String, String>();
    final MBeanInfo info = getMBeanInfo();
    for (final MBeanAttributeInfo attrInfo : info.getAttributes()) {
        final String defaultValue = defaultValue(attrInfo);
        // emit values that exist (only); null is of no use.
        if (defaultValue != null) {
            final String attrName = attrInfo.getName();
            final String name = useAttributeNames ? attrName : xmlName(attrInfo, attrName);
            m.put(name, defaultValue);
        }
    }
    return m;
}
Also used : MBeanInfo(javax.management.MBeanInfo) HashMap(java.util.HashMap) MBeanAttributeInfo(javax.management.MBeanAttributeInfo)

Example 74 with MBeanInfo

use of javax.management.MBeanInfo in project Payara by payara.

the class ConfigBeanJMXSupport method _getMBeanInfo.

private MBeanInfo _getMBeanInfo() {
    final List<MBeanAttributeInfo> attrsList = new ArrayList<MBeanAttributeInfo>();
    for (final AttributeMethodInfo info : mAttrInfos) {
        attrsList.add(attributeToMBeanAttributeInfo(info));
    }
    for (final ElementMethodInfo e : mElementInfos) {
        final MBeanAttributeInfo attrInfo = elementToMBeanAttributeInfo(e.method());
        if (attrInfo != null) {
            attrsList.add(attrInfo);
        }
    }
    final MBeanAttributeInfo[] attrs = new MBeanAttributeInfo[attrsList.size()];
    attrsList.toArray(attrs);
    final String classname = mIntf.getName();
    final String description = "ConfigBean " + mIntf.getName();
    final MBeanOperationInfo[] operations = toMBeanOperationInfos();
    final Descriptor descriptor = descriptor();
    final MBeanNotificationInfo[] notifications = new MBeanNotificationInfo[] { ATTRIBUTE_CHANGE_NOTIF_INFO };
    final MBeanInfo info = new MBeanInfo(classname, description, attrs, null, operations, notifications, descriptor);
    return info;
}
Also used : MBeanInfo(javax.management.MBeanInfo) MBeanOperationInfo(javax.management.MBeanOperationInfo) ArrayList(java.util.ArrayList) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) MBeanNotificationInfo(javax.management.MBeanNotificationInfo) Descriptor(javax.management.Descriptor)

Example 75 with MBeanInfo

use of javax.management.MBeanInfo in project Payara by payara.

the class ConfigBeanJMXSupport method getFromXMLNameMapping.

/**
 * Return a Map from the xml  name to the Attribute name.
 */
public Map<String, String> getFromXMLNameMapping() {
    final Map<String, String> m = new HashMap<String, String>();
    final MBeanInfo info = getMBeanInfo();
    for (final MBeanAttributeInfo attrInfo : info.getAttributes()) {
        m.put(xmlName(attrInfo, attrInfo.getName()), attrInfo.getName());
    }
    return m;
}
Also used : MBeanInfo(javax.management.MBeanInfo) HashMap(java.util.HashMap) MBeanAttributeInfo(javax.management.MBeanAttributeInfo)

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