Search in sources :

Example 66 with MBeanOperationInfo

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

Example 67 with MBeanOperationInfo

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

the class MBeanInterfaceGenerator method generateOperations.

protected String generateOperations(MBeanOperationInfo[] infos) {
    final StringBuffer buf = new StringBuffer();
    for (int i = 0; i < infos.length; ++i) {
        final MBeanOperationInfo info = infos[i];
        final String name = info.getName();
        final String returnType = info.getReturnType();
        final MBeanParameterInfo[] paramInfos = info.getSignature();
        final String[] paramTypes = new String[paramInfos.length];
        for (int p = 0; p < paramInfos.length; ++p) {
            paramTypes[p] = paramInfos[p].getType();
        }
        final String[] paramNames = getParamNames(info);
        if (mEmitComments) {
            final String comment = getOperationComment(info, paramNames);
            if (comment.length() != 0) {
                buf.append(NEWLINE + indent(comment) + NEWLINE);
            }
        }
        final String method = formMethod(returnType, name, paramTypes, paramNames);
        buf.append(indent(method) + NEWLINE);
    }
    return (buf.toString());
}
Also used : MBeanOperationInfo(javax.management.MBeanOperationInfo) MBeanParameterInfo(javax.management.MBeanParameterInfo)

Example 68 with MBeanOperationInfo

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

the class MBeanInterfaceGenerator method generate.

public String generate(final MBeanInfo info, boolean emitComments) {
    mEmitComments = emitComments;
    final StringBuffer buf = new StringBuffer();
    if (mEmitComments) {
        buf.append(getHeaderComment(info)).append(NEWLINE + NEWLINE);
    }
    buf.append("package ").append(getPackageName(info)).append(";" + NEWLINE);
    mCounts = countAllTypes(info);
    buf.append(NEWLINE).append(getImportBlock(mCounts)).append(NEWLINE);
    if (mEmitComments) {
        buf.append(getInterfaceComment(info)).append(NEWLINE);
    }
    String interfaceName = getClassname(info);
    buf.append("public interface ").append(interfaceName).append(" \n{\n");
    final MBeanAttributeInfo[] attrInfos = info.getAttributes();
    final MBeanOperationInfo[] operationInfos = info.getOperations();
    if (attrInfos != null) {
        Arrays.sort(attrInfos, MBeanAttributeInfoComparator.INSTANCE);
        final List<MBeanAttributeInfo> readOnlyAttrInfos = new ArrayList<MBeanAttributeInfo>();
        final List<MBeanAttributeInfo> writebleAttrInfos = new ArrayList<MBeanAttributeInfo>();
        for (final MBeanAttributeInfo ai : attrInfos) {
            if (ai.isWritable()) {
                writebleAttrInfos.add(ai);
            } else {
                readOnlyAttrInfos.add(ai);
            }
        }
        buf.append(generateAttributes(readOnlyAttrInfos));
        buf.append(generateAttributes(writebleAttrInfos));
    }
    if (operationInfos != null) {
        if (operationInfos.length != 0) {
            Arrays.sort(operationInfos, MBeanOperationInfoComparator.INSTANCE);
            buf.append(NEWLINE + "// -------------------- Operations --------------------" + NEWLINE);
            buf.append(generateOperations(operationInfos));
        }
    }
    buf.append("\n}");
    return (buf.toString());
}
Also used : MBeanOperationInfo(javax.management.MBeanOperationInfo) ArrayList(java.util.ArrayList) MBeanAttributeInfo(javax.management.MBeanAttributeInfo)

Aggregations

MBeanOperationInfo (javax.management.MBeanOperationInfo)68 MBeanInfo (javax.management.MBeanInfo)39 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)35 MBeanParameterInfo (javax.management.MBeanParameterInfo)25 ObjectName (javax.management.ObjectName)20 Test (org.junit.Test)12 ArrayList (java.util.ArrayList)11 MBeanNotificationInfo (javax.management.MBeanNotificationInfo)9 MBeanConstructorInfo (javax.management.MBeanConstructorInfo)8 MBeanServer (javax.management.MBeanServer)8 Method (java.lang.reflect.Method)7 Descriptor (javax.management.Descriptor)7 Attribute (javax.management.Attribute)5 ReflectionException (javax.management.ReflectionException)5 InstanceNotFoundException (javax.management.InstanceNotFoundException)4 AMX (com.sun.appserv.management.base.AMX)3 IOException (java.io.IOException)3 TreeMap (java.util.TreeMap)3 IntrospectionException (javax.management.IntrospectionException)3 MBeanServerConnection (javax.management.MBeanServerConnection)3