Search in sources :

Example 11 with DescriptorSupport

use of javax.management.modelmbean.DescriptorSupport 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 12 with DescriptorSupport

use of javax.management.modelmbean.DescriptorSupport in project jdk8u_jdk by JetBrains.

the class RequiredModelMBeanSetAttributeTest method main.

public static void main(String[] args) throws Exception {
    boolean ok = true;
    MBeanServer mbs = MBeanServerFactory.createMBeanServer();
    // ModelMBeanAttributeInfo
    Descriptor somethingAttributeDescriptor = new DescriptorSupport(new String[] { "name=Something", "descriptorType=attribute", "getMethod=getSomething" });
    ModelMBeanAttributeInfo somethingAttributeInfo = new ModelMBeanAttributeInfo("Something", "java.lang.String", "Something attribute", true, true, false, somethingAttributeDescriptor);
    Descriptor somethingCachedAttributeDescriptor = new DescriptorSupport(new String[] { "name=SomethingCached", "descriptorType=attribute", "getMethod=getSomethingCached", "currencyTimeLimit=5000" });
    ModelMBeanAttributeInfo somethingCachedAttributeInfo = new ModelMBeanAttributeInfo("SomethingCached", "java.lang.String", "Something cached attribute", true, true, false, somethingCachedAttributeDescriptor);
    // ModelMBeanInfo
    ModelMBeanInfo mmbi = new ModelMBeanInfoSupport(Resource.class.getName(), "Resource MBean", new ModelMBeanAttributeInfo[] { somethingAttributeInfo, somethingCachedAttributeInfo }, null, new ModelMBeanOperationInfo[] {}, null);
    // RequiredModelMBean
    ModelMBean mmb = new RequiredModelMBean(mmbi);
    mmb.setManagedResource(resource, "ObjectReference");
    ObjectName mmbName = new ObjectName(":type=ResourceMBean");
    mbs.registerMBean(mmb, mmbName);
    // Run tests
    System.out.println("\nTest that we receive ServiceNotFoundException");
    try {
        Attribute attr = new Attribute("Something", "Some string");
        mbs.setAttribute(mmbName, attr);
        System.out.println("TEST FAILED: Didn't caught exception");
        ok = false;
    } catch (MBeanException mbex) {
        Exception e = mbex.getTargetException();
        if (e == null || !(e instanceof ServiceNotFoundException)) {
            System.out.println("TEST FAILED: Caught wrong exception:" + e);
            ok = false;
        } else
            System.out.println("Received expected ServiceNotFoundException");
    } catch (Exception e) {
        System.out.println("TEST FAILED: Caught wrong exception: " + e);
        e.printStackTrace(System.out);
        ok = false;
    }
    //Now check that when caching is enabled, setAttribute is working
    System.out.println("\nTest that we are not receiving ServiceNotFoundException");
    try {
        Attribute attr = new Attribute("SomethingCached", "Some string");
        mbs.setAttribute(mmbName, attr);
        System.out.println("No exception thrown");
    } catch (Exception e) {
        System.out.println("TEST FAILED: Caught an exception: " + e);
        e.printStackTrace(System.out);
        ok = false;
    }
    if (ok)
        System.out.println("Test passed");
    else {
        System.out.println("TEST FAILED");
        throw new Exception("TEST FAILED");
    }
}
Also used : RequiredModelMBean(javax.management.modelmbean.RequiredModelMBean) ModelMBean(javax.management.modelmbean.ModelMBean) Attribute(javax.management.Attribute) DescriptorSupport(javax.management.modelmbean.DescriptorSupport) ModelMBeanInfo(javax.management.modelmbean.ModelMBeanInfo) ServiceNotFoundException(javax.management.ServiceNotFoundException) MBeanException(javax.management.MBeanException) RequiredModelMBean(javax.management.modelmbean.RequiredModelMBean) ObjectName(javax.management.ObjectName) ModelMBeanAttributeInfo(javax.management.modelmbean.ModelMBeanAttributeInfo) ServiceNotFoundException(javax.management.ServiceNotFoundException) Descriptor(javax.management.Descriptor) MBeanException(javax.management.MBeanException) ModelMBeanInfoSupport(javax.management.modelmbean.ModelMBeanInfoSupport) MBeanServer(javax.management.MBeanServer)

