Search in sources :

Example 6 with ModelMBeanInfoSupport

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

the class RequiredModelMBeanGetAttributeTest method main.

public static void main(String[] args) throws Exception {
    boolean ok = true;
    MBeanServer mbs = MBeanServerFactory.createMBeanServer();
    // Resource methods
    Method nullGetter = Resource.class.getMethod("getNull", (Class[]) null);
    Method integerGetter = Resource.class.getMethod("getInteger", (Class[]) null);
    Method hashtableGetter = Resource.class.getMethod("getHashtable", (Class[]) null);
    Method mapGetter = Resource.class.getMethod("getMap", (Class[]) null);
    // ModelMBeanOperationInfo
    Descriptor nullOperationDescriptor = new DescriptorSupport(new String[] { "name=getNull", "descriptorType=operation", "role=getter" });
    ModelMBeanOperationInfo nullOperationInfo = new ModelMBeanOperationInfo("Null attribute", nullGetter, nullOperationDescriptor);
    Descriptor integerOperationDescriptor = new DescriptorSupport(new String[] { "name=getInteger", "descriptorType=operation", "role=getter" });
    ModelMBeanOperationInfo integerOperationInfo = new ModelMBeanOperationInfo("Integer attribute", integerGetter, integerOperationDescriptor);
    Descriptor hashtableOperationDescriptor = new DescriptorSupport(new String[] { "name=getHashtable", "descriptorType=operation", "role=getter" });
    ModelMBeanOperationInfo hashtableOperationInfo = new ModelMBeanOperationInfo("Hashtable attribute", hashtableGetter, hashtableOperationDescriptor);
    Descriptor mapOperationDescriptor = new DescriptorSupport(new String[] { "name=getMap", "descriptorType=operation", "role=getter" });
    ModelMBeanOperationInfo mapOperationInfo = new ModelMBeanOperationInfo("Map attribute", mapGetter, mapOperationDescriptor);
    // ModelMBeanAttributeInfo
    Descriptor nullAttributeDescriptor = new DescriptorSupport(new String[] { "name=Null", "descriptorType=attribute", "getMethod=getNull" });
    ModelMBeanAttributeInfo nullAttributeInfo = new ModelMBeanAttributeInfo("Null", "java.lang.Object", "Null attribute", true, false, false, nullAttributeDescriptor);
    Descriptor integerAttributeDescriptor = new DescriptorSupport(new String[] { "name=Integer", "descriptorType=attribute", "getMethod=getInteger" });
    ModelMBeanAttributeInfo integerAttributeInfo = new ModelMBeanAttributeInfo("Integer", "int", "Integer attribute", true, false, false, integerAttributeDescriptor);
    Descriptor hashtableAttributeDescriptor = new DescriptorSupport(new String[] { "name=Hashtable", "descriptorType=attribute", "getMethod=getHashtable" });
    ModelMBeanAttributeInfo hashtableAttributeInfo = new ModelMBeanAttributeInfo("Hashtable", "java.util.Hashtable", "Hashtable attribute", true, false, false, hashtableAttributeDescriptor);
    Descriptor mapAttributeDescriptor = new DescriptorSupport(new String[] { "name=Map", "descriptorType=attribute", "getMethod=getMap" });
    ModelMBeanAttributeInfo mapAttributeInfo = new ModelMBeanAttributeInfo("Map", "java.util.Map", "Map attribute", true, false, false, mapAttributeDescriptor);
    Descriptor null2AttributeDescriptor = new DescriptorSupport(new String[] { "name=Null2", "descriptorType=attribute" });
    null2AttributeDescriptor.setField("default", null);
    ModelMBeanAttributeInfo null2AttributeInfo = new ModelMBeanAttributeInfo("Null2", "java.lang.Object", "Null2 attribute", true, false, false, null2AttributeDescriptor);
    Descriptor integer2AttributeDescriptor = new DescriptorSupport(new String[] { "name=Integer2", "descriptorType=attribute" });
    integer2AttributeDescriptor.setField("default", 10);
    ModelMBeanAttributeInfo integer2AttributeInfo = new ModelMBeanAttributeInfo("Integer2", "int", "Integer2 attribute", true, false, false, integer2AttributeDescriptor);
    Descriptor hashtable2AttributeDescriptor = new DescriptorSupport(new String[] { "name=Hashtable2", "descriptorType=attribute" });
    hashtable2AttributeDescriptor.setField("default", new Hashtable());
    ModelMBeanAttributeInfo hashtable2AttributeInfo = new ModelMBeanAttributeInfo("Hashtable2", "java.util.Hashtable", "Hashtable2 attribute", true, false, false, hashtable2AttributeDescriptor);
    Descriptor map2AttributeDescriptor = new DescriptorSupport(new String[] { "name=Map2", "descriptorType=attribute" });
    map2AttributeDescriptor.setField("default", new Hashtable());
    ModelMBeanAttributeInfo map2AttributeInfo = new ModelMBeanAttributeInfo("Map2", "java.util.Map", "Map2 attribute", true, false, false, map2AttributeDescriptor);
    // ModelMBeanInfo
    ModelMBeanInfo mmbi = new ModelMBeanInfoSupport(Resource.class.getName(), "Resource MBean", new ModelMBeanAttributeInfo[] { nullAttributeInfo, integerAttributeInfo, hashtableAttributeInfo, mapAttributeInfo, null2AttributeInfo, integer2AttributeInfo, hashtable2AttributeInfo, map2AttributeInfo }, null, new ModelMBeanOperationInfo[] { nullOperationInfo, integerOperationInfo, hashtableOperationInfo, mapOperationInfo }, 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("\nTesting that we can call getNull()... ");
    try {
        Object o = mbs.getAttribute(mmbName, "Null");
        System.out.println("getNull() = " + o);
        System.out.println("Attribute's declared type = java.lang.Object");
        System.out.println("Returned value's type = null");
    } catch (Exception e) {
        System.out.println("TEST FAILED: Caught exception:");
        e.printStackTrace(System.out);
        ok = false;
    }
    System.out.println("\nTesting that we can call getInteger()... ");
    try {
        Integer i = (Integer) mbs.getAttribute(mmbName, "Integer");
        System.out.println("getInteger() = " + i);
        System.out.println("Attribute's declared type = int");
        System.out.println("Returned value's type = " + i.getClass().getName());
    } catch (Exception e) {
        System.out.println("TEST FAILED: Caught exception:");
        e.printStackTrace(System.out);
        ok = false;
    }
    System.out.println("\nTesting that we can call getHashtable()... ");
    try {
        Hashtable h = (Hashtable) mbs.getAttribute(mmbName, "Hashtable");
        System.out.println("getHashtable() = " + h);
        System.out.println("Attribute's declared type = " + "java.util.Hashtable");
        System.out.println("Returned value's type = " + h.getClass().getName());
    } catch (Exception e) {
        System.out.println("TEST FAILED: Caught exception:");
        e.printStackTrace(System.out);
        ok = false;
    }
    System.out.println("\nTesting that we can call getMap()... ");
    try {
        Map m = (Map) mbs.getAttribute(mmbName, "Map");
        System.out.println("getMap() = " + m);
        System.out.println("Attribute's declared type = " + "java.util.Map");
        System.out.println("Returned value's type = " + m.getClass().getName());
    } catch (Exception e) {
        System.out.println("TEST FAILED: Caught exception:");
        e.printStackTrace(System.out);
        ok = false;
    }
    System.out.println("\nTesting that we can call getNull2()... ");
    try {
        Object o = mbs.getAttribute(mmbName, "Null2");
        System.out.println("getNull2() = " + o);
        System.out.println("Attribute's declared type = java.lang.Object");
        System.out.println("Returned value's type = null");
    } catch (Exception e) {
        System.out.println("TEST FAILED: Caught exception:");
        e.printStackTrace(System.out);
        ok = false;
    }
    System.out.println("\nTesting that we can call getInteger2()... ");
    try {
        Integer i = (Integer) mbs.getAttribute(mmbName, "Integer2");
        System.out.println("getInteger2() = " + i);
        System.out.println("Attribute's declared type = int");
        System.out.println("Returned value's type = " + i.getClass().getName());
    } catch (Exception e) {
        System.out.println("TEST FAILED: Caught exception:");
        e.printStackTrace(System.out);
        ok = false;
    }
    System.out.println("\nTesting that we can call getHashtable2()... ");
    try {
        Hashtable h = (Hashtable) mbs.getAttribute(mmbName, "Hashtable2");
        System.out.println("getHashtable2() = " + h);
        System.out.println("Attribute's declared type = " + "java.util.Hashtable");
        System.out.println("Returned value's type = " + h.getClass().getName());
    } catch (Exception e) {
        System.out.println("TEST FAILED: Caught exception:");
        e.printStackTrace(System.out);
        ok = false;
    }
    System.out.println("\nTesting that we can call getMap2()... ");
    try {
        Map m = (Map) mbs.getAttribute(mmbName, "Map2");
        System.out.println("getMap2() = " + m);
        System.out.println("Attribute's declared type = " + "java.util.Map");
        System.out.println("Returned value's type = " + m.getClass().getName());
    } catch (Exception e) {
        System.out.println("TEST FAILED: Caught exception:");
        e.printStackTrace(System.out);
        ok = false;
    }
    if (ok)
        System.out.println("\nTest passed.\n");
    else {
        System.out.println("\nTest failed.\n");
        System.exit(1);
    }
}
Also used : ModelMBeanOperationInfo(javax.management.modelmbean.ModelMBeanOperationInfo) RequiredModelMBean(javax.management.modelmbean.RequiredModelMBean) ModelMBean(javax.management.modelmbean.ModelMBean) Hashtable(java.util.Hashtable) DescriptorSupport(javax.management.modelmbean.DescriptorSupport) Method(java.lang.reflect.Method) ModelMBeanInfo(javax.management.modelmbean.ModelMBeanInfo) RequiredModelMBean(javax.management.modelmbean.RequiredModelMBean) ObjectName(javax.management.ObjectName) ModelMBeanAttributeInfo(javax.management.modelmbean.ModelMBeanAttributeInfo) Descriptor(javax.management.Descriptor) ModelMBeanInfoSupport(javax.management.modelmbean.ModelMBeanInfoSupport) Map(java.util.Map) MBeanServer(javax.management.MBeanServer)

Example 7 with ModelMBeanInfoSupport

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

the class MBeanInfoInteropTest method init.

private static void init() throws Exception {
    mbai = new MBeanAttributeInfo("name", "type", "descr", true, false, false);
    mbpi = new MBeanParameterInfo("name", "type", "descr");
    MBeanParameterInfo[] params = new MBeanParameterInfo[] { mbpi };
    mbci1 = new MBeanConstructorInfo("name", "descr", null);
    mbci2 = new MBeanConstructorInfo("name", "descr", params);
    mbni1 = new MBeanNotificationInfo(null, "name", "descr");
    mbni2 = new MBeanNotificationInfo(new String[] { "type" }, "name", "descr");
    mboi1 = new MBeanOperationInfo("name", "descr", null, "type", ACTION);
    mboi2 = new MBeanOperationInfo("name", "descr", params, "type", INFO);
    mbi1 = new MBeanInfo("class", "descr", null, null, null, null);
    mbi2 = new MBeanInfo("class", "descr", new MBeanAttributeInfo[] { mbai }, new MBeanConstructorInfo[] { mbci1, mbci2 }, new MBeanOperationInfo[] { mboi1, mboi2 }, new MBeanNotificationInfo[] { mbni1, mbni2 });
    ombai1 = new OpenMBeanAttributeInfoSupport("name", "descr", INTEGER, true, false, false);
    ombai2 = new OpenMBeanAttributeInfoSupport("name", "descr", INTEGER, true, false, false, 5);
    ombai3 = new OpenMBeanAttributeInfoSupport("name", "descr", INTEGER, true, false, false, 5, 1, 6);
    ombai4 = new OpenMBeanAttributeInfoSupport("name", "descr", INTEGER, true, false, false, 5, new Integer[] { 2, 3, 5, 7 });
    ombpi1 = new OpenMBeanParameterInfoSupport("name1", "descr", INTEGER);
    ombpi2 = new OpenMBeanParameterInfoSupport("name2", "descr", INTEGER, 5);
    ombpi3 = new OpenMBeanParameterInfoSupport("name3", "descr", INTEGER, 5, 1, 6);
    ombpi4 = new OpenMBeanParameterInfoSupport("name4", "descr", INTEGER, 5, new Integer[] { 2, 3, 5, 7 });
    OpenMBeanParameterInfo[] oparams = { ombpi1, ombpi2, ombpi3, ombpi4 };
    ombci1 = new OpenMBeanConstructorInfoSupport("name", "descr", null);
    ombci2 = new OpenMBeanConstructorInfoSupport("name", "descr", oparams);
    omboi1 = new OpenMBeanOperationInfoSupport("name", "descr", null, INTEGER, ACTION);
    omboi2 = new OpenMBeanOperationInfoSupport("name", "descr", oparams, INTEGER, ACTION);
    ombi1 = new OpenMBeanInfoSupport("class", "descr", null, null, null, null);
    ombi2 = new OpenMBeanInfoSupport("class", "descr", new OpenMBeanAttributeInfo[] { ombai1, ombai2, ombai3, ombai4 }, new OpenMBeanConstructorInfo[] { ombci1, ombci2 }, new OpenMBeanOperationInfo[] { omboi1, omboi2 }, new MBeanNotificationInfo[] { mbni1, mbni2 });
    Descriptor attrd = new DescriptorSupport(new String[] { "name=name", "descriptorType=attribute" });
    mmbai1 = new ModelMBeanAttributeInfo("name", "type", "descr", true, false, false);
    mmbai2 = new ModelMBeanAttributeInfo("name", "type", "descr", true, false, false, attrd);
    Descriptor constrd = new DescriptorSupport(new String[] { "name=name", "descriptorType=operation", "role=constructor" });
    mmbci1 = new ModelMBeanConstructorInfo("name", "descr", null);
    mmbci2 = new ModelMBeanConstructorInfo("name", "descr", null, constrd);
    mmbci3 = new ModelMBeanConstructorInfo("name", "descr", params);
    mmbci4 = new ModelMBeanConstructorInfo("name", "descr", params, constrd);
    Descriptor operd = new DescriptorSupport(new String[] { "name=name", "descriptorType=operation" });
    mmboi1 = new ModelMBeanOperationInfo("name", "descr", null, "type", ACTION);
    mmboi2 = new ModelMBeanOperationInfo("name", "descr", null, "type", ACTION, operd);
    mmboi3 = new ModelMBeanOperationInfo("name", "descr", params, "type", ACTION);
    mmboi4 = new ModelMBeanOperationInfo("name", "descr", params, "type", ACTION, operd);
    Descriptor notifd = new DescriptorSupport(new String[] { "name=name", "descriptorType=notification" });
    mmbni1 = new ModelMBeanNotificationInfo(null, "name", "descr");
    mmbni2 = new ModelMBeanNotificationInfo(null, "name", "descr", notifd);
    mmbni3 = new ModelMBeanNotificationInfo(new String[] { "type" }, "name", "descr");
    mmbni4 = new ModelMBeanNotificationInfo(new String[] { "type" }, "name", "descr", notifd);
    Descriptor mbeand = new DescriptorSupport(new String[] { "name=name", "descriptorType=mbean" });
    mmbi1 = new ModelMBeanInfoSupport("class", "descr", null, null, null, null);
    mmbi2 = new ModelMBeanInfoSupport("class", "descr", null, null, null, null, mbeand);
    mmbi3 = new ModelMBeanInfoSupport("class", "descr", new ModelMBeanAttributeInfo[] { mmbai1, mmbai2 }, new ModelMBeanConstructorInfo[] { mmbci1, mmbci2, mmbci3, mmbci4 }, new ModelMBeanOperationInfo[] { mmboi1, mmboi2, mmboi3, mmboi4 }, new ModelMBeanNotificationInfo[] { mmbni1, mmbni2, mmbni3, mmbni4 });
    mmbi4 = new ModelMBeanInfoSupport("class", "descr", new ModelMBeanAttributeInfo[] { mmbai1, mmbai2 }, new ModelMBeanConstructorInfo[] { mmbci1, mmbci2, mmbci3, mmbci4 }, new ModelMBeanOperationInfo[] { mmboi1, mmboi2, mmboi3, mmboi4 }, new ModelMBeanNotificationInfo[] { mmbni1, mmbni2, mmbni3, mmbni4 }, mbeand);
    objects = new Serializable[] { mbai, mbpi, mbci1, mbci2, mbni1, mbni2, mboi1, mboi2, mbi1, mbi2, ombai1, ombai2, ombai3, ombai4, ombpi1, ombpi2, ombpi3, ombpi4, ombci1, ombci2, omboi1, omboi2, ombi1, ombi2, mmbai1, mmbai2, mmbci1, mmbci2, mmbci3, mmbci4, mmboi1, mmboi2, mmboi3, mmboi4, mmbni1, mmbni2, mmbni3, mmbni4 };
}
Also used : ModelMBeanOperationInfo(javax.management.modelmbean.ModelMBeanOperationInfo) MBeanInfo(javax.management.MBeanInfo) OpenMBeanInfoSupport(javax.management.openmbean.OpenMBeanInfoSupport) OpenMBeanParameterInfoSupport(javax.management.openmbean.OpenMBeanParameterInfoSupport) ModelMBeanConstructorInfo(javax.management.modelmbean.ModelMBeanConstructorInfo) MBeanConstructorInfo(javax.management.MBeanConstructorInfo) OpenMBeanConstructorInfo(javax.management.openmbean.OpenMBeanConstructorInfo) ModelMBeanAttributeInfo(javax.management.modelmbean.ModelMBeanAttributeInfo) OpenMBeanAttributeInfo(javax.management.openmbean.OpenMBeanAttributeInfo) ModelMBeanInfoSupport(javax.management.modelmbean.ModelMBeanInfoSupport) OpenMBeanOperationInfoSupport(javax.management.openmbean.OpenMBeanOperationInfoSupport) OpenMBeanParameterInfo(javax.management.openmbean.OpenMBeanParameterInfo) ModelMBeanNotificationInfo(javax.management.modelmbean.ModelMBeanNotificationInfo) ModelMBeanOperationInfo(javax.management.modelmbean.ModelMBeanOperationInfo) MBeanOperationInfo(javax.management.MBeanOperationInfo) OpenMBeanOperationInfo(javax.management.openmbean.OpenMBeanOperationInfo) DescriptorSupport(javax.management.modelmbean.DescriptorSupport) ModelMBeanConstructorInfo(javax.management.modelmbean.ModelMBeanConstructorInfo) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) ModelMBeanAttributeInfo(javax.management.modelmbean.ModelMBeanAttributeInfo) OpenMBeanAttributeInfo(javax.management.openmbean.OpenMBeanAttributeInfo) OpenMBeanConstructorInfo(javax.management.openmbean.OpenMBeanConstructorInfo) ModelMBeanNotificationInfo(javax.management.modelmbean.ModelMBeanNotificationInfo) MBeanNotificationInfo(javax.management.MBeanNotificationInfo) OpenMBeanConstructorInfoSupport(javax.management.openmbean.OpenMBeanConstructorInfoSupport) Descriptor(javax.management.Descriptor) OpenMBeanAttributeInfoSupport(javax.management.openmbean.OpenMBeanAttributeInfoSupport) OpenMBeanOperationInfo(javax.management.openmbean.OpenMBeanOperationInfo) MBeanParameterInfo(javax.management.MBeanParameterInfo) OpenMBeanParameterInfo(javax.management.openmbean.OpenMBeanParameterInfo)

