javax.management.modelmbean.ModelMBeanInfoSupport Java Examples

The following examples show how to use javax.management.modelmbean.ModelMBeanInfoSupport. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ModelMBeanInfoSupporter.java    From cxf with Apache License 2.0 6 votes vote down vote up
public ModelMBeanInfo buildModelMBeanInfo(Descriptor desc)  {

        ModelMBeanOperationInfo[] ops =
            operations.values().toArray(new ModelMBeanOperationInfo[operations.values().size()]);

        ModelMBeanAttributeInfo[] atts =
            attributes.values().toArray(new ModelMBeanAttributeInfo[attributes.values().size()]);

        ModelMBeanConstructorInfo[] cons =
            constructors.values().toArray(new ModelMBeanConstructorInfo[constructors.values().size()]);

        ModelMBeanNotificationInfo[] notifs =
            notifications.values().toArray(new ModelMBeanNotificationInfo[notifications.values().size()]);

        return new ModelMBeanInfoSupport("javax.management.modelmbean.ModelMBeanInfo",
                                         "description",
                                         atts,
                                         cons,
                                         ops,
                                         notifs, desc);
    }
 
Example #2
Source File: TestModelMBean.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public MBeanInfo getMBeanInfo() {
    try {
        ModelMBeanAttributeInfo[] attributes = new ModelMBeanAttributeInfo[0];
        ModelMBeanConstructorInfo[] constructors = new ModelMBeanConstructorInfo[] {
                new ModelMBeanConstructorInfo("-", this.getClass().getConstructor())
        };
        ModelMBeanOperationInfo[] operations = new ModelMBeanOperationInfo[] {
                new ModelMBeanOperationInfo("info", "-", new MBeanParameterInfo[0], Void.class.getName(), ModelMBeanOperationInfo.INFO),
                new ModelMBeanOperationInfo("action", "-", new MBeanParameterInfo[0], Void.class.getName(), ModelMBeanOperationInfo.ACTION),
                new ModelMBeanOperationInfo("actionInfo", "-", new MBeanParameterInfo[0], Void.class.getName(), ModelMBeanOperationInfo.ACTION_INFO),
                new ModelMBeanOperationInfo("unknown", "-", new MBeanParameterInfo[0], Void.class.getName(), ModelMBeanOperationInfo.UNKNOWN)
        };
        ModelMBeanNotificationInfo[] notifications = new ModelMBeanNotificationInfo[0];
        return new ModelMBeanInfoSupport(this.getClass().getName(), "-", attributes, constructors, operations, notifications);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example #3
Source File: MBeanExporterOperationsTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testRegisterExistingMBeanWithUserSuppliedObjectName() throws Exception {
	ObjectName objectName = ObjectNameManager.getInstance("spring:name=Foo");
	ModelMBeanInfo info = new ModelMBeanInfoSupport("myClass", "myDescription", null, null, null, null);
	RequiredModelMBean bean = new RequiredModelMBean(info);

	MBeanExporter exporter = new MBeanExporter();
	exporter.setServer(getServer());
	exporter.registerManagedResource(bean, objectName);

	MBeanInfo infoFromServer = getServer().getMBeanInfo(objectName);
	assertEquals(info, infoFromServer);
}
 
Example #4
Source File: MBeanExporterOperationsTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testRegisterExistingMBeanWithUserSuppliedObjectName() throws Exception {
	ObjectName objectName = ObjectNameManager.getInstance("spring:name=Foo");
	ModelMBeanInfo info = new ModelMBeanInfoSupport("myClass", "myDescription", null, null, null, null);
	RequiredModelMBean bean = new RequiredModelMBean(info);

	MBeanExporter exporter = new MBeanExporter();
	exporter.setServer(getServer());
	exporter.registerManagedResource(bean, objectName);

	MBeanInfo infoFromServer = getServer().getMBeanInfo(objectName);
	assertEquals(info, infoFromServer);
}
 
Example #5
Source File: MBeanExporterOperationsTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testRegisterExistingMBeanWithUserSuppliedObjectName() throws Exception {
	ObjectName objectName = ObjectNameManager.getInstance("spring:name=Foo");
	ModelMBeanInfo info = new ModelMBeanInfoSupport("myClass", "myDescription", null, null, null, null);
	RequiredModelMBean bean = new RequiredModelMBean(info);

	MBeanExporter exporter = new MBeanExporter();
	exporter.setServer(getServer());
	exporter.registerManagedResource(bean, objectName);

	MBeanInfo infoFromServer = getServer().getMBeanInfo(objectName);
	assertEquals(info, infoFromServer);
}
 
Example #6
Source File: UnserializableTargetObjectTest.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    MBeanServer mbs = MBeanServerFactory.newMBeanServer();
    ObjectName name = new ObjectName("a:b=c");
    Resource resource1 = new Resource();
    Resource resource2 = new Resource();
    Resource resource3 = new Resource();
    Method operationMethod = Resource.class.getMethod("operation");
    Method getCountMethod = Resource.class.getMethod("getCount");
    Method setCountMethod = Resource.class.getMethod("setCount", int.class);
    Descriptor operationDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "targetObject"
                              }, new Object[] {
                                "operation", "operation", resource1
                              });
    Descriptor getCountDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "targetObject"
                              }, new Object[] {
                                "operation", "getCount", resource2
                              });
    Descriptor setCountDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "targetObject"
                              }, new Object[] {
                                "operation", "setCount", resource2
                              });
    Descriptor countDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "getMethod", "setMethod"
                              }, new Object[] {
                                "attribute", "Count", "getCount", "setCount"
                              });
    ModelMBeanOperationInfo operationInfo =
        new ModelMBeanOperationInfo("operation description",
                                    operationMethod, operationDescriptor);
    ModelMBeanOperationInfo getCountInfo =
        new ModelMBeanOperationInfo("getCount description",
                                    getCountMethod, getCountDescriptor);
    ModelMBeanOperationInfo setCountInfo =
        new ModelMBeanOperationInfo("setCount description",
                                    setCountMethod, setCountDescriptor);
    ModelMBeanAttributeInfo countInfo =
        new ModelMBeanAttributeInfo("Count", "Count description",
                                    getCountMethod, setCountMethod,
                                    countDescriptor);
    ModelMBeanInfo mmbi =
        new ModelMBeanInfoSupport(Resource.class.getName(),
                                  "ModelMBean to test targetObject",
                                  new ModelMBeanAttributeInfo[] {countInfo},
                                  null,  // no constructors
                                  new ModelMBeanOperationInfo[] {
                                      operationInfo, getCountInfo, setCountInfo
                                  },
                                  null); // no notifications
    ModelMBean mmb = new RequiredModelMBean(mmbi);
    mmb.setManagedResource(resource3, "ObjectReference");
    mbs.registerMBean(mmb, name);
    mbs.invoke(name, "operation", null, null);
    mbs.setAttribute(name, new Attribute("Count", 53));
    if (resource1.operationCount != 1)
        throw new Exception("operationCount: " + resource1.operationCount);
    if (resource2.count != 53)
        throw new Exception("count: " + resource2.count);
    int got = (Integer) mbs.getAttribute(name, "Count");
    if (got != 53)
        throw new Exception("got count: " + got);

    JMXServiceURL url = new JMXServiceURL("rmi", null, 0);
    JMXConnectorServer cs =
        JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
    cs.start();
    JMXServiceURL addr = cs.getAddress();
    JMXConnector cc = JMXConnectorFactory.connect(addr);
    MBeanServerConnection mbsc = cc.getMBeanServerConnection();
    ModelMBeanInfo rmmbi = (ModelMBeanInfo) mbsc.getMBeanInfo(name);
    // Above gets NotSerializableException if resource included in
    // serialized form
    cc.close();
    cs.stop();
    System.out.println("TEST PASSED");
}
 