Example 13 with DescriptorSupport

use of javax.management.modelmbean.DescriptorSupport in project jdk8u_jdk by JetBrains.

the class OpenMBeanInfoEqualsNPETest method main.

public static void main(String[] args) throws Exception {
    System.out.println("---OpenMBeanInfoEqualsNPETest-main ...");
    // ----
    System.out.println("\n---Testing on OpenMBeanAttributeInfoSupport...");
    OpenMBeanAttributeInfo openMBeanAttributeInfo0 = new OpenMBeanAttributeInfoSupport("name", "description", SimpleType.INTEGER, true, true, false, 1, new Integer[] { 1, 2, 3 });
    OpenMBeanAttributeInfo openMBeanAttributeInfo = new OpenMBeanAttributeInfoSupport("name", "description", SimpleType.INTEGER, true, true, false, null, new Integer[] { 1, 2, 3 });
    test(openMBeanAttributeInfo0, openMBeanAttributeInfo, "defaultValue");
    openMBeanAttributeInfo = new OpenMBeanAttributeInfoSupport("name", "description", SimpleType.INTEGER, true, true, false, 1, null);
    test(openMBeanAttributeInfo0, openMBeanAttributeInfo, "legalValues");
    // ----
    System.out.println("\n---Testing on OpenMBeanConstructorInfoSupport...");
    OpenMBeanConstructorInfo openMBeanConstructorInfo0 = new OpenMBeanConstructorInfoSupport("name", "description", new OpenMBeanParameterInfo[] {}, new DescriptorSupport());
    OpenMBeanConstructorInfo openMBeanConstructorInfo;
    openMBeanConstructorInfo = new OpenMBeanConstructorInfoSupport("name", "description", null, new DescriptorSupport());
    test(openMBeanConstructorInfo0, openMBeanConstructorInfo, "sigs");
    openMBeanConstructorInfo = new OpenMBeanConstructorInfoSupport("name", "description", new OpenMBeanParameterInfo[] {}, null);
    test(openMBeanConstructorInfo0, openMBeanConstructorInfo, "Descriptor");
    // ----
    System.out.println("\n---Testing on OpenMBeanOperationInfoSupport...");
    OpenMBeanOperationInfo openMBeanOperationInfo0 = new OpenMBeanOperationInfoSupport("name", "description", new OpenMBeanParameterInfo[] {}, SimpleType.INTEGER, 1, new DescriptorSupport());
    OpenMBeanOperationInfo openMBeanOperationInfo;
    openMBeanOperationInfo = new OpenMBeanOperationInfoSupport("name", "description", null, SimpleType.INTEGER, 1, new DescriptorSupport());
    test(openMBeanOperationInfo0, openMBeanOperationInfo, "sigs");
    openMBeanOperationInfo = new OpenMBeanOperationInfoSupport("name", "description", new OpenMBeanParameterInfo[] {}, SimpleType.INTEGER, MBeanOperationInfo.UNKNOWN, null);
    test(openMBeanOperationInfo0, openMBeanOperationInfo, "Descriptor");
    // ----
    System.out.println("\n---Testing on OpenMBeanParameterInfoSupport 1...");
    OpenMBeanParameterInfo openMBeanParameterInfo0 = new OpenMBeanParameterInfoSupport("name", "description", SimpleType.INTEGER, 0, -1, 1);
    OpenMBeanParameterInfo openMBeanParameterInfo;
    openMBeanParameterInfo = new OpenMBeanParameterInfoSupport("name", "description", SimpleType.INTEGER, null, -1, 1);
    test(openMBeanParameterInfo0, openMBeanParameterInfo, "default value");
    openMBeanParameterInfo = new OpenMBeanParameterInfoSupport("name", "description", SimpleType.INTEGER, 0, null, 1);
    test(openMBeanParameterInfo0, openMBeanParameterInfo, "min value");
    openMBeanParameterInfo = new OpenMBeanParameterInfoSupport("name", "description", SimpleType.INTEGER, 0, -1, null);
    test(openMBeanParameterInfo0, openMBeanParameterInfo, "max value");
    // ----
    System.out.println("\n---Testing on OpenMBeanParameterInfoSupport 2...");
    openMBeanParameterInfo0 = new OpenMBeanParameterInfoSupport("name", "description", SimpleType.INTEGER, 1, new Integer[] { -1, 1, 2 });
    openMBeanParameterInfo = new OpenMBeanParameterInfoSupport("name", "description", SimpleType.INTEGER, null, new Integer[] { -1, 1, 2 });
    test(openMBeanParameterInfo0, openMBeanParameterInfo, "default value");
    openMBeanParameterInfo = new OpenMBeanParameterInfoSupport("name", "description", SimpleType.INTEGER, 1, null);
    test(openMBeanParameterInfo0, openMBeanParameterInfo, "legal values");
    // ----
    System.out.println("\n---Testing on OpenMBeanInfoSupport...");
    String className = "toto";
    String description = "titi";
    OpenMBeanAttributeInfo[] attrInfos = new OpenMBeanAttributeInfo[] {};
    OpenMBeanConstructorInfo[] constrInfos = new OpenMBeanConstructorInfo[] {};
    OpenMBeanOperationInfo[] operaInfos = new OpenMBeanOperationInfo[] {};
    MBeanNotificationInfo[] notifInfos = new MBeanNotificationInfo[] {};
    OpenMBeanInfo ominfo0 = new OpenMBeanInfoSupport("toto", description, attrInfos, constrInfos, operaInfos, notifInfos);
    OpenMBeanInfo ominfo = new OpenMBeanInfoSupport(null, description, attrInfos, constrInfos, operaInfos, notifInfos);
    test(ominfo0, ominfo, "class name");
    ominfo = new OpenMBeanInfoSupport(className, null, attrInfos, constrInfos, operaInfos, notifInfos);
    test(ominfo0, ominfo, "description");
    ominfo = new OpenMBeanInfoSupport(className, description, null, constrInfos, operaInfos, notifInfos);
    test(ominfo0, ominfo, "attrInfos");
    ominfo = new OpenMBeanInfoSupport(className, description, attrInfos, null, operaInfos, notifInfos);
    test(ominfo0, ominfo, "constructor infos");
    ominfo = new OpenMBeanInfoSupport(className, description, attrInfos, constrInfos, null, notifInfos);
    test(ominfo0, ominfo, "operation infos");
    ominfo = new OpenMBeanInfoSupport(className, description, attrInfos, constrInfos, operaInfos, null);
    test(ominfo0, ominfo, "notif infos");
    if (failed > 0) {
        throw new RuntimeException("Test failed: " + failed);
    } else {
        System.out.println("---Test: PASSED");
    }
}
Also used : OpenMBeanParameterInfo(javax.management.openmbean.OpenMBeanParameterInfo) OpenMBeanInfoSupport(javax.management.openmbean.OpenMBeanInfoSupport) DescriptorSupport(javax.management.modelmbean.DescriptorSupport) OpenMBeanParameterInfoSupport(javax.management.openmbean.OpenMBeanParameterInfoSupport) OpenMBeanConstructorInfo(javax.management.openmbean.OpenMBeanConstructorInfo) MBeanNotificationInfo(javax.management.MBeanNotificationInfo) OpenMBeanAttributeInfo(javax.management.openmbean.OpenMBeanAttributeInfo) OpenMBeanConstructorInfoSupport(javax.management.openmbean.OpenMBeanConstructorInfoSupport) OpenMBeanAttributeInfoSupport(javax.management.openmbean.OpenMBeanAttributeInfoSupport) OpenMBeanOperationInfo(javax.management.openmbean.OpenMBeanOperationInfo) OpenMBeanOperationInfoSupport(javax.management.openmbean.OpenMBeanOperationInfoSupport) OpenMBeanInfo(javax.management.openmbean.OpenMBeanInfo)

