Search in sources :

Example 96 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 StringBuilder buf = new StringBuilder();
    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 && 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)

Example 97 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 98 with MBeanOperationInfo

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

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

Example 100 with MBeanOperationInfo

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

the class TestExoMBeanOperation method test6.

public void test6() throws Exception {
    Bean bean = register("domain:name=mbean", MBean6.class);
    MBeanOperationInfo[] operationInfos = bean.info.getOperations();
    assertNotNull(operationInfos);
    assertEquals(4, operationInfos.length);
    MBeanOperationInfo readInfo = bean.info.getOperation("read");
    assertNotNull(readInfo);
    assertEquals(MBeanOperationInfo.INFO, readInfo.getImpact());
    MBeanOperationInfo writeInfo = bean.info.getOperation("write");
    assertNotNull(writeInfo);
    assertEquals(MBeanOperationInfo.ACTION, writeInfo.getImpact());
    MBeanOperationInfo idempotentWriteInfo = bean.info.getOperation("idempotentWrite");
    assertNotNull(idempotentWriteInfo);
    assertEquals(MBeanOperationInfo.ACTION, idempotentWriteInfo.getImpact());
    MBeanOperationInfo defaultImpactInfo = bean.info.getOperation("defaultImpact");
    assertNotNull(defaultImpactInfo);
    assertEquals(MBeanOperationInfo.ACTION, defaultImpactInfo.getImpact());
}
Also used : MBeanOperationInfo(javax.management.MBeanOperationInfo)

Aggregations

MBeanOperationInfo (javax.management.MBeanOperationInfo)117 MBeanInfo (javax.management.MBeanInfo)76 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)59 MBeanParameterInfo (javax.management.MBeanParameterInfo)38 ObjectName (javax.management.ObjectName)33 MBeanNotificationInfo (javax.management.MBeanNotificationInfo)23 ArrayList (java.util.ArrayList)22 MBeanConstructorInfo (javax.management.MBeanConstructorInfo)20 InstanceNotFoundException (javax.management.InstanceNotFoundException)19 ReflectionException (javax.management.ReflectionException)17 Test (org.junit.Test)16 IntrospectionException (javax.management.IntrospectionException)13 MBeanServer (javax.management.MBeanServer)13 MalformedObjectNameException (javax.management.MalformedObjectNameException)9 Test (org.testng.annotations.Test)9 Method (java.lang.reflect.Method)8 Attribute (javax.management.Attribute)8 Descriptor (javax.management.Descriptor)7 IOException (java.io.IOException)6 HashMap (java.util.HashMap)5