javax.management.modelmbean.RequiredModelMBean Java Examples
The following examples show how to use
javax.management.modelmbean.RequiredModelMBean.
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: JmxMbeanHelper.java From iaf with Apache License 2.0 | 6 votes |
/** * Registers an mBean at an MBeanServer. If there is already an mbean registered * under the specified name, it is first de-registered. */ private static ObjectInstance registerMBean(MBeanServer server, ObjectName name, RequiredModelMBean mbean) throws ConfigurationException { try { if (server.isRegistered(name)) { LOG.debug("unregistering [" + name.getCanonicalName() + "] as it already exists"); server.unregisterMBean(name); } ObjectInstance objectInstance = server.registerMBean(mbean, name); LOG.debug("MBean [" + name.getCanonicalName() + "] registered as [" + objectInstance.getObjectName().getCanonicalName()+"]"); return objectInstance; } catch (InstanceAlreadyExistsException iae) { LOG.warn("Could not register mbean [" + name.getCanonicalName() + "]:" + iae.getMessage()); } catch (Exception e) { throw new ConfigurationException(e); } return null; }
Example #2
Source File: JmxMbeanHelper.java From iaf with Apache License 2.0 | 6 votes |
/** * Hooks an {@link nl.nn.adapterframework.core.Adapter Adapter} to the MBean server */ public static void hookupAdapter(IAdapter adapter) throws ConfigurationException { MBeanServer server = getMBeanServer(); if (server != null) { synchronized(registeredAdapters) { try { ObjectName objectName = getObjectName(adapter); RequiredModelMBean modelMbean = new RequiredModelMBean(createMBeanInfo(adapter)); modelMbean.setManagedResource(adapter, "ObjectReference"); LOG.debug("modelMBean generated for object " + objectName); ObjectInstance objectInstance = registerMBean(server, objectName, modelMbean); if (objectInstance!=null) { registeredAdapters.put(adapter, objectInstance.getObjectName()); } } catch (Exception e) { throw new ConfigurationException(e); } } } else { LOG.warn("No MBean server found"); } }
Example #3
Source File: DefaultManagementAgentTest.java From flowable-engine with Apache License 2.0 | 6 votes |
@Test public void testRegisterandUnregister() throws JMException { reset(); // Register MBean and return different ObjectName when(mbeanServer.isRegistered(sourceObjectName)).thenReturn(false); when(mbeanServer.registerMBean(any(RequiredModelMBean.class), any(ObjectName.class))).thenReturn(instance); when(instance.getObjectName()).thenReturn(registeredObjectName); when(mbeanServer.isRegistered(registeredObjectName)).thenReturn(true); agent.register(object, sourceObjectName); verify(mbeanServer).isRegistered(sourceObjectName); verify(mbeanServer).registerMBean(any(RequiredModelMBean.class), any(ObjectName.class)); assertTrue(agent.isRegistered(sourceObjectName)); agent.unregister(sourceObjectName); verify(mbeanServer).unregisterMBean(registeredObjectName); assertFalse(agent.isRegistered(sourceObjectName)); }
Example #4
Source File: DefaultManagementAgentTest.java From activiti6-boot2 with Apache License 2.0 | 6 votes |
@Test public void testRegisterandUnregister() throws JMException { reset(); // Register MBean and return different ObjectName when(mbeanServer.isRegistered(sourceObjectName)).thenReturn(false); when(mbeanServer.registerMBean(any(RequiredModelMBean.class), any(ObjectName.class))).thenReturn(instance); when(instance.getObjectName()).thenReturn(registeredObjectName); when(mbeanServer.isRegistered(registeredObjectName)).thenReturn(true); agent.register(object, sourceObjectName); verify(mbeanServer).isRegistered(sourceObjectName); verify(mbeanServer).registerMBean(any(RequiredModelMBean.class), any(ObjectName.class)); assertTrue(agent.isRegistered(sourceObjectName)); agent.unregister(sourceObjectName); verify(mbeanServer).unregisterMBean(registeredObjectName); assertFalse(agent.isRegistered(sourceObjectName)); }
Example #5
Source File: MBeanExporterOperationsTests.java From spring-analysis-note with MIT License | 5 votes |
@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: JmxUtils.java From iaf with Apache License 2.0 | 5 votes |
/** * Registers an mBean at an MBeanServer. If there is already an mbean registered * under the specified name, it is first de-registered. * @param name the objectName * @param mbean the modelMbean to register */ public static void registerMBean(ObjectName name, RequiredModelMBean mbean) throws Exception { MBeanServer server = getMBeanServer(); // if (server.isRegistered(name)) { // log.debug("unregistering ["+name.getCanonicalName()+"] as it already exists"); // server.unregisterMBean(name); // } server.registerMBean(mbean, name); log.debug("MBean [" + name.getCanonicalName() + "] registered"); return; }
Example #7
Source File: InstrumentationManagerImpl.java From cxf with Apache License 2.0 | 5 votes |
private void register(Object obj, ObjectName name, ModelMBeanInfo mbi, boolean forceRegistration) throws JMException { RequiredModelMBean rtMBean = (RequiredModelMBean)mbs.instantiate("javax.management.modelmbean.RequiredModelMBean"); rtMBean.setModelMBeanInfo(mbi); try { rtMBean.setManagedResource(obj, "ObjectReference"); } catch (InvalidTargetObjectTypeException itotex) { throw new JMException(itotex.getMessage()); } registerMBeanWithServer(rtMBean, persist(name), forceRegistration); }
Example #8
Source File: RMEndpoint.java From cxf with Apache License 2.0 | 5 votes |
void initialise(RMConfiguration config, Conduit c, EndpointReferenceType r, org.apache.cxf.transport.Destination d, Message message) { configuration = config; conduit = c; replyTo = r; createServices(); createEndpoints(d); setPolicies(message); if (manager != null && manager.getBus() != null) { managedEndpoint = new ManagedRMEndpoint(this); instrumentationManager = manager.getBus().getExtension(InstrumentationManager.class); if (instrumentationManager != null) { ModelMBeanAssembler assembler = new ModelMBeanAssembler(); ModelMBeanInfo mbi = assembler.getModelMbeanInfo(managedEndpoint.getClass()); MBeanServer mbs = instrumentationManager.getMBeanServer(); if (mbs == null) { LOG.log(Level.WARNING, "MBeanServer not available."); } else { try { RequiredModelMBean rtMBean = (RequiredModelMBean)mbs.instantiate("javax.management.modelmbean.RequiredModelMBean"); rtMBean.setModelMBeanInfo(mbi); try { rtMBean.setManagedResource(managedEndpoint, "ObjectReference"); } catch (InvalidTargetObjectTypeException itotex) { throw new JMException(itotex.getMessage()); } ObjectName name = managedEndpoint.getObjectName(); instrumentationManager.register(rtMBean, name); modelMBean = rtMBean; } catch (JMException jmex) { LOG.log(Level.WARNING, "Registering ManagedRMEndpoint failed.", jmex); } } } } }
Example #9
Source File: DefaultManagementMBeanAssembler.java From flowable-engine with Apache License 2.0 | 5 votes |
@Override public ModelMBean assemble(Object obj, ObjectName name) throws JMException { ModelMBeanInfo mbi = null; // use the default provided mbean which has been annotated with JMX annotations LOGGER.trace("Assembling MBeanInfo for: {} from @ManagedResource object: {}", name, obj); mbi = assembler.getMBeanInfo(obj, null, name.toString()); if (mbi == null) { return null; } RequiredModelMBean mbean = new RequiredModelMBean(mbi); try { mbean.setManagedResource(obj, "ObjectReference"); } catch (InvalidTargetObjectTypeException e) { throw new JMException(e.getMessage()); } // Allows the managed object to send notifications if (obj instanceof NotificationSenderAware) { ((NotificationSenderAware) obj).setNotificationSender(new NotificationSenderAdapter(mbean)); } return mbean; }
Example #10
Source File: MBeanExporterOperationsTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@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 #11
Source File: MBeanExporterOperationsTests.java From java-technology-stack with MIT License | 5 votes |
@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 #12
Source File: RequiredModelMBeanBootstrap.java From thinking-in-spring-boot-samples with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws Exception { // 获取当前平台 MBean Server MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer(); RequiredModelMBean modelMBean = new RequiredModelMBean(); modelMBean.setManagedResource(new User(), "objectReference"); // 创建 RequiredModelMBean 的 ObjectName ObjectName objectName = new ObjectName("thinking.in.spring.boot.samples.production.ready.jmx:type=User"); mBeanServer.registerMBean(modelMBean, objectName); System.out.printf("MBean (ObjectName[%s])已注册到平台 MBean Server...\n", objectName); System.out.println("按任意键结束..."); System.in.read(); }
Example #13
Source File: DefaultManagementMBeanAssembler.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
public ModelMBean assemble(Object obj, ObjectName name) throws JMException { ModelMBeanInfo mbi = null; // use the default provided mbean which has been annotated with JMX // annotations LOG.trace("Assembling MBeanInfo for: {} from @ManagedResource object: {}", name, obj); mbi = assembler.getMBeanInfo(obj, null, name.toString()); if (mbi == null) { return null; } RequiredModelMBean mbean = new RequiredModelMBean(mbi); try { mbean.setManagedResource(obj, "ObjectReference"); } catch (InvalidTargetObjectTypeException e) { throw new JMException(e.getMessage()); } // Allows the managed object to send notifications if (obj instanceof NotificationSenderAware) { ((NotificationSenderAware) obj).setNotificationSender(new NotificationSenderAdapter(mbean)); } return mbean; }
Example #14
Source File: UnserializableTargetObjectTest.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
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 jdk8u-dev-jdk with GNU General Public License v2.0 | 4 votes |
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 |
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 jdk8u60 with GNU General Public License v2.0 | 4 votes |
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 jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
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-8 with GNU General Public License v2.0 | 4 votes |
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: UnserializableTargetObjectTest.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
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 #21
Source File: UnserializableTargetObjectTest.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
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 #22
Source File: UnserializableTargetObjectTest.java From hottub with GNU General Public License v2.0 | 4 votes |
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 #23
Source File: UnserializableTargetObjectTest.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
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 #24
Source File: UnserializableTargetObjectTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
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 #25
Source File: UnserializableTargetObjectTest.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
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 #26
Source File: UnserializableTargetObjectTest.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
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 #27
Source File: MBeanExporter.java From spring-analysis-note with MIT License | 2 votes |
/** * Create an instance of a class that implements {@code ModelMBean}. * <p>This method is called to obtain a {@code ModelMBean} instance to * use when registering a bean. This method is called once per bean during the * registration phase and must return a new instance of {@code ModelMBean} * @return a new instance of a class that implements {@code ModelMBean} * @throws javax.management.MBeanException if creation of the ModelMBean failed */ protected ModelMBean createModelMBean() throws MBeanException { return (this.exposeManagedResourceClassLoader ? new SpringModelMBean() : new RequiredModelMBean()); }
Example #28
Source File: MBeanExporter.java From java-technology-stack with MIT License | 2 votes |
/** * Create an instance of a class that implements {@code ModelMBean}. * <p>This method is called to obtain a {@code ModelMBean} instance to * use when registering a bean. This method is called once per bean during the * registration phase and must return a new instance of {@code ModelMBean} * @return a new instance of a class that implements {@code ModelMBean} * @throws javax.management.MBeanException if creation of the ModelMBean failed */ protected ModelMBean createModelMBean() throws MBeanException { return (this.exposeManagedResourceClassLoader ? new SpringModelMBean() : new RequiredModelMBean()); }
Example #29
Source File: MBeanExporter.java From spring4-understanding with Apache License 2.0 | 2 votes |
/** * Create an instance of a class that implements {@code ModelMBean}. * <p>This method is called to obtain a {@code ModelMBean} instance to * use when registering a bean. This method is called once per bean during the * registration phase and must return a new instance of {@code ModelMBean} * @return a new instance of a class that implements {@code ModelMBean} * @throws javax.management.MBeanException if creation of the ModelMBean failed */ protected ModelMBean createModelMBean() throws MBeanException { return (this.exposeManagedResourceClassLoader ? new SpringModelMBean() : new RequiredModelMBean()); }
Example #30
Source File: MBeanExporter.java From lams with GNU General Public License v2.0 | 2 votes |
/** * Create an instance of a class that implements {@code ModelMBean}. * <p>This method is called to obtain a {@code ModelMBean} instance to * use when registering a bean. This method is called once per bean during the * registration phase and must return a new instance of {@code ModelMBean} * @return a new instance of a class that implements {@code ModelMBean} * @throws javax.management.MBeanException if creation of the ModelMBean failed */ protected ModelMBean createModelMBean() throws MBeanException { return (this.exposeManagedResourceClassLoader ? new SpringModelMBean() : new RequiredModelMBean()); }