Search in sources :

Example 56 with MBeanParameterInfo

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

the class TestExoMBeanAttribute method test3.

public void test3(Bean bean, String getterName, String setterName) throws Exception {
    MBeanOperationInfo[] operationInfos = bean.info.getOperations();
    assertNotNull(operationInfos);
    assertEquals(2, operationInfos.length);
    MBeanOperationInfo setStringInfo = bean.info.getOperation(setterName);
    assertNotNull(setStringInfo);
    assertEquals(setterName, setStringInfo.getName());
    assertEquals("void", setStringInfo.getReturnType());
    MBeanParameterInfo[] setStringParameterInfos = setStringInfo.getSignature();
    assertEquals(1, setStringParameterInfos.length);
    MBeanParameterInfo attributeParameterInfo = setStringParameterInfos[0];
    assertEquals("java.lang.String", attributeParameterInfo.getType());
    MBeanOperationInfo getStringInfo = bean.info.getOperation(getterName);
    assertNotNull(getStringInfo);
    assertEquals(getterName, getStringInfo.getName());
    assertEquals("java.lang.String", getStringInfo.getReturnType());
    assertEquals(0, getStringInfo.getSignature().length);
    MBeanAttributeInfo[] attributeInfos = bean.info.getAttributes();
    assertNotNull(attributeInfos);
    assertEquals(1, attributeInfos.length);
    MBeanAttributeInfo attributeInfo = attributeInfos[0];
    assertEquals("String", attributeInfo.getName());
    assertEquals("java.lang.String", attributeInfo.getType());
    assertEquals(true, attributeInfo.isReadable());
    assertEquals(true, attributeInfo.isWritable());
    MBean3_0.string = null;
    assertEquals(null, server.invoke(bean.name, setterName, new Object[] { "Foo" }, new String[] { "java.lang.String" }));
    assertEquals("Foo", MBean3_0.string);
    server.setAttribute(bean.name, new Attribute("String", "Bar"));
    assertEquals("Bar", MBean3_0.string);
    MBean3_0.string = "Juu";
    assertEquals("Juu", server.invoke(bean.name, getterName, new Object[0], new String[0]));
    MBean3_0.string = "Daa";
    assertEquals("Daa", server.getAttribute(bean.name, "String"));
}
Also used : Attribute(javax.management.Attribute) MBeanOperationInfo(javax.management.MBeanOperationInfo) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) MBeanParameterInfo(javax.management.MBeanParameterInfo)

Example 57 with MBeanParameterInfo

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

the class TestExoMBeanAttribute method test2.

public void test2(Bean bean, String setterName) throws Exception {
    MBeanOperationInfo[] operationInfos = bean.info.getOperations();
    assertNotNull(operationInfos);
    assertEquals(1, operationInfos.length);
    MBeanOperationInfo operationInfo = operationInfos[0];
    assertNotNull(operationInfo);
    assertEquals(setterName, operationInfo.getName());
    assertEquals("void", operationInfo.getReturnType());
    MBeanParameterInfo[] attributeParameterInfos = operationInfo.getSignature();
    assertEquals(1, attributeParameterInfos.length);
    MBeanParameterInfo attributeParameterInfo = attributeParameterInfos[0];
    assertEquals("java.lang.String", attributeParameterInfo.getType());
    MBeanAttributeInfo[] attributeInfos = bean.info.getAttributes();
    assertNotNull(attributeInfos);
    assertEquals(1, attributeInfos.length);
    MBeanAttributeInfo attributeInfo = attributeInfos[0];
    assertEquals("String", attributeInfo.getName());
    assertEquals("java.lang.String", attributeInfo.getType());
    assertEquals(false, attributeInfo.isReadable());
    assertEquals(true, attributeInfo.isWritable());
    MBean2_0.string = null;
    assertEquals(null, server.invoke(bean.name, setterName, new Object[] { "Foo" }, new String[] { "java.lang.String" }));
    assertEquals("Foo", MBean2_0.string);
    server.setAttribute(bean.name, new Attribute("String", "Bar"));
    assertEquals("Bar", MBean2_0.string);
}
Also used : Attribute(javax.management.Attribute) MBeanOperationInfo(javax.management.MBeanOperationInfo) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) MBeanParameterInfo(javax.management.MBeanParameterInfo)

Example 58 with MBeanParameterInfo

use of javax.management.MBeanParameterInfo 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);
    return new MBeanOperationInfo(name, description, paramInfosArray, type.getName(), impact, descriptor);
}
Also used : MBeanOperationInfo(javax.management.MBeanOperationInfo) ArrayList(java.util.ArrayList) Descriptor(javax.management.Descriptor) MBeanParameterInfo(javax.management.MBeanParameterInfo)

Example 59 with MBeanParameterInfo

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

the class MBeanInterfaceGenerator method generateOperations.

protected String generateOperations(MBeanOperationInfo[] infos) {
    final StringBuilder buf = new StringBuilder();
    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).append(indent(comment)).append(NEWLINE);
            }
        }
        final String method = formMethod(returnType, name, paramTypes, paramNames);
        buf.append(indent(method)).append(NEWLINE);
    }
    return (buf.toString());
}
Also used : MBeanOperationInfo(javax.management.MBeanOperationInfo) 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