Example #7
Source File: UnserializableTargetObjectTest.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    MBeanServer mbs = MBeanServerFactory.newMBeanServer();
    ObjectName name = new ObjectName("a:b=c");
    Resource resource1 = new Resource();
    Resource resource2 = new Resource();
    Resource resource3 = new Resource();
    Method operationMethod = Resource.class.getMethod("operation");
    Method getCountMethod = Resource.class.getMethod("getCount");
    Method setCountMethod = Resource.class.getMethod("setCount", int.class);
    Descriptor operationDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "targetObject"
                              }, new Object[] {
                                "operation", "operation", resource1
                              });
    Descriptor getCountDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "targetObject"
                              }, new Object[] {
                                "operation", "getCount", resource2
                              });
    Descriptor setCountDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "targetObject"
                              }, new Object[] {
                                "operation", "setCount", resource2
                              });
    Descriptor countDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "getMethod", "setMethod"
                              }, new Object[] {
                                "attribute", "Count", "getCount", "setCount"
                              });
    ModelMBeanOperationInfo operationInfo =
        new ModelMBeanOperationInfo("operation description",
                                    operationMethod, operationDescriptor);
    ModelMBeanOperationInfo getCountInfo =
        new ModelMBeanOperationInfo("getCount description",
                                    getCountMethod, getCountDescriptor);
    ModelMBeanOperationInfo setCountInfo =
        new ModelMBeanOperationInfo("setCount description",
                                    setCountMethod, setCountDescriptor);
    ModelMBeanAttributeInfo countInfo =
        new ModelMBeanAttributeInfo("Count", "Count description",
                                    getCountMethod, setCountMethod,
                                    countDescriptor);
    ModelMBeanInfo mmbi =
        new ModelMBeanInfoSupport(Resource.class.getName(),
                                  "ModelMBean to test targetObject",
                                  new ModelMBeanAttributeInfo[] {countInfo},
                                  null,  // no constructors
                                  new ModelMBeanOperationInfo[] {
                                      operationInfo, getCountInfo, setCountInfo
                                  },
                                  null); // no notifications
    ModelMBean mmb = new RequiredModelMBean(mmbi);
    mmb.setManagedResource(resource3, "ObjectReference");
    mbs.registerMBean(mmb, name);
    mbs.invoke(name, "operation", null, null);
    mbs.setAttribute(name, new Attribute("Count", 53));
    if (resource1.operationCount != 1)
        throw new Exception("operationCount: " + resource1.operationCount);
    if (resource2.count != 53)
        throw new Exception("count: " + resource2.count);
    int got = (Integer) mbs.getAttribute(name, "Count");
    if (got != 53)
        throw new Exception("got count: " + got);

    JMXServiceURL url = new JMXServiceURL("rmi", null, 0);
    JMXConnectorServer cs =
        JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
    cs.start();
    JMXServiceURL addr = cs.getAddress();
    JMXConnector cc = JMXConnectorFactory.connect(addr);
    MBeanServerConnection mbsc = cc.getMBeanServerConnection();
    ModelMBeanInfo rmmbi = (ModelMBeanInfo) mbsc.getMBeanInfo(name);
    // Above gets NotSerializableException if resource included in
    // serialized form
    cc.close();
    cs.stop();
    System.out.println("TEST PASSED");
}
 
Example #8
Source File: UnserializableTargetObjectTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    MBeanServer mbs = MBeanServerFactory.newMBeanServer();
    ObjectName name = new ObjectName("a:b=c");
    Resource resource1 = new Resource();
    Resource resource2 = new Resource();
    Resource resource3 = new Resource();
    Method operationMethod = Resource.class.getMethod("operation");
    Method getCountMethod = Resource.class.getMethod("getCount");
    Method setCountMethod = Resource.class.getMethod("setCount", int.class);
    Descriptor operationDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "targetObject"
                              }, new Object[] {
                                "operation", "operation", resource1
                              });
    Descriptor getCountDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "targetObject"
                              }, new Object[] {
                                "operation", "getCount", resource2
                              });
    Descriptor setCountDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "targetObject"
                              }, new Object[] {
                                "operation", "setCount", resource2
                              });
    Descriptor countDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "getMethod", "setMethod"
                              }, new Object[] {
                                "attribute", "Count", "getCount", "setCount"
                              });
    ModelMBeanOperationInfo operationInfo =
        new ModelMBeanOperationInfo("operation description",
                                    operationMethod, operationDescriptor);
    ModelMBeanOperationInfo getCountInfo =
        new ModelMBeanOperationInfo("getCount description",
                                    getCountMethod, getCountDescriptor);
    ModelMBeanOperationInfo setCountInfo =
        new ModelMBeanOperationInfo("setCount description",
                                    setCountMethod, setCountDescriptor);
    ModelMBeanAttributeInfo countInfo =
        new ModelMBeanAttributeInfo("Count", "Count description",
                                    getCountMethod, setCountMethod,
                                    countDescriptor);
    ModelMBeanInfo mmbi =
        new ModelMBeanInfoSupport(Resource.class.getName(),
                                  "ModelMBean to test targetObject",
                                  new ModelMBeanAttributeInfo[] {countInfo},
                                  null,  // no constructors
                                  new ModelMBeanOperationInfo[] {
                                      operationInfo, getCountInfo, setCountInfo
                                  },
                                  null); // no notifications
    ModelMBean mmb = new RequiredModelMBean(mmbi);
    mmb.setManagedResource(resource3, "ObjectReference");
    mbs.registerMBean(mmb, name);
    mbs.invoke(name, "operation", null, null);
    mbs.setAttribute(name, new Attribute("Count", 53));
    if (resource1.operationCount != 1)
        throw new Exception("operationCount: " + resource1.operationCount);
    if (resource2.count != 53)
        throw new Exception("count: " + resource2.count);
    int got = (Integer) mbs.getAttribute(name, "Count");
    if (got != 53)
        throw new Exception("got count: " + got);

    JMXServiceURL url = new JMXServiceURL("rmi", null, 0);
    JMXConnectorServer cs =
        JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
    cs.start();
    JMXServiceURL addr = cs.getAddress();
    JMXConnector cc = JMXConnectorFactory.connect(addr);
    MBeanServerConnection mbsc = cc.getMBeanServerConnection();
    ModelMBeanInfo rmmbi = (ModelMBeanInfo) mbsc.getMBeanInfo(name);
    // Above gets NotSerializableException if resource included in
    // serialized form
    cc.close();
    cs.stop();
    System.out.println("TEST PASSED");
}
 
