Search in sources :

Example 1 with AMXMBeanMetadata

use of org.glassfish.admin.amx.core.AMXMBeanMetadata in project Payara by payara.

the class Util method deduceType.

/**
 *    Deduce the type to be used in the path.  Presence of a TYPE_FIELD field always
 *    take precedence, then the AMXMBeanMetadata.
 */
public static String deduceType(final Class<?> intf) {
    if (intf == null) {
        throw new IllegalArgumentException("null interface");
    }
    String type = null;
    AMXMBeanMetadata meta = null;
    final Object typeField = ClassUtil.getFieldValue(intf, TYPE_FIELD);
    if (typeField instanceof String) {
        type = (String) typeField;
    } else if ((meta = intf.getAnnotation(AMXMBeanMetadata.class)) != null) {
        final String typeValue = meta.type();
        if (typeValue.equals(AMXMBeanMetadata.NULL) || typeValue.length() == 0) {
            type = Util.typeFromName(intf.getName());
        } else {
            type = typeValue;
        }
    } else {
        // no annotation, use our default conversion
        type = Util.typeFromName(intf.getName());
    }
    return type;
}
Also used : AMXMBeanMetadata(org.glassfish.admin.amx.core.AMXMBeanMetadata)

Example 2 with AMXMBeanMetadata

use of org.glassfish.admin.amx.core.AMXMBeanMetadata in project Payara by payara.

the class MBeanInfoSupport method getMBeanInfo.

public static <T extends AMX_SPI> MBeanInfo getMBeanInfo(final Class<T> intf) {
    final Map<String, Method> getters = new HashMap<String, Method>();
    final Map<String, Method> setters = new HashMap<String, Method>();
    final Map<String, Method> getterSetters = new HashMap<String, Method>();
    final Set<Method> operations = new HashSet<Method>();
    findInterfaceMethods(intf, getters, setters, getterSetters, operations);
    if (!AMX_SPI.class.isAssignableFrom(intf)) {
        findInterfaceMethods(AMX_SPI.class, getters, setters, getterSetters, operations);
    }
    final List<MBeanAttributeInfo> attrsList = generateMBeanAttributeInfos(getterSetters.values(), getters.values(), setters.values());
    final MBeanOperationInfo[] operationInfos = generateMBeanOperationInfos(operations);
    // might or might not have metadata
    final AMXMBeanMetadata meta = intf.getAnnotation(AMXMBeanMetadata.class);
    final boolean globalSingleton = meta != null && meta.globalSingleton();
    final boolean singleton = Singleton.class.isAssignableFrom(intf) || globalSingleton || (meta != null && meta.singleton());
    final String group = GROUP_OTHER;
    final boolean isLeaf = meta != null && meta.leaf();
    final boolean supportsAdoption = !isLeaf;
    if (isLeaf) {
        JMXUtil.remove(attrsList, ATTR_CHILDREN);
    }
    final Descriptor d = mbeanDescriptor(true, intf, singleton, globalSingleton, group, supportsAdoption, null);
    final MBeanAttributeInfo[] attrInfos = new MBeanAttributeInfo[attrsList.size()];
    attrsList.toArray(attrInfos);
    final MBeanInfo mbeanInfo = new MBeanInfo(intf.getName(), intf.getName(), attrInfos, null, operationInfos, null, d);
    return (mbeanInfo);
}
Also used : MBeanInfo(javax.management.MBeanInfo) HashMap(java.util.HashMap) MBeanOperationInfo(javax.management.MBeanOperationInfo) AMX_SPI(org.glassfish.admin.amx.core.AMX_SPI) Method(java.lang.reflect.Method) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) AMXMBeanMetadata(org.glassfish.admin.amx.core.AMXMBeanMetadata) Descriptor(javax.management.Descriptor) HashSet(java.util.HashSet)

Aggregations

AMXMBeanMetadata (org.glassfish.admin.amx.core.AMXMBeanMetadata)2 Method (java.lang.reflect.Method)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Descriptor (javax.management.Descriptor)1 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)1 MBeanInfo (javax.management.MBeanInfo)1 MBeanOperationInfo (javax.management.MBeanOperationInfo)1 AMX_SPI (org.glassfish.admin.amx.core.AMX_SPI)1