Example usage for org.springframework.jmx.support JmxUtils isMBean

List of usage examples for org.springframework.jmx.support JmxUtils isMBean

Introduction

In this page you can find the example usage for org.springframework.jmx.support JmxUtils isMBean.

Prototype

public static boolean isMBean(@Nullable Class<?> clazz) 

Source Link

Document

Determine whether the given bean class qualifies as an MBean as-is.

Usage

From source file:cyrille.springframework.jmx.JmxUtilsTest.java

public void testIsMBean() throws Exception {
    {//from w w  w.  j  a  v  a  2s  . c o  m
        boolean actual = JmxUtils.isMBean(org.springframework.jmx.support.ConnectorServerFactoryBean.class);
        System.out.println("isMBean(ConnectorServerFactoryBean.class): " + actual);
    }

    // MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
    // JMXServiceURL serviceURL = new
    // JMXServiceURL("service:jmx:rmi://localhost/jndi/rmi://localhost:1099/server");
    // JMXConnectorServer connectorServer =
    // JMXConnectorServerFactory.newJMXConnectorServer(serviceURL, null,
    // mbeanServer);
    {
        boolean actual = JmxUtils.isMBean(JMXConnectorServer.class);
        System.out.println("isMBean(JMXConnectorServer.class): " + actual);
    }

}

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

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

From source file:org.springframework.jmx.export.MBeanExporter.java

/**
 * Registers an existing MBean or an MBean adapter for a plain bean
 * with the <code>MBeanServer</code>.
 * @param beanInstance the bean to register, either an MBean or a plain bean
 * @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
 *///from w  ww .  j  av a2 s.co m
private ObjectName registerBeanInstance(Object beanInstance, String beanKey)
        throws JMException, InvalidTargetObjectTypeException {

    if (JmxUtils.isMBean(beanInstance.getClass())) {
        if (logger.isDebugEnabled()) {
            logger.debug("Located MBean under key [" + beanKey + "]: registering with JMX server");
        }
        return registerMBean(beanInstance, beanKey);
    } else {
        if (logger.isDebugEnabled()) {
            logger.debug("Located bean under key [" + beanKey + "] registering with JMX server.");
        }
        return registerSimpleBean(beanInstance, beanKey);
    }
}

From source file:org.springframework.jmx.export.MBeanExporter.java

/**
 * Attempts to detect any beans defined in the <code>ApplicationContext</code> that are
 * valid MBeans and registers them automatically with the <code>MBeanServer</code>.
 *///from   w w  w  . java2 s .com
private void autodetectMBeans() {
    autodetect(new AutodetectCallback() {
        public boolean include(Class beanClass, String beanName) {
            return JmxUtils.isMBean(beanClass);
        }
    });
}