Example #9
Source File: UnserializableTargetObjectTest.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    MBeanServer mbs = MBeanServerFactory.newMBeanServer();
    ObjectName name = new ObjectName("a:b=c");
    Resource resource1 = new Resource();
    Resource resource2 = new Resource();
    Resource resource3 = new Resource();
    Method operationMethod = Resource.class.getMethod("operation");
    Method getCountMethod = Resource.class.getMethod("getCount");
    Method setCountMethod = Resource.class.getMethod("setCount", int.class);
    Descriptor operationDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "targetObject"
                              }, new Object[] {
                                "operation", "operation", resource1
                              });
    Descriptor getCountDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "targetObject"
                              }, new Object[] {
                                "operation", "getCount", resource2
                              });
    Descriptor setCountDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "targetObject"
                              }, new Object[] {
                                "operation", "setCount", resource2
                              });
    Descriptor countDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "getMethod", "setMethod"
                              }, new Object[] {
                                "attribute", "Count", "getCount", "setCount"
                              });
    ModelMBeanOperationInfo operationInfo =
        new ModelMBeanOperationInfo("operation description",
                                    operationMethod, operationDescriptor);
    ModelMBeanOperationInfo getCountInfo =
        new ModelMBeanOperationInfo("getCount description",
                                    getCountMethod, getCountDescriptor);
    ModelMBeanOperationInfo setCountInfo =
        new ModelMBeanOperationInfo("setCount description",
                                    setCountMethod, setCountDescriptor);
    ModelMBeanAttributeInfo countInfo =
        new ModelMBeanAttributeInfo("Count", "Count description",
                                    getCountMethod, setCountMethod,
                                    countDescriptor);
    ModelMBeanInfo mmbi =
        new ModelMBeanInfoSupport(Resource.class.getName(),
                                  "ModelMBean to test targetObject",
                                  new ModelMBeanAttributeInfo[] {countInfo},
                                  null,  // no constructors
                                  new ModelMBeanOperationInfo[] {
                                      operationInfo, getCountInfo, setCountInfo
                                  },
                                  null); // no notifications
    ModelMBean mmb = new RequiredModelMBean(mmbi);
    mmb.setManagedResource(resource3, "ObjectReference");
    mbs.registerMBean(mmb, name);
    mbs.invoke(name, "operation", null, null);
    mbs.setAttribute(name, new Attribute("Count", 53));
    if (resource1.operationCount != 1)
        throw new Exception("operationCount: " + resource1.operationCount);
    if (resource2.count != 53)
        throw new Exception("count: " + resource2.count);
    int got = (Integer) mbs.getAttribute(name, "Count");
    if (got != 53)
        throw new Exception("got count: " + got);

    JMXServiceURL url = new JMXServiceURL("rmi", null, 0);
    JMXConnectorServer cs =
        JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
    cs.start();
    JMXServiceURL addr = cs.getAddress();
    JMXConnector cc = JMXConnectorFactory.connect(addr);
    MBeanServerConnection mbsc = cc.getMBeanServerConnection();
    ModelMBeanInfo rmmbi = (ModelMBeanInfo) mbsc.getMBeanInfo(name);
    // Above gets NotSerializableException if resource included in
    // serialized form
    cc.close();
    cs.stop();
    System.out.println("TEST PASSED");
}
 
Example #10
Source File: MBeanInfoAssembler.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
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())) {
            LOGGER.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<>();
        Set<ManagedOperationInfo> operations = new LinkedHashSet<>();
        Set<ModelMBeanAttributeInfo> mBeanAttributes = new LinkedHashSet<>();
        Set<ModelMBeanOperationInfo> mBeanOperations = new LinkedHashSet<>();
        Set<ModelMBeanNotificationInfo> mBeanNotifications = new LinkedHashSet<>();

        // 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);
        LOGGER.trace("Created ModelMBeanInfo {}", info);
        return info;
    }
 
Example #11
Source File: UnserializableTargetObjectTest.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    MBeanServer mbs = MBeanServerFactory.newMBeanServer();
    ObjectName name = new ObjectName("a:b=c");
    Resource resource1 = new Resource();
    Resource resource2 = new Resource();
    Resource resource3 = new Resource();
    Method operationMethod = Resource.class.getMethod("operation");
    Method getCountMethod = Resource.class.getMethod("getCount");
    Method setCountMethod = Resource.class.getMethod("setCount", int.class);
    Descriptor operationDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "targetObject"
                              }, new Object[] {
                                "operation", "operation", resource1
                              });
    Descriptor getCountDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "targetObject"
                              }, new Object[] {
                                "operation", "getCount", resource2
                              });
    Descriptor setCountDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "targetObject"
                              }, new Object[] {
                                "operation", "setCount", resource2
                              });
    Descriptor countDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "getMethod", "setMethod"
                              }, new Object[] {
                                "attribute", "Count", "getCount", "setCount"
                              });
    ModelMBeanOperationInfo operationInfo =
        new ModelMBeanOperationInfo("operation description",
                                    operationMethod, operationDescriptor);
    ModelMBeanOperationInfo getCountInfo =
        new ModelMBeanOperationInfo("getCount description",
                                    getCountMethod, getCountDescriptor);
    ModelMBeanOperationInfo setCountInfo =
        new ModelMBeanOperationInfo("setCount description",
                                    setCountMethod, setCountDescriptor);
    ModelMBeanAttributeInfo countInfo =
        new ModelMBeanAttributeInfo("Count", "Count description",
                                    getCountMethod, setCountMethod,
                                    countDescriptor);
    ModelMBeanInfo mmbi =
        new ModelMBeanInfoSupport(Resource.class.getName(),
                                  "ModelMBean to test targetObject",
                                  new ModelMBeanAttributeInfo[] {countInfo},
                                  null,  // no constructors
                                  new ModelMBeanOperationInfo[] {
                                      operationInfo, getCountInfo, setCountInfo
                                  },
                                  null); // no notifications
    ModelMBean mmb = new RequiredModelMBean(mmbi);
    mmb.setManagedResource(resource3, "ObjectReference");
    mbs.registerMBean(mmb, name);
    mbs.invoke(name, "operation", null, null);
    mbs.setAttribute(name, new Attribute("Count", 53));
    if (resource1.operationCount != 1)
        throw new Exception("operationCount: " + resource1.operationCount);
    if (resource2.count != 53)
        throw new Exception("count: " + resource2.count);
    int got = (Integer) mbs.getAttribute(name, "Count");
    if (got != 53)
        throw new Exception("got count: " + got);

    JMXServiceURL url = new JMXServiceURL("rmi", null, 0);
    JMXConnectorServer cs =
        JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
    cs.start();
    JMXServiceURL addr = cs.getAddress();
    JMXConnector cc = JMXConnectorFactory.connect(addr);
    MBeanServerConnection mbsc = cc.getMBeanServerConnection();
    ModelMBeanInfo rmmbi = (ModelMBeanInfo) mbsc.getMBeanInfo(name);
    // Above gets NotSerializableException if resource included in
    // serialized form
    cc.close();
    cs.stop();
    System.out.println("TEST PASSED");
}
 
