List of usage examples for javax.management.modelmbean ModelMBean setModelMBeanInfo
public void setModelMBeanInfo(ModelMBeanInfo inModelMBeanInfo) throws MBeanException, RuntimeOperationsException;
From source file:com.brienwheeler.lib.jmx.MBeanRegistrationSupport.java
public static void registerMBean(Object mbean) { try {/* w w w . j a v a2 s. co m*/ ObjectNamingStrategy namingStrategy = new IdentityNamingStrategy(); ObjectName objectName = namingStrategy.getObjectName(mbean, null); MBeanRegistrationSupport registrar = new MBeanRegistrationSupport(); registrar.setServer(JmxUtils.locateMBeanServer()); // if item qualifies as MBean, export it directly if (JmxUtils.isMBean(mbean.getClass())) { registrar.doRegister(mbean, objectName); return; } // assemble MBean info (from annotations by default) ModelMBean modelMBean = new RequiredModelMBean(); modelMBean.setManagedResource(mbean, MR_TYPE_OBJECT_REFERENCE); MBeanInfoAssembler mBeanInfoAssembler = new MetadataMBeanInfoAssembler( new AnnotationJmxAttributeSource()); modelMBean.setModelMBeanInfo(mBeanInfoAssembler.getMBeanInfo(mbean, objectName.getCanonicalName())); registrar.doRegister(modelMBean, objectName); } catch (Exception e) { throw new JmxRegisterException("error registering MBean", e); } }
From source file:com.espertech.esper.metrics.jmx.CommonJMXUtil.java
private static ModelMBean createModelMBean(Object o) { try {//ww w .j ava 2 s .c om ModelMBean mbean = new RequiredModelMBean(); JmxManaged annotation = o.getClass().getAnnotation(JmxManaged.class); String description = annotation == null ? "" : annotation.description(); ModelMBeanInfo info = new ModelMBeanInfoSupport(o.getClass().getName(), description, extractAttributeInfo(o), new ModelMBeanConstructorInfo[0], extractOperationInfo(o), new ModelMBeanNotificationInfo[0]); mbean.setModelMBeanInfo(info); mbean.setManagedResource(o, "ObjectReference"); return mbean; } catch (MBeanException e) { throw new RuntimeException(e); } catch (InvalidTargetObjectTypeException e) { throw new RuntimeException(e); } catch (InstanceNotFoundException e) { throw new RuntimeException(e); } }
From source file:org.atomserver.utils.jmx.NoGetterMBeanExporter.java
protected void doRegister(Object mbean, ObjectName objectName) throws JMException { if (mbean instanceof ModelMBean) { ModelMBean mmb = (ModelMBean) mbean; ModelMBeanInfo mmbi = (ModelMBeanInfo) mmb.getMBeanInfo(); mmb.setModelMBeanInfo(new NoGetterMBeanInfo(mmbi)); }/*w w w . j a v a 2s.co m*/ super.doRegister(mbean, objectName); }
From source file:org.springframework.jmx.export.MBeanExporter.java
/** * Registers a plain bean as MBean with the <code>MBeanServer</code>. * The management interface for the bean is created by the configured * <code>MBeanInfoAssembler</code>. * @param bean the bean instance to register * @param beanKey the key associated with this bean in the beans map * @return the <code>ObjectName</code> under which the bean was registered * with the <code>MBeanServer</code> * @throws JMException in case of an error in the underlying JMX infrastructure * @throws InvalidTargetObjectTypeException an error in the definition of the MBean resource */// w ww .j a v a 2s .c om private ObjectName registerSimpleBean(Object bean, String beanKey) throws JMException, InvalidTargetObjectTypeException { ObjectName objectName = getObjectName(bean, beanKey); if (logger.isDebugEnabled()) { logger.debug("Registering and assembling MBean [" + objectName + "]"); } ModelMBean mbean = createModelMBean(); mbean.setModelMBeanInfo(getMBeanInfo(bean, beanKey)); mbean.setManagedResource(bean, MR_TYPE_OBJECT_REFERENCE); return doRegister(mbean, objectName); }
From source file:org.springframework.jmx.export.MBeanExporter.java
/** * Registers beans that are configured for lazy initialization with the * <code>MBeanServer<code> indirectly through a proxy. * @param beanName the name of the bean in the <code>BeanFactory</code> * @param beanKey the key associated with this bean in the beans map * @return the <code>ObjectName</code> under which the bean was registered * with the <code>MBeanServer</code> * @throws JMException an error in the underlying JMX infrastructure * @throws InvalidTargetObjectTypeException an error in the definition of the MBean resource */// w w w . ja va 2 s .co m private ObjectName registerLazyInit(String beanName, String beanKey) throws JMException, InvalidTargetObjectTypeException { LazyInitTargetSource targetSource = new LazyInitTargetSource(); targetSource.setTargetBeanName(beanName); targetSource.setBeanFactory(this.beanFactory); ProxyFactory proxyFactory = new ProxyFactory(); proxyFactory.setTargetSource(targetSource); proxyFactory.setProxyTargetClass(true); proxyFactory.setFrozen(true); Object proxy = proxyFactory.getProxy(); ObjectName objectName = getObjectName(proxy, beanKey); if (logger.isDebugEnabled()) { logger.debug("Registering lazy-init MBean [" + objectName + "]"); } ModelMBean mbean = createModelMBean(); mbean.setModelMBeanInfo(getMBeanInfo(proxy, beanKey)); mbean.setManagedResource(proxy, MR_TYPE_OBJECT_REFERENCE); return doRegister(mbean, objectName); }