Search in sources :

Example 71 with Descriptor

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

the class ConfigBeanJMXSupport method duckTypedToMBeanOperationInfo.

/**
 *    DuckTyped methods are <em>always</em> exposed as operations, never as Attributes.
 */
public MBeanOperationInfo duckTypedToMBeanOperationInfo(final DuckTypedInfo info) {
    final Descriptor descriptor = descriptor(info.duckTyped());
    final String name = info.name();
    final Class<?> type = remoteType(info.returnType());
    final String description = "@DuckTyped " + name + " of " + mIntf.getName();
    // how to tell?
    final int impact = MBeanOperationInfo.UNKNOWN;
    final List<MBeanParameterInfo> paramInfos = new ArrayList<MBeanParameterInfo>();
    int i = 0;
    for (final Class<?> paramClass : info.signature()) {
        final String paramName = "p" + i;
        final String paramType = remoteType(paramClass).getName();
        final String paramDescription = "parameter " + i;
        final MBeanParameterInfo paramInfo = new MBeanParameterInfo(paramName, paramType, paramDescription, null);
        paramInfos.add(paramInfo);
        ++i;
    }
    final MBeanParameterInfo[] paramInfosArray = CollectionUtil.toArray(paramInfos, MBeanParameterInfo.class);
    final MBeanOperationInfo opInfo = new MBeanOperationInfo(name, description, paramInfosArray, type.getName(), impact, descriptor);
    return opInfo;
}
Also used : MBeanOperationInfo(javax.management.MBeanOperationInfo) ArrayList(java.util.ArrayList) Descriptor(javax.management.Descriptor) MBeanParameterInfo(javax.management.MBeanParameterInfo)

Example 72 with Descriptor

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

the class ConfigBeanJMXSupport method attributeToMBeanAttributeInfo.

public MBeanAttributeInfo attributeToMBeanAttributeInfo(final AttributeMethodInfo info) {
    final Descriptor descriptor = descriptor(info);
    final String name = info.attrName();
    final String xmlName = info.xmlName();
    descriptor.setField(DESC_XML_NAME, xmlName);
    if (info.pattern() != null) {
        descriptor.setField(DESC_PATTERN_REGEX, info.pattern());
    }
    if (info.units() != null) {
        descriptor.setField(DESC_UNITS, info.units());
    }
    if (info.min() != null) {
        descriptor.setField(DESC_MIN, info.min());
    }
    if (info.max() != null) {
        descriptor.setField(DESC_MAX, info.max());
    }
    addAnnotationsToDescriptor(descriptor, info);
    descriptor.setField(DESC_NOT_NULL, "" + info.notNull());
    Class type = info.returnType();
    String description = "@Attribute " + name;
    final boolean isReadable = true;
    // we assume that all getters are writeable for now
    final boolean isWriteable = true;
    final boolean isIs = false;
    final MBeanAttributeInfo attrInfo = new MBeanAttributeInfo(name, type.getName(), description, isReadable, isWriteable, isIs, descriptor);
    return attrInfo;
}
Also used : Descriptor(javax.management.Descriptor) MBeanAttributeInfo(javax.management.MBeanAttributeInfo)

Example 73 with Descriptor

use of javax.management.Descriptor 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

Descriptor (javax.management.Descriptor)73 RuntimeOperationsException (javax.management.RuntimeOperationsException)18 ModelMBeanAttributeInfo (javax.management.modelmbean.ModelMBeanAttributeInfo)16 ModelMBeanInfo (javax.management.modelmbean.ModelMBeanInfo)16 DescriptorSupport (javax.management.modelmbean.DescriptorSupport)11 ModelMBeanOperationInfo (javax.management.modelmbean.ModelMBeanOperationInfo)11 Method (java.lang.reflect.Method)10 ImmutableDescriptor (javax.management.ImmutableDescriptor)9 MBeanException (javax.management.MBeanException)9 AttributeNotFoundException (javax.management.AttributeNotFoundException)8 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)8 MBeanInfo (javax.management.MBeanInfo)8 MBeanServer (javax.management.MBeanServer)8 ObjectName (javax.management.ObjectName)8 ServiceNotFoundException (javax.management.ServiceNotFoundException)8 ArrayList (java.util.ArrayList)7 InstanceNotFoundException (javax.management.InstanceNotFoundException)7 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)7 MBeanOperationInfo (javax.management.MBeanOperationInfo)7 MBeanParameterInfo (javax.management.MBeanParameterInfo)7