Example #12
Source File: UnserializableTargetObjectTest.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    MBeanServer mbs = MBeanServerFactory.newMBeanServer();
    ObjectName name = new ObjectName("a:b=c");
    Resource resource1 = new Resource();
    Resource resource2 = new Resource();
    Resource resource3 = new Resource();
    Method operationMethod = Resource.class.getMethod("operation");
    Method getCountMethod = Resource.class.getMethod("getCount");
    Method setCountMethod = Resource.class.getMethod("setCount", int.class);
    Descriptor operationDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "targetObject"
                              }, new Object[] {
                                "operation", "operation", resource1
                              });
    Descriptor getCountDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "targetObject"
                              }, new Object[] {
                                "operation", "getCount", resource2
                              });
    Descriptor setCountDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "targetObject"
                              }, new Object[] {
                                "operation", "setCount", resource2
                              });
    Descriptor countDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "getMethod", "setMethod"
                              }, new Object[] {
                                "attribute", "Count", "getCount", "setCount"
                              });
    ModelMBeanOperationInfo operationInfo =
        new ModelMBeanOperationInfo("operation description",
                                    operationMethod, operationDescriptor);
    ModelMBeanOperationInfo getCountInfo =
        new ModelMBeanOperationInfo("getCount description",
                                    getCountMethod, getCountDescriptor);
    ModelMBeanOperationInfo setCountInfo =
        new ModelMBeanOperationInfo("setCount description",
                                    setCountMethod, setCountDescriptor);
    ModelMBeanAttributeInfo countInfo =
        new ModelMBeanAttributeInfo("Count", "Count description",
                                    getCountMethod, setCountMethod,
                                    countDescriptor);
    ModelMBeanInfo mmbi =
        new ModelMBeanInfoSupport(Resource.class.getName(),
                                  "ModelMBean to test targetObject",
                                  new ModelMBeanAttributeInfo[] {countInfo},
                                  null,  // no constructors
                                  new ModelMBeanOperationInfo[] {
                                      operationInfo, getCountInfo, setCountInfo
                                  },
                                  null); // no notifications
    ModelMBean mmb = new RequiredModelMBean(mmbi);
    mmb.setManagedResource(resource3, "ObjectReference");
    mbs.registerMBean(mmb, name);
    mbs.invoke(name, "operation", null, null);
    mbs.setAttribute(name, new Attribute("Count", 53));
    if (resource1.operationCount != 1)
        throw new Exception("operationCount: " + resource1.operationCount);
    if (resource2.count != 53)
        throw new Exception("count: " + resource2.count);
    int got = (Integer) mbs.getAttribute(name, "Count");
    if (got != 53)
        throw new Exception("got count: " + got);

    JMXServiceURL url = new JMXServiceURL("rmi", null, 0);
    JMXConnectorServer cs =
        JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
    cs.start();
    JMXServiceURL addr = cs.getAddress();
    JMXConnector cc = JMXConnectorFactory.connect(addr);
    MBeanServerConnection mbsc = cc.getMBeanServerConnection();
    ModelMBeanInfo rmmbi = (ModelMBeanInfo) mbsc.getMBeanInfo(name);
    // Above gets NotSerializableException if resource included in
    // serialized form
    cc.close();
    cs.stop();
    System.out.println("TEST PASSED");
}
 
Example #13
Source File: UnserializableTargetObjectTest.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    MBeanServer mbs = MBeanServerFactory.newMBeanServer();
    ObjectName name = new ObjectName("a:b=c");
    Resource resource1 = new Resource();
    Resource resource2 = new Resource();
    Resource resource3 = new Resource();
    Method operationMethod = Resource.class.getMethod("operation");
    Method getCountMethod = Resource.class.getMethod("getCount");
    Method setCountMethod = Resource.class.getMethod("setCount", int.class);
    Descriptor operationDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "targetObject"
                              }, new Object[] {
                                "operation", "operation", resource1
                              });
    Descriptor getCountDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "targetObject"
                              }, new Object[] {
                                "operation", "getCount", resource2
                              });
    Descriptor setCountDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "targetObject"
                              }, new Object[] {
                                "operation", "setCount", resource2
                              });
    Descriptor countDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "getMethod", "setMethod"
                              }, new Object[] {
                                "attribute", "Count", "getCount", "setCount"
                              });
    ModelMBeanOperationInfo operationInfo =
        new ModelMBeanOperationInfo("operation description",
                                    operationMethod, operationDescriptor);
    ModelMBeanOperationInfo getCountInfo =
        new ModelMBeanOperationInfo("getCount description",
                                    getCountMethod, getCountDescriptor);
    ModelMBeanOperationInfo setCountInfo =
        new ModelMBeanOperationInfo("setCount description",
                                    setCountMethod, setCountDescriptor);
    ModelMBeanAttributeInfo countInfo =
        new ModelMBeanAttributeInfo("Count", "Count description",
                                    getCountMethod, setCountMethod,
                                    countDescriptor);
    ModelMBeanInfo mmbi =
        new ModelMBeanInfoSupport(Resource.class.getName(),
                                  "ModelMBean to test targetObject",
                                  new ModelMBeanAttributeInfo[] {countInfo},
                                  null,  // no constructors
                                  new ModelMBeanOperationInfo[] {
                                      operationInfo, getCountInfo, setCountInfo
                                  },
                                  null); // no notifications
    ModelMBean mmb = new RequiredModelMBean(mmbi);
    mmb.setManagedResource(resource3, "ObjectReference");
    mbs.registerMBean(mmb, name);
    mbs.invoke(name, "operation", null, null);
    mbs.setAttribute(name, new Attribute("Count", 53));
    if (resource1.operationCount != 1)
        throw new Exception("operationCount: " + resource1.operationCount);
    if (resource2.count != 53)
        throw new Exception("count: " + resource2.count);
    int got = (Integer) mbs.getAttribute(name, "Count");
    if (got != 53)
        throw new Exception("got count: " + got);

    JMXServiceURL url = new JMXServiceURL("rmi", null, 0);
    JMXConnectorServer cs =
        JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
    cs.start();
    JMXServiceURL addr = cs.getAddress();
    JMXConnector cc = JMXConnectorFactory.connect(addr);
    MBeanServerConnection mbsc = cc.getMBeanServerConnection();
    ModelMBeanInfo rmmbi = (ModelMBeanInfo) mbsc.getMBeanInfo(name);
    // Above gets NotSerializableException if resource included in
    // serialized form
    cc.close();
    cs.stop();
    System.out.println("TEST PASSED");
}
 
