Search in sources :

Example 51 with MBeanParameterInfo

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

the class GroovyMBean method describeOperation.

/**
 * Description of the operation.
 *
 * @param operation the operation to describe
 * @return pretty-printed description
 */
protected String describeOperation(MBeanOperationInfo operation) {
    StringBuilder buf = new StringBuilder();
    buf.append(operation.getReturnType()).append(" ").append(operation.getName()).append("(");
    MBeanParameterInfo[] params = operation.getSignature();
    for (int j = 0; j < params.length; j++) {
        MBeanParameterInfo param = params[j];
        if (j != 0) {
            buf.append(", ");
        }
        buf.append(param.getType()).append(" ").append(param.getName());
    }
    buf.append(")");
    return buf.toString();
}
Also used : MBeanParameterInfo(javax.management.MBeanParameterInfo)

Example 52 with MBeanParameterInfo

use of javax.management.MBeanParameterInfo in project voldemort by voldemort.

the class JmxUtils method extractParameterInfo.

/**
 * Extract the parameters from a method using the Jmx annotation if present,
 * or just the raw types otherwise
 *
 * @param m The method to extract parameters from
 * @return An array of parameter infos
 */
public static MBeanParameterInfo[] extractParameterInfo(Method m) {
    Class<?>[] types = m.getParameterTypes();
    Annotation[][] annotations = m.getParameterAnnotations();
    MBeanParameterInfo[] params = new MBeanParameterInfo[types.length];
    for (int i = 0; i < params.length; i++) {
        boolean hasAnnotation = false;
        for (int j = 0; j < annotations[i].length; j++) {
            if (annotations[i][j] instanceof JmxParam) {
                JmxParam param = (JmxParam) annotations[i][j];
                params[i] = new MBeanParameterInfo(param.name(), types[i].getName(), param.description());
                hasAnnotation = true;
                break;
            }
        }
        if (!hasAnnotation) {
            params[i] = new MBeanParameterInfo("", types[i].getName(), "");
        }
    }
    return params;
}
Also used : JmxParam(voldemort.annotations.jmx.JmxParam) MBeanParameterInfo(javax.management.MBeanParameterInfo)

Example 53 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 54 with MBeanParameterInfo

use of javax.management.MBeanParameterInfo in project kernel by exoplatform.

the class TestExoMBeanOperation method test4.

public void test4() throws Exception {
    Bean bean = register("domain:name=mbean", MBean4.class);
    MBeanOperationInfo[] operationInfos = bean.info.getOperations();
    assertNotNull(operationInfos);
    assertEquals(2, operationInfos.length);
    MBeanOperationInfo operation1Info = bean.info.getOperation("op1");
    assertNotNull(operation1Info);
    assertEquals("op1", operation1Info.getName());
    assertEquals("java.lang.String", operation1Info.getReturnType());
    MBeanParameterInfo[] operation1ParameterInfos = operation1Info.getSignature();
    assertNotNull(operation1ParameterInfos);
    assertEquals(1, operation1ParameterInfos.length);
    MBeanParameterInfo operation1ParameterInfo = operation1ParameterInfos[0];
    assertNotNull(operation1ParameterInfo);
    assertEquals("java.lang.Boolean", operation1ParameterInfo.getType());
    MBeanOperationInfo operation2Info = bean.info.getOperation("op2");
    assertNotNull(operation2Info);
    assertEquals("op2", operation2Info.getName());
    assertEquals("java.lang.String", operation2Info.getReturnType());
    MBeanParameterInfo[] operation2ParameterInfos = operation2Info.getSignature();
    assertNotNull(operation2ParameterInfos);
    assertEquals(1, operation2ParameterInfos.length);
    MBeanParameterInfo operation2ParameterInfo = operation2ParameterInfos[0];
    assertNotNull(operation2ParameterInfo);
    assertEquals("java.lang.Integer", operation2ParameterInfo.getType());
    MBeanAttributeInfo[] mbeanAttributeInfos = bean.info.getAttributes();
    assertNotNull(mbeanAttributeInfos);
    assertEquals(0, mbeanAttributeInfos.length);
    assertEquals("true", server.invoke(bean.name, "op1", new Object[] { true }, new String[] { "java.lang.Boolean" }));
    assertEquals("7", server.invoke(bean.name, "op2", new Object[] { 7 }, new String[] { "java.lang.Integer" }));
}
Also used : MBeanOperationInfo(javax.management.MBeanOperationInfo) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) MBeanParameterInfo(javax.management.MBeanParameterInfo)

Example 55 with MBeanParameterInfo

use of javax.management.MBeanParameterInfo in project kernel by exoplatform.

the class TestExoMBeanOperation method test2.

public void test2() throws Exception {
    Bean bean = register("domain:name=mbean", MBean2.class);
    MBeanOperationInfo[] operationInfos = bean.info.getOperations();
    assertNotNull(operationInfos);
    assertEquals(1, operationInfos.length);
    MBeanOperationInfo operationInfo = operationInfos[0];
    assertNotNull(operationInfo);
    assertEquals("op", operationInfo.getName());
    assertEquals("op_desc", operationInfo.getDescription());
    assertEquals("java.lang.String", operationInfo.getReturnType());
    MBeanParameterInfo[] parameterInfos = operationInfo.getSignature();
    assertNotNull(parameterInfos);
    assertEquals(1, parameterInfos.length);
    MBeanParameterInfo parameterInfo = parameterInfos[0];
    assertNotNull(parameterInfo);
    assertEquals("arg_desc", parameterInfo.getDescription());
    assertEquals("java.lang.Integer", parameterInfo.getType());
    MBeanAttributeInfo[] mbeanAttributeInfos = bean.info.getAttributes();
    assertNotNull(mbeanAttributeInfos);
    assertEquals(0, mbeanAttributeInfos.length);
    assertEquals("5", server.invoke(bean.name, "op", new Object[] { 5 }, new String[] { "java.lang.Integer" }));
}
Also used : MBeanOperationInfo(javax.management.MBeanOperationInfo) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) MBeanParameterInfo(javax.management.MBeanParameterInfo)

Aggregations

MBeanParameterInfo (javax.management.MBeanParameterInfo)59 MBeanOperationInfo (javax.management.MBeanOperationInfo)36 MBeanInfo (javax.management.MBeanInfo)19 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)15 ObjectName (javax.management.ObjectName)10 ArrayList (java.util.ArrayList)9 Descriptor (javax.management.Descriptor)8 Method (java.lang.reflect.Method)5 MBeanConstructorInfo (javax.management.MBeanConstructorInfo)5 Annotation (java.lang.annotation.Annotation)4 ModelMBeanOperationInfo (javax.management.modelmbean.ModelMBeanOperationInfo)4 Test (org.junit.Test)4 IOException (java.io.IOException)3 TreeMap (java.util.TreeMap)3 Attribute (javax.management.Attribute)3 ImmutableDescriptor (javax.management.ImmutableDescriptor)3 MBeanNotificationInfo (javax.management.MBeanNotificationInfo)3 ReflectionException (javax.management.ReflectionException)3 DescriptorSupport (javax.management.modelmbean.DescriptorSupport)3 Constructor (java.lang.reflect.Constructor)2