Search in sources :

Example 21 with MBeanParameterInfo

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

the class MBeanInfoSupport method parameterInfos.

public static MBeanParameterInfo[] parameterInfos(final Method method) {
    final Class<?>[] sig = method.getParameterTypes();
    final Annotation[][] paramAnnotations = method.getParameterAnnotations();
    final MBeanParameterInfo[] infos = new MBeanParameterInfo[sig.length];
    for (int i = 0; i < sig.length; ++i) {
        final Class<?> paramClass = translatedType(sig[i]);
        final Annotation[] annotations = paramAnnotations[i];
        final Param p = getAnnotation(annotations, Param.class);
        final String paramName = (p == null || p.name().length() == 0) ? ("p" + i) : p.name();
        final Description d = getAnnotation(annotations, Description.class);
        String description = "";
        if (d != null && d.value().length() != 0) {
            description = d.value();
        }
        final String type = paramClass.getName();
        final MBeanParameterInfo info = new MBeanParameterInfo(paramName, type, description);
        infos[i] = info;
    }
    return (infos);
}
Also used : Description(org.glassfish.admin.amx.annotation.Description) Param(org.glassfish.admin.amx.annotation.Param) Annotation(java.lang.annotation.Annotation) MBeanParameterInfo(javax.management.MBeanParameterInfo)

Example 22 with MBeanParameterInfo

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

the class MBeanInfoSupport method generateMBeanOperationInfos.

public static MBeanOperationInfo[] generateMBeanOperationInfos(final Collection<Method> methods) {
    final MBeanOperationInfo[] infos = new MBeanOperationInfo[methods.size()];
    int i = 0;
    for (final Method m : methods) {
        final ManagedOperation managed = m.getAnnotation(ManagedOperation.class);
        final String methodName = m.getName();
        final MBeanParameterInfo[] parameterInfos = parameterInfos(m);
        final int impact = managed == null ? MBeanOperationInfo.UNKNOWN : managed.impact();
        final String description = getDescription(m);
        final MBeanOperationInfo info = new MBeanOperationInfo(methodName, description, parameterInfos, translatedType(m.getReturnType()).getName(), impact, null);
        infos[i] = info;
        ++i;
    }
    return (infos);
}
Also used : MBeanOperationInfo(javax.management.MBeanOperationInfo) Method(java.lang.reflect.Method) ManagedOperation(org.glassfish.admin.amx.annotation.ManagedOperation) MBeanParameterInfo(javax.management.MBeanParameterInfo)

Example 23 with MBeanParameterInfo

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

the class MBeanInterfaceGenerator method getOperationComment.

public String getOperationComment(MBeanOperationInfo info, final String[] paramNames) {
    final String description = info.getDescription();
    final StringBuffer buf = new StringBuffer();
    if (description != null && description.length() != 0) {
        buf.append(description + NEWLINE);
    }
    final Descriptor desc = info.getDescriptor();
    buf.append(toString(desc));
    final MBeanParameterInfo[] signature = info.getSignature();
    for (int i = 0; i < paramNames.length; ++i) {
        final String paramDescription = signature[i].getDescription();
        buf.append("@param " + paramNames[i] + " " + paramDescription + NEWLINE);
    }
    final String returnType = getCodeClassname(info.getReturnType());
    if (!returnType.equals("void")) {
        buf.append("@return " + returnType + NEWLINE);
    }
    return (makeJavadocComment(buf.toString()));
}
Also used : Descriptor(javax.management.Descriptor) MBeanParameterInfo(javax.management.MBeanParameterInfo)

Example 24 with MBeanParameterInfo

use of javax.management.MBeanParameterInfo in project tomee by apache.

the class DynamicMBeanWrapper method parameters.

static MBeanParameterInfo[] parameters(final MBeanOperationInfo jvmInfo, final Class<?>[] classes, final Annotation[][] annots) {
    final MBeanParameterInfo[] params = new MBeanParameterInfo[classes.length];
    assert classes.length == annots.length;
    String desc = "";
    for (int i = 0; i < classes.length; i++) {
        final Descriptor d = jvmInfo.getSignature()[i].getDescriptor();
        final String pn = "arg" + i;
        for (final Annotation a : annots[i]) {
            final Class<? extends Annotation> type = a.annotationType();
            if (type.equals(Description.class) || type.equals(OPENEJB_API_TO_JAVAX.get(Description.class))) {
                desc = getDescription(annotationProxy(a, Description.class), desc);
                break;
            }
        }
        params[i] = new MBeanParameterInfo(pn, classes[i].getName(), desc, d);
    }
    return params;
}
Also used : Description(org.apache.openejb.api.jmx.Description) Descriptor(javax.management.Descriptor) ImmutableDescriptor(javax.management.ImmutableDescriptor) Annotation(java.lang.annotation.Annotation) MBeanParameterInfo(javax.management.MBeanParameterInfo)

Example 25 with MBeanParameterInfo

use of javax.management.MBeanParameterInfo in project jetty.project by eclipse.

the class ObjectMBean method defineOperation.