Example #14
Source File: UnserializableTargetObjectTest.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    MBeanServer mbs = MBeanServerFactory.newMBeanServer();
    ObjectName name = new ObjectName("a:b=c");
    Resource resource1 = new Resource();
    Resource resource2 = new Resource();
    Resource resource3 = new Resource();
    Method operationMethod = Resource.class.getMethod("operation");
    Method getCountMethod = Resource.class.getMethod("getCount");
    Method setCountMethod = Resource.class.getMethod("setCount", int.class);
    Descriptor operationDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "targetObject"
                              }, new Object[] {
                                "operation", "operation", resource1
                              });
    Descriptor getCountDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "targetObject"
                              }, new Object[] {
                                "operation", "getCount", resource2
                              });
    Descriptor setCountDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "targetObject"
                              }, new Object[] {
                                "operation", "setCount", resource2
                              });
    Descriptor countDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "getMethod", "setMethod"
                              }, new Object[] {
                                "attribute", "Count", "getCount", "setCount"
                              });
    ModelMBeanOperationInfo operationInfo =
        new ModelMBeanOperationInfo("operation description",
                                    operationMethod, operationDescriptor);
    ModelMBeanOperationInfo getCountInfo =
        new ModelMBeanOperationInfo("getCount description",
                                    getCountMethod, getCountDescriptor);
    ModelMBeanOperationInfo setCountInfo =
        new ModelMBeanOperationInfo("setCount description",
                                    setCountMethod, setCountDescriptor);
    ModelMBeanAttributeInfo countInfo =
        new ModelMBeanAttributeInfo("Count", "Count description",
                                    getCountMethod, setCountMethod,
                                    countDescriptor);
    ModelMBeanInfo mmbi =
        new ModelMBeanInfoSupport(Resource.class.getName(),
                                  "ModelMBean to test targetObject",
                                  new ModelMBeanAttributeInfo[] {countInfo},
                                  null,  // no constructors
                                  new ModelMBeanOperationInfo[] {
                                      operationInfo, getCountInfo, setCountInfo
                                  },
                                  null); // no notifications
    ModelMBean mmb = new RequiredModelMBean(mmbi);
    mmb.setManagedResource(resource3, "ObjectReference");
    mbs.registerMBean(mmb, name);
    mbs.invoke(name, "operation", null, null);
    mbs.setAttribute(name, new Attribute("Count", 53));
    if (resource1.operationCount != 1)
        throw new Exception("operationCount: " + resource1.operationCount);
    if (resource2.count != 53)
        throw new Exception("count: " + resource2.count);
    int got = (Integer) mbs.getAttribute(name, "Count");
    if (got != 53)
        throw new Exception("got count: " + got);

    JMXServiceURL url = new JMXServiceURL("rmi", null, 0);
    JMXConnectorServer cs =
        JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
    cs.start();
    JMXServiceURL addr = cs.getAddress();
    JMXConnector cc = JMXConnectorFactory.connect(addr);
    MBeanServerConnection mbsc = cc.getMBeanServerConnection();
    ModelMBeanInfo rmmbi = (ModelMBeanInfo) mbsc.getMBeanInfo(name);
    // Above gets NotSerializableException if resource included in
    // serialized form
    cc.close();
    cs.stop();
    System.out.println("TEST PASSED");
}
 
Example #15
Source File: UnserializableTargetObjectTest.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    MBeanServer mbs = MBeanServerFactory.newMBeanServer();
    ObjectName name = new ObjectName("a:b=c");
    Resource resource1 = new Resource();
    Resource resource2 = new Resource();
    Resource resource3 = new Resource();
    Method operationMethod = Resource.class.getMethod("operation");
    Method getCountMethod = Resource.class.getMethod("getCount");
    Method setCountMethod = Resource.class.getMethod("setCount", int.class);
    Descriptor operationDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "targetObject"
                              }, new Object[] {
                                "operation", "operation", resource1
                              });
    Descriptor getCountDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "targetObject"
                              }, new Object[] {
                                "operation", "getCount", resource2
                              });
    Descriptor setCountDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "targetObject"
                              }, new Object[] {
                                "operation", "setCount", resource2
                              });
    Descriptor countDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "getMethod", "setMethod"
                              }, new Object[] {
                                "attribute", "Count", "getCount", "setCount"
                              });
    ModelMBeanOperationInfo operationInfo =
        new ModelMBeanOperationInfo("operation description",
                                    operationMethod, operationDescriptor);
    ModelMBeanOperationInfo getCountInfo =
        new ModelMBeanOperationInfo("getCount description",
                                    getCountMethod, getCountDescriptor);
    ModelMBeanOperationInfo setCountInfo =
        new ModelMBeanOperationInfo("setCount description",
                                    setCountMethod, setCountDescriptor);
    ModelMBeanAttributeInfo countInfo =
        new ModelMBeanAttributeInfo("Count", "Count description",
                                    getCountMethod, setCountMethod,
                                    countDescriptor);
    ModelMBeanInfo mmbi =
        new ModelMBeanInfoSupport(Resource.class.getName(),
                                  "ModelMBean to test targetObject",
                                  new ModelMBeanAttributeInfo[] {countInfo},
                                  null,  // no constructors
                                  new ModelMBeanOperationInfo[] {
                                      operationInfo, getCountInfo, setCountInfo
                                  },
                                  null); // no notifications
    ModelMBean mmb = new RequiredModelMBean(mmbi);
    mmb.setManagedResource(resource3, "ObjectReference");
    mbs.registerMBean(mmb, name);
    mbs.invoke(name, "operation", null, null);
    mbs.setAttribute(name, new Attribute("Count", 53));
    if (resource1.operationCount != 1)
        throw new Exception("operationCount: " + resource1.operationCount);
    if (resource2.count != 53)
        throw new Exception("count: " + resource2.count);
    int got = (Integer) mbs.getAttribute(name, "Count");
    if (got != 53)
        throw new Exception("got count: " + got);

    JMXServiceURL url = new JMXServiceURL("rmi", null, 0);
    JMXConnectorServer cs =
        JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
    cs.start();
    JMXServiceURL addr = cs.getAddress();
    JMXConnector cc = JMXConnectorFactory.connect(addr);
    MBeanServerConnection mbsc = cc.getMBeanServerConnection();
    ModelMBeanInfo rmmbi = (ModelMBeanInfo) mbsc.getMBeanInfo(name);
    // Above gets NotSerializableException if resource included in
    // serialized form
    cc.close();
    cs.stop();
    System.out.println("TEST PASSED");
}
 