Example 14 with DescriptorSupport

use of javax.management.modelmbean.DescriptorSupport in project jdk8u_jdk by JetBrains.

the class UnionTest method main.

public static void main(String[] args) throws Exception {
    ImmutableDescriptor immutableEmpty = new ImmutableDescriptor();
    DescriptorSupport mutableEmpty = new DescriptorSupport();
    checkEmpty(union());
    checkEmpty(union(immutableEmpty));
    checkEmpty(union(mutableEmpty));
    checkEmpty(union(EMPTY_DESCRIPTOR, immutableEmpty, mutableEmpty));
    checkEmpty(union(null, immutableEmpty, null));
    ImmutableDescriptor immutableNumbers = new ImmutableDescriptor(new String[] { "one", "two", "three" }, new Object[] { 1, 2, 3 });
    final String[] noNames = null;
    DescriptorSupport mutableNumbers = new DescriptorSupport(immutableNumbers.getFieldNames(), immutableNumbers.getFieldValues(noNames));
    ImmutableDescriptor immutableOne = new ImmutableDescriptor(Collections.singletonMap("one", 1));
    DescriptorSupport mutableOne = new DescriptorSupport(new String[] { "one" }, new Object[] { 1 });
    ImmutableDescriptor immutableTwo = new ImmutableDescriptor(Collections.singletonMap("two", 2));
    DescriptorSupport mutableTwo = new DescriptorSupport(new String[] { "two" }, new Object[] { 2 });
    ImmutableDescriptor immutableOneTwo = new ImmutableDescriptor(new String[] { "one", "two" }, new Object[] { 1, 2 });
    checkEqual(union(immutableNumbers), immutableNumbers);
    checkEqual(union(immutableNumbers, mutableNumbers), immutableNumbers);
    checkEqual(union(mutableNumbers, immutableNumbers), immutableNumbers);
    checkEqual(union(mutableEmpty, immutableEmpty, immutableNumbers, mutableNumbers, immutableOne), immutableNumbers);
    checkEqual(union(immutableOne, immutableTwo, immutableNumbers), immutableNumbers);
    checkEquivalent(union(immutableOne, mutableNumbers), immutableNumbers);
    checkEquivalent(union(immutableOne, immutableTwo), immutableOneTwo);
    checkEquivalent(union(mutableOne, mutableTwo), immutableOneTwo);
    if (failure != null)
        throw new Exception("TEST FAILED: " + failure);
    System.out.println("TEST PASSED");
}
Also used : ImmutableDescriptor(javax.management.ImmutableDescriptor) DescriptorSupport(javax.management.modelmbean.DescriptorSupport)

