Search in sources :

Example 31 with MBeanParameterInfo

use of javax.management.MBeanParameterInfo in project jdk8u_jdk by JetBrains.

the class MBeanInfoEqualsNPETest method main.

public static void main(String[] args) throws Exception {
    System.out.println("---MBeanInfoEqualsNPETest-main ...");
    // ----
    System.out.println("\n---Testing on MBeanAttributeInfo...");
    MBeanAttributeInfo mbeanAttributeInfo0 = new MBeanAttributeInfo("name", SimpleType.INTEGER.getClassName(), "description", true, true, false);
    MBeanAttributeInfo mbeanAttributeInfo = new MBeanAttributeInfo(null, SimpleType.INTEGER.getClassName(), "description", true, true, false);
    test(mbeanAttributeInfo0, mbeanAttributeInfo, "class name");
    mbeanAttributeInfo = new MBeanAttributeInfo("name", null, "description", true, true, false);
    test(mbeanAttributeInfo0, mbeanAttributeInfo, "type");
    mbeanAttributeInfo = new MBeanAttributeInfo("name", SimpleType.INTEGER.getClassName(), null, true, true, false);
    test(mbeanAttributeInfo0, mbeanAttributeInfo, "description");
    // ----
    System.out.println("\n---Testing on MBeanConstructorInfo...");
    MBeanConstructorInfo mbeanConstructorInfo0 = new MBeanConstructorInfo("", "", new MBeanParameterInfo[] {}, new DescriptorSupport());
    MBeanConstructorInfo mbeanConstructorInfo = new MBeanConstructorInfo(null, "", new MBeanParameterInfo[] {}, new DescriptorSupport());
    test(mbeanConstructorInfo0, mbeanConstructorInfo, "name");
    mbeanConstructorInfo = new MBeanConstructorInfo("", null, new MBeanParameterInfo[] {}, new DescriptorSupport());
    test(mbeanConstructorInfo0, mbeanConstructorInfo, "description");
    mbeanConstructorInfo = new MBeanConstructorInfo("", "", null, new DescriptorSupport());
    test(mbeanConstructorInfo0, mbeanConstructorInfo, "MBeanParameterInfo");
    mbeanConstructorInfo = new MBeanConstructorInfo("", "", new MBeanParameterInfo[] {}, null);
    test(mbeanConstructorInfo0, mbeanConstructorInfo, "descriptor");
    // ----
    System.out.println("\n---Testing on MBeanOperationInfo...");
    MBeanOperationInfo mbeanOperationInfo0 = new MBeanOperationInfo("name", "description", new MBeanParameterInfo[] {}, "type", MBeanOperationInfo.UNKNOWN, new DescriptorSupport());
    MBeanOperationInfo mbeanOperationInfo = new MBeanOperationInfo(null, "description", new MBeanParameterInfo[] {}, "type", MBeanOperationInfo.UNKNOWN, new DescriptorSupport());
    test(mbeanOperationInfo0, mbeanOperationInfo, "name");
    mbeanOperationInfo = new MBeanOperationInfo("name", null, new MBeanParameterInfo[] {}, "type", MBeanOperationInfo.UNKNOWN, new DescriptorSupport());
    test(mbeanOperationInfo0, mbeanOperationInfo, "description");
    mbeanOperationInfo = new MBeanOperationInfo("name", "description", null, "type", 1, new DescriptorSupport());
    test(mbeanOperationInfo0, mbeanOperationInfo, "MBeanParameterInfo");
    mbeanOperationInfo = new MBeanOperationInfo("name", "description", new MBeanParameterInfo[] {}, null, MBeanOperationInfo.UNKNOWN, new DescriptorSupport());
    test(mbeanOperationInfo0, mbeanOperationInfo, "type");
    mbeanOperationInfo = new MBeanOperationInfo("name", "description", new MBeanParameterInfo[] {}, null, MBeanOperationInfo.UNKNOWN, null);
    test(mbeanOperationInfo0, mbeanOperationInfo, "Descriptor");
    // ----
    System.out.println("\n---Testing on MBeanParameterInfo...");
    MBeanParameterInfo mbeanParameterInfo0 = new MBeanParameterInfo("name", "type", "description", new DescriptorSupport());
    MBeanParameterInfo mbeanParameterInfo = new MBeanParameterInfo(null, "type", "description", new DescriptorSupport());
    test(mbeanParameterInfo0, mbeanParameterInfo, "name");
    mbeanParameterInfo = new MBeanParameterInfo("name", null, "description", new DescriptorSupport());
    test(mbeanParameterInfo0, mbeanParameterInfo, "type");
    mbeanParameterInfo = new MBeanParameterInfo("name", "type", null, new DescriptorSupport());
    test(mbeanParameterInfo0, mbeanParameterInfo, "description");
    mbeanParameterInfo = new MBeanParameterInfo("name", "type", "description", null);
    test(mbeanParameterInfo0, mbeanParameterInfo, "Descriptor");
    // ----
    System.out.println("\n---Testing on MBeanFeatureInfo ...");
    MBeanFeatureInfo mbeanFeatureInfo0 = new MBeanFeatureInfo("name", "description", new DescriptorSupport());
    MBeanFeatureInfo mbeanFeatureInfo = new MBeanFeatureInfo(null, "description", new DescriptorSupport());
    test(mbeanFeatureInfo0, mbeanFeatureInfo, "name");
    mbeanFeatureInfo = new MBeanFeatureInfo("name", null, new DescriptorSupport());
    test(mbeanParameterInfo0, mbeanParameterInfo, "description");
    mbeanFeatureInfo = new MBeanFeatureInfo("name", "description", null);
    test(mbeanParameterInfo0, mbeanParameterInfo, "Descriptor");
    // ----
    System.out.println("\n---Testing on MBeanInfo...");
    String className = "toto";
    String description = "titi";
    MBeanAttributeInfo[] attrInfos = new MBeanAttributeInfo[] {};
    MBeanConstructorInfo[] constrInfos = new MBeanConstructorInfo[] {};
    MBeanOperationInfo[] operaInfos = new MBeanOperationInfo[] {};
    MBeanNotificationInfo[] notifInfos = new MBeanNotificationInfo[] {};
    MBeanInfo minfo0 = new MBeanInfo("toto", description, attrInfos, constrInfos, operaInfos, notifInfos);
    MBeanInfo minfo = new MBeanInfo(null, description, attrInfos, constrInfos, operaInfos, notifInfos);
    test(minfo0, minfo, "class name");
    minfo = new MBeanInfo(className, null, attrInfos, constrInfos, operaInfos, notifInfos);
    test(minfo0, minfo, "description");
    minfo = new MBeanInfo(className, description, null, constrInfos, operaInfos, notifInfos);
    test(minfo0, minfo, "attrInfos");
    minfo = new MBeanInfo(className, description, attrInfos, null, operaInfos, notifInfos);
    test(minfo0, minfo, "constrInfos");
    minfo = new MBeanInfo(className, description, attrInfos, constrInfos, null, notifInfos);
    test(minfo0, minfo, "operaInfos");
    minfo = new MBeanInfo(className, description, attrInfos, constrInfos, operaInfos, null);
    test(minfo0, minfo, "notifInfos");
    if (failed > 0) {
        throw new RuntimeException("Test failed: " + failed);
    } else {
        System.out.println("---Test: PASSED");
    }
}
Also used : MBeanInfo(javax.management.MBeanInfo) MBeanOperationInfo(javax.management.MBeanOperationInfo) DescriptorSupport(javax.management.modelmbean.DescriptorSupport) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) MBeanConstructorInfo(javax.management.MBeanConstructorInfo) MBeanNotificationInfo(javax.management.MBeanNotificationInfo) MBeanParameterInfo(javax.management.MBeanParameterInfo) MBeanFeatureInfo(javax.management.MBeanFeatureInfo)