Example #16
Source File: UnserializableTargetObjectTest.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    MBeanServer mbs = MBeanServerFactory.newMBeanServer();
    ObjectName name = new ObjectName("a:b=c");
    Resource resource1 = new Resource();
    Resource resource2 = new Resource();
    Resource resource3 = new Resource();
    Method operationMethod = Resource.class.getMethod("operation");
    Method getCountMethod = Resource.class.getMethod("getCount");
    Method setCountMethod = Resource.class.getMethod("setCount", int.class);
    Descriptor operationDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "targetObject"
                              }, new Object[] {
                                "operation", "operation", resource1
                              });
    Descriptor getCountDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "targetObject"
                              }, new Object[] {
                                "operation", "getCount", resource2
                              });
    Descriptor setCountDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "targetObject"
                              }, new Object[] {
                                "operation", "setCount", resource2
                              });
    Descriptor countDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "getMethod", "setMethod"
                              }, new Object[] {
                                "attribute", "Count", "getCount", "setCount"
                              });
    ModelMBeanOperationInfo operationInfo =
        new ModelMBeanOperationInfo("operation description",
                                    operationMethod, operationDescriptor);
    ModelMBeanOperationInfo getCountInfo =
        new ModelMBeanOperationInfo("getCount description",
                                    getCountMethod, getCountDescriptor);
    ModelMBeanOperationInfo setCountInfo =
        new ModelMBeanOperationInfo("setCount description",
                                    setCountMethod, setCountDescriptor);
    ModelMBeanAttributeInfo countInfo =
        new ModelMBeanAttributeInfo("Count", "Count description",
                                    getCountMethod, setCountMethod,
                                    countDescriptor);
    ModelMBeanInfo mmbi =
        new ModelMBeanInfoSupport(Resource.class.getName(),
                                  "ModelMBean to test targetObject",
                                  new ModelMBeanAttributeInfo[] {countInfo},
                                  null,  // no constructors
                                  new ModelMBeanOperationInfo[] {
                                      operationInfo, getCountInfo, setCountInfo
                                  },
                                  null); // no notifications
    ModelMBean mmb = new RequiredModelMBean(mmbi);
    mmb.setManagedResource(resource3, "ObjectReference");
    mbs.registerMBean(mmb, name);
    mbs.invoke(name, "operation", null, null);
    mbs.setAttribute(name, new Attribute("Count", 53));
    if (resource1.operationCount != 1)
        throw new Exception("operationCount: " + resource1.operationCount);
    if (resource2.count != 53)
        throw new Exception("count: " + resource2.count);
    int got = (Integer) mbs.getAttribute(name, "Count");
    if (got != 53)
        throw new Exception("got count: " + got);

    JMXServiceURL url = new JMXServiceURL("rmi", null, 0);
    JMXConnectorServer cs =
        JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
    cs.start();
    JMXServiceURL addr = cs.getAddress();
    JMXConnector cc = JMXConnectorFactory.connect(addr);
    MBeanServerConnection mbsc = cc.getMBeanServerConnection();
    ModelMBeanInfo rmmbi = (ModelMBeanInfo) mbsc.getMBeanInfo(name);
    // Above gets NotSerializableException if resource included in
    // serialized form
    cc.close();
    cs.stop();
    System.out.println("TEST PASSED");
}
 
Example #17
Source File: UnserializableTargetObjectTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    MBeanServer mbs = MBeanServerFactory.newMBeanServer();
    ObjectName name = new ObjectName("a:b=c");
    Resource resource1 = new Resource();
    Resource resource2 = new Resource();
    Resource resource3 = new Resource();
    Method operationMethod = Resource.class.getMethod("operation");
    Method getCountMethod = Resource.class.getMethod("getCount");
    Method setCountMethod = Resource.class.getMethod("setCount", int.class);
    Descriptor operationDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "targetObject"
                              }, new Object[] {
                                "operation", "operation", resource1
                              });
    Descriptor getCountDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "targetObject"
                              }, new Object[] {
                                "operation", "getCount", resource2
                              });
    Descriptor setCountDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "targetObject"
                              }, new Object[] {
                                "operation", "setCount", resource2
                              });
    Descriptor countDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "getMethod", "setMethod"
                              }, new Object[] {
                                "attribute", "Count", "getCount", "setCount"
                              });
    ModelMBeanOperationInfo operationInfo =
        new ModelMBeanOperationInfo("operation description",
                                    operationMethod, operationDescriptor);
    ModelMBeanOperationInfo getCountInfo =
        new ModelMBeanOperationInfo("getCount description",
                                    getCountMethod, getCountDescriptor);
    ModelMBeanOperationInfo setCountInfo =
        new ModelMBeanOperationInfo("setCount description",
                                    setCountMethod, setCountDescriptor);
    ModelMBeanAttributeInfo countInfo =
        new ModelMBeanAttributeInfo("Count", "Count description",
                                    getCountMethod, setCountMethod,
                                    countDescriptor);
    ModelMBeanInfo mmbi =
        new ModelMBeanInfoSupport(Resource.class.getName(),
                                  "ModelMBean to test targetObject",
                                  new ModelMBeanAttributeInfo[] {countInfo},
                                  null,  // no constructors
                                  new ModelMBeanOperationInfo[] {
                                      operationInfo, getCountInfo, setCountInfo
                                  },
                                  null); // no notifications
    ModelMBean mmb = new RequiredModelMBean(mmbi);
    mmb.setManagedResource(resource3, "ObjectReference");
    mbs.registerMBean(mmb, name);
    mbs.invoke(name, "operation", null, null);
    mbs.setAttribute(name, new Attribute("Count", 53));
    if (resource1.operationCount != 1)
        throw new Exception("operationCount: " + resource1.operationCount);
    if (resource2.count != 53)
        throw new Exception("count: " + resource2.count);
    int got = (Integer) mbs.getAttribute(name, "Count");
    if (got != 53)
        throw new Exception("got count: " + got);

    JMXServiceURL url = new JMXServiceURL("rmi", null, 0);
    JMXConnectorServer cs =
        JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
    cs.start();
    JMXServiceURL addr = cs.getAddress();
    JMXConnector cc = JMXConnectorFactory.connect(addr);
    MBeanServerConnection mbsc = cc.getMBeanServerConnection();
    ModelMBeanInfo rmmbi = (ModelMBeanInfo) mbsc.getMBeanInfo(name);
    // Above gets NotSerializableException if resource included in
    // serialized form
    cc.close();
    cs.stop();
    System.out.println("TEST PASSED");
}
 
