Example usage for org.springframework.jmx.export.assembler MBeanInfoAssembler getMBeanInfo

List of usage examples for org.springframework.jmx.export.assembler MBeanInfoAssembler getMBeanInfo

Introduction

In this page you can find the example usage for org.springframework.jmx.export.assembler MBeanInfoAssembler getMBeanInfo.

Prototype

ModelMBeanInfo getMBeanInfo(Object managedBean, String beanKey) throws JMException;

Source Link

Document

Create the ModelMBeanInfo for the given managed resource.

Usage

From source file:com.brienwheeler.lib.jmx.MBeanRegistrationSupport.java

public static void registerMBean(Object mbean) {
    try {//  w  w w.j  a  v a 2s  .  c o  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);
    }
}