/* ------------------------------------------------------------ */
/**
     *  TODO update to new behavior
     *
     * Define an operation on the managed object. Defines an operation with parameters. Refection is
     * used to determine find the method and it's return type. The description of the method is
     * found with a call to findDescription on "name(signature)". The name and description of each
     * parameter is found with a call to findDescription with "name(signature)[n]", the returned
     * description is for the last parameter of the partial signature and is assumed to start with
     * the parameter name, followed by a colon.
     *
     * @param metaData "description" or "impact:description" or "type:impact:description", type is
     * the "Object","MBean", "MMBean" or "MObject" to indicate the method is on the object, the MBean or on the
     * object but converted to an MBean reference, and impact is either "ACTION","INFO","ACTION_INFO" or "UNKNOWN".
     */
private MBeanOperationInfo defineOperation(Method method, ManagedOperation methodAnnotation) {
    String description = methodAnnotation.value();
    boolean onMBean = methodAnnotation.proxied();
    boolean convert = false;
    // determine if we should convert
    Class<?> returnType = method.getReturnType();
    if (returnType.isArray()) {
        if (LOG.isDebugEnabled())
            LOG.debug("returnType is array, get component type");
        returnType = returnType.getComponentType();
    }
    if (returnType.isAnnotationPresent(ManagedObject.class)) {
        convert = true;
    }
    String impactName = methodAnnotation.impact();
    if (LOG.isDebugEnabled())
        LOG.debug("defineOperation {} {}:{}:{}", method.getName(), onMBean, impactName, description);
    String signature = method.getName();
    try {
        // Resolve the impact
        int impact = MBeanOperationInfo.UNKNOWN;
        if (impactName == null || impactName.equals("UNKNOWN"))
            impact = MBeanOperationInfo.UNKNOWN;
        else if (impactName.equals("ACTION"))
            impact = MBeanOperationInfo.ACTION;
        else if (impactName.equals("INFO"))
            impact = MBeanOperationInfo.INFO;
        else if (impactName.equals("ACTION_INFO"))
            impact = MBeanOperationInfo.ACTION_INFO;
        else
            LOG.warn("Unknown impact '" + impactName + "' for " + signature);
        Annotation[][] allParameterAnnotations = method.getParameterAnnotations();
        Class<?>[] methodTypes = method.getParameterTypes();
        MBeanParameterInfo[] pInfo = new MBeanParameterInfo[allParameterAnnotations.length];
        for (int i = 0; i < allParameterAnnotations.length; ++i) {
            Annotation[] parameterAnnotations = allParameterAnnotations[i];
            for (Annotation anno : parameterAnnotations) {
                if (anno instanceof Name) {
                    Name nameAnnotation = (Name) anno;
                    pInfo[i] = new MBeanParameterInfo(nameAnnotation.value(), methodTypes[i].getName(), nameAnnotation.description());
                }
            }
        }
        signature += "(";
        for (int i = 0; i < methodTypes.length; ++i) {
            signature += methodTypes[i].getName();
            if (i != methodTypes.length - 1) {
                signature += ",";
            }
        }
        signature += ")";
        Class<?> returnClass = method.getReturnType();
        if (LOG.isDebugEnabled())
            LOG.debug("Method Cache: " + signature);
        if (_methods.containsKey(signature)) {
            // we have an operation for this already
            return null;
        }
        _methods.put(signature, method);
        if (convert)
            _convert.add(signature);
        return new MBeanOperationInfo(method.getName(), description, pInfo, returnClass.isPrimitive() ? TypeUtil.toName(returnClass) : (returnClass.getName()), impact);
    } catch (Exception e) {
        LOG.warn("Operation '" + signature + "'", e);
        throw new IllegalArgumentException(e.toString());
    }
}
Also used : MBeanOperationInfo(javax.management.MBeanOperationInfo) Annotation(java.lang.annotation.Annotation) AttributeNotFoundException(javax.management.AttributeNotFoundException) ReflectionException(javax.management.ReflectionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) MBeanException(javax.management.MBeanException) ObjectName(javax.management.ObjectName) Name(org.eclipse.jetty.util.annotation.Name) MBeanParameterInfo(javax.management.MBeanParameterInfo)

Aggregations

MBeanParameterInfo (javax.management.MBeanParameterInfo)42 MBeanOperationInfo (javax.management.MBeanOperationInfo)25 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)14 MBeanInfo (javax.management.MBeanInfo)12 Descriptor (javax.management.Descriptor)7 ArrayList (java.util.ArrayList)6 ObjectName (javax.management.ObjectName)6 Test (org.junit.Test)5 MBeanConstructorInfo (javax.management.MBeanConstructorInfo)4 ModelMBeanOperationInfo (javax.management.modelmbean.ModelMBeanOperationInfo)4 Annotation (java.lang.annotation.Annotation)3 Method (java.lang.reflect.Method)3 TreeMap (java.util.TreeMap)3 Attribute (javax.management.Attribute)3 MBeanNotificationInfo (javax.management.MBeanNotificationInfo)3 DescriptorSupport (javax.management.modelmbean.DescriptorSupport)3 ImmutableDescriptor (javax.management.ImmutableDescriptor)2 OpenMBeanOperationInfoSupport (javax.management.openmbean.OpenMBeanOperationInfoSupport)2 OpenMBeanParameterInfo (javax.management.openmbean.OpenMBeanParameterInfo)2 OpenType (javax.management.openmbean.OpenType)2