Example #18
Source File: UnserializableTargetObjectTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    MBeanServer mbs = MBeanServerFactory.newMBeanServer();
    ObjectName name = new ObjectName("a:b=c");
    Resource resource1 = new Resource();
    Resource resource2 = new Resource();
    Resource resource3 = new Resource();
    Method operationMethod = Resource.class.getMethod("operation");
    Method getCountMethod = Resource.class.getMethod("getCount");
    Method setCountMethod = Resource.class.getMethod("setCount", int.class);
    Descriptor operationDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "targetObject"
                              }, new Object[] {
                                "operation", "operation", resource1
                              });
    Descriptor getCountDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "targetObject"
                              }, new Object[] {
                                "operation", "getCount", resource2
                              });
    Descriptor setCountDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "targetObject"
                              }, new Object[] {
                                "operation", "setCount", resource2
                              });
    Descriptor countDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "getMethod", "setMethod"
                              }, new Object[] {
                                "attribute", "Count", "getCount", "setCount"
                              });
    ModelMBeanOperationInfo operationInfo =
        new ModelMBeanOperationInfo("operation description",
                                    operationMethod, operationDescriptor);
    ModelMBeanOperationInfo getCountInfo =
        new ModelMBeanOperationInfo("getCount description",
                                    getCountMethod, getCountDescriptor);
    ModelMBeanOperationInfo setCountInfo =
        new ModelMBeanOperationInfo("setCount description",
                                    setCountMethod, setCountDescriptor);
    ModelMBeanAttributeInfo countInfo =
        new ModelMBeanAttributeInfo("Count", "Count description",
                                    getCountMethod, setCountMethod,
                                    countDescriptor);
    ModelMBeanInfo mmbi =
        new ModelMBeanInfoSupport(Resource.class.getName(),
                                  "ModelMBean to test targetObject",
                                  new ModelMBeanAttributeInfo[] {countInfo},
                                  null,  // no constructors
                                  new ModelMBeanOperationInfo[] {
                                      operationInfo, getCountInfo, setCountInfo
                                  },
                                  null); // no notifications
    ModelMBean mmb = new RequiredModelMBean(mmbi);
    mmb.setManagedResource(resource3, "ObjectReference");
    mbs.registerMBean(mmb, name);
    mbs.invoke(name, "operation", null, null);
    mbs.setAttribute(name, new Attribute("Count", 53));
    if (resource1.operationCount != 1)
        throw new Exception("operationCount: " + resource1.operationCount);
    if (resource2.count != 53)
        throw new Exception("count: " + resource2.count);
    int got = (Integer) mbs.getAttribute(name, "Count");
    if (got != 53)
        throw new Exception("got count: " + got);

    JMXServiceURL url = new JMXServiceURL("rmi", null, 0);
    JMXConnectorServer cs =
        JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
    cs.start();
    JMXServiceURL addr = cs.getAddress();
    JMXConnector cc = JMXConnectorFactory.connect(addr);
    MBeanServerConnection mbsc = cc.getMBeanServerConnection();
    ModelMBeanInfo rmmbi = (ModelMBeanInfo) mbsc.getMBeanInfo(name);
    // Above gets NotSerializableException if resource included in
    // serialized form
    cc.close();
    cs.stop();
    System.out.println("TEST PASSED");
}
 
Example #19
Source File: UnserializableTargetObjectTest.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    MBeanServer mbs = MBeanServerFactory.newMBeanServer();
    ObjectName name = new ObjectName("a:b=c");
    Resource resource1 = new Resource();
    Resource resource2 = new Resource();
    Resource resource3 = new Resource();
    Method operationMethod = Resource.class.getMethod("operation");
    Method getCountMethod = Resource.class.getMethod("getCount");
    Method setCountMethod = Resource.class.getMethod("setCount", int.class);
    Descriptor operationDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "targetObject"
                              }, new Object[] {
                                "operation", "operation", resource1
                              });
    Descriptor getCountDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "targetObject"
                              }, new Object[] {
                                "operation", "getCount", resource2
                              });
    Descriptor setCountDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "targetObject"
                              }, new Object[] {
                                "operation", "setCount", resource2
                              });
    Descriptor countDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "getMethod", "setMethod"
                              }, new Object[] {
                                "attribute", "Count", "getCount", "setCount"
                              });
    ModelMBeanOperationInfo operationInfo =
        new ModelMBeanOperationInfo("operation description",
                                    operationMethod, operationDescriptor);
    ModelMBeanOperationInfo getCountInfo =
        new ModelMBeanOperationInfo("getCount description",
                                    getCountMethod, getCountDescriptor);
    ModelMBeanOperationInfo setCountInfo =
        new ModelMBeanOperationInfo("setCount description",
                                    setCountMethod, setCountDescriptor);
    ModelMBeanAttributeInfo countInfo =
        new ModelMBeanAttributeInfo("Count", "Count description",
                                    getCountMethod, setCountMethod,
                                    countDescriptor);
    ModelMBeanInfo mmbi =
        new ModelMBeanInfoSupport(Resource.class.getName(),
                                  "ModelMBean to test targetObject",
                                  new ModelMBeanAttributeInfo[] {countInfo},
                                  null,  // no constructors
                                  new ModelMBeanOperationInfo[] {
                                      operationInfo, getCountInfo, setCountInfo
                                  },
                                  null); // no notifications
    ModelMBean mmb = new RequiredModelMBean(mmbi);
    mmb.setManagedResource(resource3, "ObjectReference");
    mbs.registerMBean(mmb, name);
    mbs.invoke(name, "operation", null, null);
    mbs.setAttribute(name, new Attribute("Count", 53));
    if (resource1.operationCount != 1)
        throw new Exception("operationCount: " + resource1.operationCount);
    if (resource2.count != 53)
        throw new Exception("count: " + resource2.count);
    int got = (Integer) mbs.getAttribute(name, "Count");
    if (got != 53)
        throw new Exception("got count: " + got);

    JMXServiceURL url = new JMXServiceURL("rmi", null, 0);
    JMXConnectorServer cs =
        JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
    cs.start();
    JMXServiceURL addr = cs.getAddress();
    JMXConnector cc = JMXConnectorFactory.connect(addr);
    MBeanServerConnection mbsc = cc.getMBeanServerConnection();
    ModelMBeanInfo rmmbi = (ModelMBeanInfo) mbsc.getMBeanInfo(name);
    // Above gets NotSerializableException if resource included in
    // serialized form
    cc.close();
    cs.stop();
    System.out.println("TEST PASSED");
}
 