Example 32 with MBeanParameterInfo

use of javax.management.MBeanParameterInfo in project jdk8u_jdk by JetBrains.

the class MBeanInfoHashCodeNPETest method main.

public static void main(String[] args) throws Exception {
    System.out.println("---MBeanInfoHashCodeNPETest-main ...");
    // ----
    System.out.println("\n---Testing on MBeanAttributeInfo...");
    MBeanAttributeInfo mbeanAttributeInfo = new MBeanAttributeInfo(null, SimpleType.INTEGER.getClassName(), "description", true, true, false);
    test(mbeanAttributeInfo, "class name");
    mbeanAttributeInfo = new MBeanAttributeInfo("name", null, "description", true, true, false);
    test(mbeanAttributeInfo, "type");
    mbeanAttributeInfo = new MBeanAttributeInfo("name", SimpleType.INTEGER.getClassName(), null, true, true, false);
    test(mbeanAttributeInfo, "description");
    // ----
    System.out.println("\n---Testing on MBeanConstructorInfo...");
    MBeanConstructorInfo mbeanConstructorInfo = new MBeanConstructorInfo(null, "", new MBeanParameterInfo[] {}, new DescriptorSupport());
    test(mbeanConstructorInfo, "name");
    mbeanConstructorInfo = new MBeanConstructorInfo("", null, new MBeanParameterInfo[] {}, new DescriptorSupport());
    test(mbeanConstructorInfo, "description");
    mbeanConstructorInfo = new MBeanConstructorInfo("", "", null, new DescriptorSupport());
    test(mbeanConstructorInfo, "MBeanParameterInfo");
    mbeanConstructorInfo = new MBeanConstructorInfo("", "", new MBeanParameterInfo[] {}, null);
    test(mbeanConstructorInfo, "descriptor");
    // ----
    System.out.println("\n---Testing on MBeanOperationInfo...");
    MBeanOperationInfo mbeanOperationInfo = new MBeanOperationInfo(null, "description", new MBeanParameterInfo[] {}, "type", 1, new DescriptorSupport());
    test(mbeanOperationInfo, "name");
    mbeanOperationInfo = new MBeanOperationInfo("name", null, new MBeanParameterInfo[] {}, "type", 1, new DescriptorSupport());
    test(mbeanOperationInfo, "description");
    mbeanOperationInfo = new MBeanOperationInfo("name", "description", null, "type", 1, new DescriptorSupport());
    test(mbeanOperationInfo, "MBeanParameterInfo");
    mbeanOperationInfo = new MBeanOperationInfo("name", "description", new MBeanParameterInfo[] {}, null, 1, new DescriptorSupport());
    test(mbeanOperationInfo, "type");
    mbeanOperationInfo = new MBeanOperationInfo("name", "description", new MBeanParameterInfo[] {}, "type", -1, new DescriptorSupport());
    test(mbeanOperationInfo, "native impact");
    mbeanOperationInfo = new MBeanOperationInfo("name", "description", new MBeanParameterInfo[] {}, "type", 1, null);
    test(mbeanOperationInfo, "Descriptor");
    // ----
    System.out.println("\n---Testing on MBeanParameterInfo...");
    MBeanParameterInfo mbeanParameterInfo = new MBeanParameterInfo(null, "type", "description", new DescriptorSupport());
    test(mbeanParameterInfo, "name");
    mbeanParameterInfo = new MBeanParameterInfo("name", null, "description", new DescriptorSupport());
    test(mbeanParameterInfo, "description");
    mbeanParameterInfo = new MBeanParameterInfo("name", "type", null, new DescriptorSupport());
    test(mbeanParameterInfo, "description");
    mbeanParameterInfo = new MBeanParameterInfo("name", "type", "description", null);
    test(mbeanParameterInfo, "Descriptor");
    // ----
    System.out.println("\n---Testing on MBeanInfo...");
    String className = "toto";
    String description = "titi";
    MBeanAttributeInfo[] attrInfos = new MBeanAttributeInfo[] {};
    MBeanConstructorInfo[] constrInfos = new MBeanConstructorInfo[] {};
    MBeanOperationInfo[] operaInfos = new MBeanOperationInfo[] {};
    MBeanNotificationInfo[] notifInfos = new MBeanNotificationInfo[] {};
    MBeanInfo minfo = new MBeanInfo(null, description, attrInfos, constrInfos, operaInfos, notifInfos);
    test(minfo, "class name");
    minfo = new MBeanInfo(className, description, attrInfos, constrInfos, operaInfos, notifInfos);
    test(minfo, "name");
    minfo = new MBeanInfo(className, null, attrInfos, constrInfos, operaInfos, notifInfos);
    test(minfo, "description");
    minfo = new MBeanInfo(className, description, null, constrInfos, operaInfos, notifInfos);
    test(minfo, "attrInfos");
    minfo = new MBeanInfo(className, description, attrInfos, constrInfos, null, notifInfos);
    test(minfo, "operaInfos");
    minfo = new MBeanInfo(className, description, attrInfos, constrInfos, operaInfos, null);
    test(minfo, "notifInfos");
    Thread.sleep(100);
    if (failed > 0) {
        throw new RuntimeException("Test failed: " + failed);
    } else {
        System.out.println("---Test: PASSED");
    }
}
Also used : MBeanInfo(javax.management.MBeanInfo) MBeanOperationInfo(javax.management.MBeanOperationInfo) DescriptorSupport(javax.management.modelmbean.DescriptorSupport) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) MBeanConstructorInfo(javax.management.MBeanConstructorInfo) MBeanNotificationInfo(javax.management.MBeanNotificationInfo) MBeanParameterInfo(javax.management.MBeanParameterInfo)