Example 8 with ModelMBeanInfoSupport

use of javax.management.modelmbean.ModelMBeanInfoSupport in project Activiti by Activiti.

the class MBeanInfoAssembler method getMBeanInfo.

public ModelMBeanInfo getMBeanInfo(Object defaultManagedBean, Object customManagedBean, String objectName) throws JMException {
    if ((defaultManagedBean == null && customManagedBean == null) || objectName == null)
        return null;
    // skip proxy classes
    if (defaultManagedBean != null && Proxy.isProxyClass(defaultManagedBean.getClass())) {
        LOG.trace("Skip creating ModelMBeanInfo due proxy class {}", defaultManagedBean.getClass());
        return null;
    }
    // maps and lists to contain information about attributes and operations
    Map<String, ManagedAttributeInfo> attributes = new LinkedHashMap<String, ManagedAttributeInfo>();
    Set<ManagedOperationInfo> operations = new LinkedHashSet<ManagedOperationInfo>();
    Set<ModelMBeanAttributeInfo> mBeanAttributes = new LinkedHashSet<ModelMBeanAttributeInfo>();
    Set<ModelMBeanOperationInfo> mBeanOperations = new LinkedHashSet<ModelMBeanOperationInfo>();
    Set<ModelMBeanNotificationInfo> mBeanNotifications = new LinkedHashSet<ModelMBeanNotificationInfo>();
    // extract details from default managed bean
    if (defaultManagedBean != null) {
        extractAttributesAndOperations(defaultManagedBean.getClass(), attributes, operations);
        extractMbeanAttributes(defaultManagedBean, attributes, mBeanAttributes, mBeanOperations);
        extractMbeanOperations(defaultManagedBean, operations, mBeanOperations);
        extractMbeanNotifications(defaultManagedBean, mBeanNotifications);
    }
    // extract details from custom managed bean
    if (customManagedBean != null) {
        extractAttributesAndOperations(customManagedBean.getClass(), attributes, operations);
        extractMbeanAttributes(customManagedBean, attributes, mBeanAttributes, mBeanOperations);
        extractMbeanOperations(customManagedBean, operations, mBeanOperations);
        extractMbeanNotifications(customManagedBean, mBeanNotifications);
    }
    // create the ModelMBeanInfo
    String name = getName(customManagedBean != null ? customManagedBean : defaultManagedBean, objectName);
    String description = getDescription(customManagedBean != null ? customManagedBean : defaultManagedBean, objectName);
    ModelMBeanAttributeInfo[] arrayAttributes = mBeanAttributes.toArray(new ModelMBeanAttributeInfo[mBeanAttributes.size()]);
    ModelMBeanOperationInfo[] arrayOperations = mBeanOperations.toArray(new ModelMBeanOperationInfo[mBeanOperations.size()]);
    ModelMBeanNotificationInfo[] arrayNotifications = mBeanNotifications.toArray(new ModelMBeanNotificationInfo[mBeanNotifications.size()]);
    ModelMBeanInfo info = new ModelMBeanInfoSupport(name, description, arrayAttributes, null, arrayOperations, arrayNotifications);
    LOG.trace("Created ModelMBeanInfo {}", info);
    return info;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ModelMBeanOperationInfo(javax.management.modelmbean.ModelMBeanOperationInfo) ModelMBeanNotificationInfo(javax.management.modelmbean.ModelMBeanNotificationInfo) ModelMBeanInfo(javax.management.modelmbean.ModelMBeanInfo) LinkedHashMap(java.util.LinkedHashMap) ModelMBeanAttributeInfo(javax.management.modelmbean.ModelMBeanAttributeInfo) ModelMBeanInfoSupport(javax.management.modelmbean.ModelMBeanInfoSupport)

Example 9 with ModelMBeanInfoSupport

use of javax.management.modelmbean.ModelMBeanInfoSupport in project voldemort by voldemort.

the class JmxUtils method createModelMBean.

/**
     * Create a model mbean from an object using the description given in the
     * Jmx annotation if present. Only operations are supported so far, no
     * attributes, constructors, or notifications
     * 
     * @param o The object to create an MBean for
     * @return The ModelMBean for the given object
     */
public static ModelMBean createModelMBean(Object o) {
    try {
        ModelMBean mbean = new RequiredModelMBean();
        JmxManaged annotation = o.getClass().getAnnotation(JmxManaged.class);
        String description = annotation == null ? "" : annotation.description();
        ModelMBeanInfo info = new ModelMBeanInfoSupport(o.getClass().getName(), description, extractAttributeInfo(o), new ModelMBeanConstructorInfo[0], extractOperationInfo(o), new ModelMBeanNotificationInfo[0]);
        mbean.setModelMBeanInfo(info);
        mbean.setManagedResource(o, "ObjectReference");
        return mbean;
    } catch (MBeanException e) {
        throw new VoldemortException(e);
    } catch (InvalidTargetObjectTypeException e) {
        throw new VoldemortException(e);
    } catch (InstanceNotFoundException e) {
        throw new VoldemortException(e);
    }
}
Also used : RequiredModelMBean(javax.management.modelmbean.RequiredModelMBean) ModelMBean(javax.management.modelmbean.ModelMBean) JmxManaged(voldemort.annotations.jmx.JmxManaged) InstanceNotFoundException(javax.management.InstanceNotFoundException) MBeanException(javax.management.MBeanException) ModelMBeanInfoSupport(javax.management.modelmbean.ModelMBeanInfoSupport) InvalidTargetObjectTypeException(javax.management.modelmbean.InvalidTargetObjectTypeException) ModelMBeanInfo(javax.management.modelmbean.ModelMBeanInfo) VoldemortException(voldemort.VoldemortException) RequiredModelMBean(javax.management.modelmbean.RequiredModelMBean)

Example 10 with ModelMBeanInfoSupport

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

Aggregations

ModelMBeanInfoSupport (javax.management.modelmbean.ModelMBeanInfoSupport)10 ModelMBeanInfo (javax.management.modelmbean.ModelMBeanInfo)9 Descriptor (javax.management.Descriptor)6 ModelMBeanAttributeInfo (javax.management.modelmbean.ModelMBeanAttributeInfo)6 DescriptorSupport (javax.management.modelmbean.DescriptorSupport)5 ModelMBeanOperationInfo (javax.management.modelmbean.ModelMBeanOperationInfo)5 RequiredModelMBean (javax.management.modelmbean.RequiredModelMBean)5 ObjectName (javax.management.ObjectName)4 ModelMBean (javax.management.modelmbean.ModelMBean)4 MBeanServer (javax.management.MBeanServer)3 ModelMBeanNotificationInfo (javax.management.modelmbean.ModelMBeanNotificationInfo)3 Method (java.lang.reflect.Method)2 LinkedHashMap (java.util.LinkedHashMap)2 LinkedHashSet (java.util.LinkedHashSet)2 Attribute (javax.management.Attribute)2 MBeanException (javax.management.MBeanException)2 MBeanInfo (javax.management.MBeanInfo)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ObjectInputStream (java.io.ObjectInputStream)1