Example #20
Source File: MBeanInfoAssembler.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
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;
  }
 
Example #21
Source File: AbstractMBeanInfoAssembler.java    From spring4-understanding with Apache License 2.0 3 votes vote down vote up
/**
 * Create an instance of the {@code ModelMBeanInfoSupport} class supplied with all
 * JMX implementations and populates the metadata through calls to the subclass.
 * @param managedBean the bean that will be exposed (might be an AOP proxy)
 * @param beanKey the key associated with the managed bean
 * @return the populated ModelMBeanInfo instance
 * @throws JMException in case of errors
 * @see #getDescription(Object, String)
 * @see #getAttributeInfo(Object, String)
 * @see #getConstructorInfo(Object, String)
 * @see #getOperationInfo(Object, String)
 * @see #getNotificationInfo(Object, String)
 * @see #populateMBeanDescriptor(javax.management.Descriptor, Object, String)
 */
@Override
public ModelMBeanInfo getMBeanInfo(Object managedBean, String beanKey) throws JMException {
	checkManagedBean(managedBean);
	ModelMBeanInfo info = new ModelMBeanInfoSupport(
			getClassName(managedBean, beanKey), getDescription(managedBean, beanKey),
			getAttributeInfo(managedBean, beanKey), getConstructorInfo(managedBean, beanKey),
			getOperationInfo(managedBean, beanKey), getNotificationInfo(managedBean, beanKey));
	Descriptor desc = info.getMBeanDescriptor();
	populateMBeanDescriptor(desc, managedBean, beanKey);
	info.setMBeanDescriptor(desc);
	return info;
}
 
Example #22
Source File: AbstractMBeanInfoAssembler.java    From lams with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Create an instance of the {@code ModelMBeanInfoSupport} class supplied with all
 * JMX implementations and populates the metadata through calls to the subclass.
 * @param managedBean the bean that will be exposed (might be an AOP proxy)
 * @param beanKey the key associated with the managed bean
 * @return the populated ModelMBeanInfo instance
 * @throws JMException in case of errors
 * @see #getDescription(Object, String)
 * @see #getAttributeInfo(Object, String)
 * @see #getConstructorInfo(Object, String)
 * @see #getOperationInfo(Object, String)
 * @see #getNotificationInfo(Object, String)
 * @see #populateMBeanDescriptor(javax.management.Descriptor, Object, String)
 */
@Override
public ModelMBeanInfo getMBeanInfo(Object managedBean, String beanKey) throws JMException {
	checkManagedBean(managedBean);
	ModelMBeanInfo info = new ModelMBeanInfoSupport(
			getClassName(managedBean, beanKey), getDescription(managedBean, beanKey),
			getAttributeInfo(managedBean, beanKey), getConstructorInfo(managedBean, beanKey),
			getOperationInfo(managedBean, beanKey), getNotificationInfo(managedBean, beanKey));
	Descriptor desc = info.getMBeanDescriptor();
	populateMBeanDescriptor(desc, managedBean, beanKey);
	info.setMBeanDescriptor(desc);
	return info;
}
 
Example #23
Source File: AbstractMBeanInfoAssembler.java    From java-technology-stack with MIT License 3 votes vote down vote up
/**
 * Create an instance of the {@code ModelMBeanInfoSupport} class supplied with all
 * JMX implementations and populates the metadata through calls to the subclass.
 * @param managedBean the bean that will be exposed (might be an AOP proxy)
 * @param beanKey the key associated with the managed bean
 * @return the populated ModelMBeanInfo instance
 * @throws JMException in case of errors
 * @see #getDescription(Object, String)
 * @see #getAttributeInfo(Object, String)
 * @see #getConstructorInfo(Object, String)
 * @see #getOperationInfo(Object, String)
 * @see #getNotificationInfo(Object, String)
 * @see #populateMBeanDescriptor(javax.management.Descriptor, Object, String)
 */
@Override
public ModelMBeanInfo getMBeanInfo(Object managedBean, String beanKey) throws JMException {
	checkManagedBean(managedBean);
	ModelMBeanInfo info = new ModelMBeanInfoSupport(
			getClassName(managedBean, beanKey), getDescription(managedBean, beanKey),
			getAttributeInfo(managedBean, beanKey), getConstructorInfo(managedBean, beanKey),
			getOperationInfo(managedBean, beanKey), getNotificationInfo(managedBean, beanKey));
	Descriptor desc = info.getMBeanDescriptor();
	populateMBeanDescriptor(desc, managedBean, beanKey);
	info.setMBeanDescriptor(desc);
	return info;
}
 
Example #24
Source File: AbstractMBeanInfoAssembler.java    From spring-analysis-note with MIT License 3 votes vote down vote up
/**
 * Create an instance of the {@code ModelMBeanInfoSupport} class supplied with all
 * JMX implementations and populates the metadata through calls to the subclass.
 * @param managedBean the bean that will be exposed (might be an AOP proxy)
 * @param beanKey the key associated with the managed bean
 * @return the populated ModelMBeanInfo instance
 * @throws JMException in case of errors
 * @see #getDescription(Object, String)
 * @see #getAttributeInfo(Object, String)
 * @see #getConstructorInfo(Object, String)
 * @see #getOperationInfo(Object, String)
 * @see #getNotificationInfo(Object, String)
 * @see #populateMBeanDescriptor(javax.management.Descriptor, Object, String)
 */
@Override
public ModelMBeanInfo getMBeanInfo(Object managedBean, String beanKey) throws JMException {
	checkManagedBean(managedBean);
	ModelMBeanInfo info = new ModelMBeanInfoSupport(
			getClassName(managedBean, beanKey), getDescription(managedBean, beanKey),
			getAttributeInfo(managedBean, beanKey), getConstructorInfo(managedBean, beanKey),
			getOperationInfo(managedBean, beanKey), getNotificationInfo(managedBean, beanKey));
	Descriptor desc = info.getMBeanDescriptor();
	populateMBeanDescriptor(desc, managedBean, beanKey);
	info.setMBeanDescriptor(desc);
	return info;
}