Example 33 with MBeanParameterInfo

use of javax.management.MBeanParameterInfo in project jdk8u_jdk by JetBrains.

the class MustBeValidCommand method makeOpInfos.

private static MBeanOperationInfo[] makeOpInfos(String[][] spec) {
    final MBeanOperationInfo[] result = new MBeanOperationInfo[spec.length];
    final MBeanParameterInfo[] pars = makeParInfos(parameters);
    for (int i = 0; i < result.length; i++) {
        System.out.println("\tCreate an MBeanOperationInfo: " + spec[i][0]);
        final MBeanOperationInfo item = new MBeanOperationInfo(spec[i][2], spec[i][0], pars, spec[i][1], MBeanOperationInfo.ACTION_INFO);
        result[i] = item;
    }
    return result;
}
Also used : MBeanOperationInfo(javax.management.MBeanOperationInfo) MBeanParameterInfo(javax.management.MBeanParameterInfo)

Example 34 with MBeanParameterInfo

use of javax.management.MBeanParameterInfo in project jdk8u_jdk by JetBrains.

the class MXBeanTest method testInterface.

private static <T> void testInterface(Class<T> c, MBeanServerConnection mbsc, ObjectName on, NamedMXBeans namedMXBeans, boolean nullTest) throws Exception {
    System.out.println("Type check...");
    MBeanInfo mbi = mbsc.getMBeanInfo(on);
    MBeanAttributeInfo[] mbais = mbi.getAttributes();
    for (int i = 0; i < mbais.length; i++) {
        MBeanAttributeInfo mbai = mbais[i];
        String name = mbai.getName();
        Field typeField = c.getField(name + "Type");
        OpenType typeValue = (OpenType) typeField.get(null);
        OpenType openType = (OpenType) mbai.getDescriptor().getFieldValue("openType");
        if (typeValue.equals(openType))
            success("attribute " + name);
        else {
            final String msg = "Wrong type attribute " + name + ": " + openType + " should be " + typeValue;
            failure(msg);
        }
    }
    MBeanOperationInfo[] mbois = mbi.getOperations();
    for (int i = 0; i < mbois.length; i++) {
        MBeanOperationInfo mboi = mbois[i];
        String oname = mboi.getName();
        if (!oname.startsWith("op"))
            throw new Error();
        OpenType retType = (OpenType) mboi.getDescriptor().getFieldValue("openType");
        MBeanParameterInfo[] params = mboi.getSignature();
        MBeanParameterInfo p1i = params[0];
        MBeanParameterInfo p2i = params[1];
        OpenType p1Type = (OpenType) p1i.getDescriptor().getFieldValue("openType");
        OpenType p2Type = (OpenType) p2i.getDescriptor().getFieldValue("openType");
        if (!retType.equals(p1Type) || !p1Type.equals(p2Type)) {
            final String msg = "Parameter and return open types should all be same " + "but are not: " + retType + " " + oname + "(" + p1Type + ", " + p2Type + ")";
            failure(msg);
            continue;
        }
        String name = oname.substring(2);
        Field typeField = c.getField(name + "Type");
        OpenType typeValue = (OpenType) typeField.get(null);
        if (typeValue.equals(retType))
            success("operation " + oname);
        else {
            final String msg = "Wrong type operation " + oname + ": " + retType + " should be " + typeValue;
            failure(msg);
        }
    }
    System.out.println("Mapping check...");
    Object proxy = JMX.newMXBeanProxy(mbsc, on, c);
    Method[] methods = c.getMethods();
    for (int i = 0; i < methods.length; i++) {
        final Method method = methods[i];
        if (method.getDeclaringClass() != c)
            // skip hashCode() etc inherited from Object
            continue;
        final String mname = method.getName();
        final int what = getType(method);
        final String name = getName(method);
        final Field refField = c.getField(name);
        if (nullTest && refField.getType().isPrimitive())
            continue;
        final Field openTypeField = c.getField(name + "Type");
        final OpenType openType = (OpenType) openTypeField.get(null);
        final Object refValue = nullTest ? null : refField.get(null);
        Object setValue = refValue;
        try {
            Field onField = c.getField(name + "ObjectName");
            String refName = (String) onField.get(null);
            ObjectName refObjName = ObjectName.getInstance(refName);
            Class<?> mxbeanInterface = refField.getType();
            setValue = nullTest ? null : JMX.newMXBeanProxy(mbsc, refObjName, mxbeanInterface);
        } catch (Exception e) {
        // no xObjectName field, setValue == refValue
        }
        boolean ok = true;
        try {
            switch(what) {
                case GET:
                    final Object gotOpen = mbsc.getAttribute(on, name);
                    if (nullTest) {
                        if (gotOpen != null) {
                            failure(mname + " got non-null value " + gotOpen);
                            ok = false;
                        }
                    } else if (!openType.isValue(gotOpen)) {
                        if (gotOpen instanceof TabularData) {
                            // detail the mismatch
                            TabularData gotTabular = (TabularData) gotOpen;
                            compareTabularType((TabularType) openType, gotTabular.getTabularType());
                        }
                        failure(mname + " got open data " + gotOpen + " not valid for open type " + openType);
                        ok = false;
                    }
                    final Object got = method.invoke(proxy, (Object[]) null);
                    if (!equal(refValue, got, namedMXBeans)) {
                        failure(mname + " got " + string(got) + ", should be " + string(refValue));
                        ok = false;
                    }
                    break;
                case SET:
                    method.invoke(proxy, new Object[] { setValue });
                    break;
                case OP:
                    final Object opped = method.invoke(proxy, new Object[] { setValue, setValue });
                    if (!equal(refValue, opped, namedMXBeans)) {
                        failure(mname + " got " + string(opped) + ", should be " + string(refValue));
                        ok = false;
                    }
                    break;
                default:
                    throw new Error();
            }
            if (ok)
                success(mname);
        } catch (Exception e) {
            failure(mname, e);
        }
    }
}
Also used : OpenType(javax.management.openmbean.OpenType) MBeanInfo(javax.management.MBeanInfo) MBeanOperationInfo(javax.management.MBeanOperationInfo) TabularType(javax.management.openmbean.TabularType) Method(java.lang.reflect.Method) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) ObjectName(javax.management.ObjectName) TabularData(javax.management.openmbean.TabularData) Field(java.lang.reflect.Field) MBeanParameterInfo(javax.management.MBeanParameterInfo)

