List of usage examples for javax.management.modelmbean RequiredModelMBean setModelMBeanInfo
public void setModelMBeanInfo(ModelMBeanInfo mbi) throws MBeanException, RuntimeOperationsException
From source file:org.apache.camel.management.JmxMBeanAssembler.java
public RequiredModelMBean assemble(Object obj, ObjectName name) throws JMException { ModelMBeanInfo mbi = null;/* w w w . ja v a 2 s . c o m*/ // prefer to use the managed instance if it has been annotated with Spring JMX annotations if (obj instanceof ManagedInstance) { Object custom = ((ManagedInstance) obj).getInstance(); if (custom != null && ObjectHelper.hasAnnotation(custom.getClass().getAnnotations(), ManagedResource.class)) { if (LOG.isTraceEnabled()) { LOG.trace("Assembling MBeanInfo for: " + name.toString() + " from custom @ManagedResource object: " + custom); } // get the mbean info from the custom managed object mbi = assembler.getMBeanInfo(custom, name.toString()); // and let the custom object be registered in JMX obj = custom; } } if (mbi == null) { // use the default provided mbean which has been annotated with Spring JMX annotations if (LOG.isTraceEnabled()) { LOG.trace("Assembling MBeanInfo for: " + name.toString() + " from @ManagedResource object: " + obj); } mbi = assembler.getMBeanInfo(obj, name.toString()); } RequiredModelMBean mbean = (RequiredModelMBean) server.instantiate(RequiredModelMBean.class.getName()); mbean.setModelMBeanInfo(mbi); try { mbean.setManagedResource(obj, "ObjectReference"); } catch (InvalidTargetObjectTypeException e) { throw new JMException(e.getMessage()); } return mbean; }
From source file:org.apache.servicemix.nmr.management.ManagementAgent.java
public void register(Object obj, ObjectName name, boolean forceRegistration) throws JMException { try {/*from w ww. j a v a 2s . c o m*/ registerMBeanWithServer(obj, name, forceRegistration); } catch (NotCompliantMBeanException e) { // If this is not a "normal" MBean, then try to deploy it using JMX // annotations ModelMBeanInfo mbi = assembler.getMBeanInfo(obj, name.toString()); RequiredModelMBean mbean = (RequiredModelMBean) mbeanServer .instantiate(RequiredModelMBean.class.getName()); mbean.setModelMBeanInfo(mbi); try { mbean.setManagedResource(obj, "ObjectReference"); } catch (InvalidTargetObjectTypeException itotex) { throw new JMException(itotex.getMessage()); } registerMBeanWithServer(mbean, name, forceRegistration); } }
From source file:org.jolokia.jmx.JolokiaMBeanServerTest.java
@Test public void withModelMBean() throws MBeanException, InvalidTargetObjectTypeException, InstanceNotFoundException, InstanceAlreadyExistsException, NotCompliantMBeanException, MalformedObjectNameException, NoSuchMethodException, IntrospectionException { RequiredModelMBean modelMBean = new RequiredModelMBean(); ModelMBeanInfo mbi = new ModelMBeanInfoSupport(JsonAnnoPlainTest.class.getName(), "JsonMBean Test", new ModelMBeanAttributeInfo[] { new ModelMBeanAttributeInfo("DeepDive", "description", JsonAnnoPlainTest.class.getDeclaredMethod("getDeepDive"), null) }, new ModelMBeanConstructorInfo[] {}, new ModelMBeanOperationInfo[] {}, new ModelMBeanNotificationInfo[] {}); modelMBean.setModelMBeanInfo(mbi); modelMBean.setManagedResource(new JsonAnnoPlainTest(), "ObjectReference"); JolokiaMBeanServer server = new JolokiaMBeanServer(); ObjectName oName = new ObjectName("test:type=jsonMBean"); server.registerMBean(modelMBean, oName); MBeanServer plattformServer = ManagementFactory.getPlatformMBeanServer(); Assert.assertTrue(plattformServer.isRegistered(oName)); Assert.assertTrue(server.isRegistered(oName)); server.unregisterMBean(oName);/*from ww w . j a va2s . c o m*/ Assert.assertFalse(plattformServer.isRegistered(oName)); Assert.assertFalse(server.isRegistered(oName)); }