Aggregations

DescriptorSupport (javax.management.modelmbean.DescriptorSupport)14 Descriptor (javax.management.Descriptor)7 ModelMBeanAttributeInfo (javax.management.modelmbean.ModelMBeanAttributeInfo)6 MBeanNotificationInfo (javax.management.MBeanNotificationInfo)5 ModelMBeanInfoSupport (javax.management.modelmbean.ModelMBeanInfoSupport)5 ModelMBeanInfo (javax.management.modelmbean.ModelMBeanInfo)4 RequiredModelMBean (javax.management.modelmbean.RequiredModelMBean)4 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)3 MBeanConstructorInfo (javax.management.MBeanConstructorInfo)3 MBeanInfo (javax.management.MBeanInfo)3 MBeanOperationInfo (javax.management.MBeanOperationInfo)3 MBeanParameterInfo (javax.management.MBeanParameterInfo)3 MBeanServer (javax.management.MBeanServer)3 ObjectName (javax.management.ObjectName)3 ModelMBean (javax.management.modelmbean.ModelMBean)3 ModelMBeanOperationInfo (javax.management.modelmbean.ModelMBeanOperationInfo)3 OpenMBeanAttributeInfo (javax.management.openmbean.OpenMBeanAttributeInfo)3 OpenMBeanAttributeInfoSupport (javax.management.openmbean.OpenMBeanAttributeInfoSupport)3 OpenMBeanConstructorInfo (javax.management.openmbean.OpenMBeanConstructorInfo)3 OpenMBeanConstructorInfoSupport (javax.management.openmbean.OpenMBeanConstructorInfoSupport)3