Example 35 with MBeanParameterInfo

use of javax.management.MBeanParameterInfo in project jdk8u_jdk by JetBrains.

the class MXBeanIntrospector method getMBeanOperationInfo.

@Override
MBeanOperationInfo getMBeanOperationInfo(String operationName, ConvertingMethod operation) {
    final Method method = operation.getMethod();
    final String description = operationName;
    /* Ideally this would be an empty string, but
           OMBOperationInfo constructor forbids that.  Also, we
           could consult an annotation to get a useful
           description.  */
    final int impact = MBeanOperationInfo.UNKNOWN;
    final OpenType<?> returnType = operation.getOpenReturnType();
    final Type originalReturnType = operation.getGenericReturnType();
    final OpenType<?>[] paramTypes = operation.getOpenParameterTypes();
    final Type[] originalParamTypes = operation.getGenericParameterTypes();
    final MBeanParameterInfo[] params = new MBeanParameterInfo[paramTypes.length];
    boolean openReturnType = canUseOpenInfo(originalReturnType);
    boolean openParameterTypes = true;
    Annotation[][] annots = method.getParameterAnnotations();
    for (int i = 0; i < paramTypes.length; i++) {
        final String paramName = "p" + i;
        final String paramDescription = paramName;
        final OpenType<?> openType = paramTypes[i];
        final Type originalType = originalParamTypes[i];
        Descriptor descriptor = typeDescriptor(openType, originalType);
        descriptor = ImmutableDescriptor.union(descriptor, Introspector.descriptorForAnnotations(annots[i]));
        final MBeanParameterInfo pi;
        if (canUseOpenInfo(originalType)) {
            pi = new OpenMBeanParameterInfoSupport(paramName, paramDescription, openType, descriptor);
        } else {
            openParameterTypes = false;
            pi = new MBeanParameterInfo(paramName, originalTypeString(originalType), paramDescription, descriptor);
        }
        params[i] = pi;
    }
    Descriptor descriptor = typeDescriptor(returnType, originalReturnType);
    descriptor = ImmutableDescriptor.union(descriptor, Introspector.descriptorForElement(method));
    final MBeanOperationInfo oi;
    if (openReturnType && openParameterTypes) {
        /* If the return value and all the parameters can be faithfully
             * represented as OpenType then we return an OpenMBeanOperationInfo.
             * If any of them is a primitive type, we can't.  Compatibility
             * with JSR 174 means that we must return an MBean*Info where
             * the getType() is the primitive type, not its wrapped type as
             * we would get with an OpenMBean*Info.  The OpenType is available
             * in the Descriptor in either case.
             */
        final OpenMBeanParameterInfo[] oparams = new OpenMBeanParameterInfo[params.length];
        System.arraycopy(params, 0, oparams, 0, params.length);
        oi = new OpenMBeanOperationInfoSupport(operationName, description, oparams, returnType, impact, descriptor);
    } else {
        oi = new MBeanOperationInfo(operationName, description, params, openReturnType ? returnType.getClassName() : originalTypeString(originalReturnType), impact, descriptor);
    }
    return oi;
}
Also used : OpenMBeanParameterInfo(javax.management.openmbean.OpenMBeanParameterInfo) OpenType(javax.management.openmbean.OpenType) MBeanOperationInfo(javax.management.MBeanOperationInfo) OpenMBeanParameterInfoSupport(javax.management.openmbean.OpenMBeanParameterInfoSupport) Method(java.lang.reflect.Method) GenericArrayType(java.lang.reflect.GenericArrayType) OpenType(javax.management.openmbean.OpenType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) Descriptor(javax.management.Descriptor) ImmutableDescriptor(javax.management.ImmutableDescriptor) OpenMBeanOperationInfoSupport(javax.management.openmbean.OpenMBeanOperationInfoSupport) MBeanParameterInfo(javax.management.MBeanParameterInfo) OpenMBeanParameterInfo(javax.management.openmbean.OpenMBeanParameterInfo)

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