Search in sources :

Example 41 with StandardMBean

use of javax.management.StandardMBean in project sonarqube by SonarSource.

the class Jmx method register.

/**
 * Register a MBean to JMX server
 */
public static void register(String name, Object instance) {
    try {
        Class<Object> mbeanInterface = guessMBeanInterface(instance);
        ManagementFactory.getPlatformMBeanServer().registerMBean(new StandardMBean(instance, mbeanInterface), new ObjectName(name));
    } catch (MalformedObjectNameException | NotCompliantMBeanException | InstanceAlreadyExistsException | MBeanRegistrationException e) {
        throw new IllegalStateException("Can not register MBean [" + name + "]", e);
    }
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) StandardMBean(javax.management.StandardMBean) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) MBeanRegistrationException(javax.management.MBeanRegistrationException) ObjectName(javax.management.ObjectName)

Example 42 with StandardMBean

use of javax.management.StandardMBean in project scheduling by ow2-proactive.

the class RMJMXHelper method registerMBeans.

/**
 * {@inheritDoc}
 */
@Override
public void registerMBeans(final MBeanServer mbs) {
    // Register all mbeans into the server
    try {
        final RuntimeDataMBean anonymMBean = new RuntimeDataMBeanImpl(RMMonitoringImpl.rmStatistics);
        // Uniquely identify the MBean and register it to the MBeanServer
        final ObjectName name = new ObjectName(RMJMXBeans.RUNTIMEDATA_MBEAN_NAME);
        mbs.registerMBean(anonymMBean, name);
        String dataBaseName = PAResourceManagerProperties.getAbsolutePath(PAResourceManagerProperties.RM_RRD_DATABASE_NAME.getValueAsString());
        FileUtils.forceMkdir(new File(dataBaseName).getParentFile());
        setDataStore(new RRDDataStore((StandardMBean) anonymMBean, dataBaseName, PAResourceManagerProperties.RM_RRD_STEP.getValueAsInt(), Logger.getLogger(RMJMXHelper.class)));
    } catch (Exception e) {
        LOGGER.error("Unable to register the ResourceManagerRuntimeMBean", e);
    }
    // Register the MyAccount MBean into the MBean server
    try {
        final MyAccountMBeanImpl myAccountMBean = new MyAccountMBeanImpl(this.accountsManager);
        final ObjectName name = new ObjectName(RMJMXBeans.MYACCOUNT_MBEAN_NAME);
        mbs.registerMBean(myAccountMBean, name);
    } catch (Exception e) {
        LOGGER.error("Unable to register the MyAccountMBean", e);
    }
    // Register the ViewAccount MBean into the MBean server
    try {
        final AllAccountsMBeanImpl viewAccountMBean = new AllAccountsMBeanImpl(this.accountsManager);
        final ObjectName name = new ObjectName(RMJMXBeans.ALLACCOUNTS_MBEAN_NAME);
        mbs.registerMBean(viewAccountMBean, name);
    } catch (Exception e) {
        LOGGER.error("Unable to register the AllAccountsMBean", e);
    }
    // Register the Management MBean into the MBean server
    try {
        final ManagementMBeanImpl managementMBean = new ManagementMBeanImpl(this.accountsManager);
        final ObjectName name = new ObjectName(RMJMXBeans.MANAGEMENT_MBEAN_NAME);
        mbs.registerMBean(managementMBean, name);
    } catch (Exception e) {
        LOGGER.error("Unable to register the ManagementMBean", e);
    }
}
Also used : AllAccountsMBeanImpl(org.ow2.proactive.resourcemanager.core.jmx.mbean.AllAccountsMBeanImpl) MyAccountMBeanImpl(org.ow2.proactive.resourcemanager.core.jmx.mbean.MyAccountMBeanImpl) RuntimeDataMBeanImpl(org.ow2.proactive.resourcemanager.core.jmx.mbean.RuntimeDataMBeanImpl) StandardMBean(javax.management.StandardMBean) ManagementMBeanImpl(org.ow2.proactive.resourcemanager.core.jmx.mbean.ManagementMBeanImpl) RRDDataStore(org.ow2.proactive.jmx.RRDDataStore) RuntimeDataMBean(org.ow2.proactive.resourcemanager.core.jmx.mbean.RuntimeDataMBean) File(java.io.File) ObjectName(javax.management.ObjectName)

Example 43 with StandardMBean

use of javax.management.StandardMBean in project spring-framework by spring-projects.

the class JmxUtilsTests method testIsMBeanWithStandardMBeanInherited.

@Test
public void testIsMBeanWithStandardMBeanInherited() throws Exception {
    StandardMBean mbean = new StandardMBeanImpl();
    assertTrue("Standard MBean not detected correctly", JmxUtils.isMBean(mbean.getClass()));
}
Also used : StandardMBean(javax.management.StandardMBean) Test(org.junit.Test)

Example 44 with StandardMBean

use of javax.management.StandardMBean in project spring-framework by spring-projects.

the class JmxUtilsTests method testIsMBeanWithStandardMBeanWrapper.

@Test
public void testIsMBeanWithStandardMBeanWrapper() throws Exception {
    StandardMBean mbean = new StandardMBean(new JmxTestBean(), IJmxTestBean.class);
    assertTrue("Standard MBean not detected correctly", JmxUtils.isMBean(mbean.getClass()));
}
Also used : StandardMBean(javax.management.StandardMBean) JmxTestBean(org.springframework.jmx.JmxTestBean) IJmxTestBean(org.springframework.jmx.IJmxTestBean) Test(org.junit.Test)

Example 45 with StandardMBean

use of javax.management.StandardMBean in project archaius by Netflix.

the class ConfigJMXManager method registerConfigMbean.

public static ConfigMBean registerConfigMbean(AbstractConfiguration config) {
    StandardMBean mbean = null;
    ConfigMBean bean = null;
    try {
        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        bean = new BaseConfigMBean(config);
        mbean = new StandardMBean(bean, ConfigMBean.class);
        mbs.registerMBean(mbean, getJMXObjectName(config, bean));
    } catch (NotCompliantMBeanException e) {
        throw new RuntimeException("NotCompliantMBeanException", e);
    } catch (InstanceAlreadyExistsException e) {
        throw new RuntimeException("InstanceAlreadyExistsException", e);
    } catch (MBeanRegistrationException e) {
        throw new RuntimeException("MBeanRegistrationException", e);
    } catch (Exception e) {
        throw new RuntimeException("registerConfigMbeanException", e);
    }
    return bean;
}
Also used : StandardMBean(javax.management.StandardMBean) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) MBeanRegistrationException(javax.management.MBeanRegistrationException) MalformedObjectNameException(javax.management.MalformedObjectNameException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) MBeanRegistrationException(javax.management.MBeanRegistrationException) InstanceNotFoundException(javax.management.InstanceNotFoundException) MBeanServer(javax.management.MBeanServer)

Aggregations

StandardMBean (javax.management.StandardMBean)70 ObjectName (javax.management.ObjectName)32 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)21 MBeanServer (javax.management.MBeanServer)17 MalformedObjectNameException (javax.management.MalformedObjectNameException)16 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)12 MBeanRegistrationException (javax.management.MBeanRegistrationException)9 Test (org.junit.Test)9 JMException (javax.management.JMException)7 IOException (java.io.IOException)6 Logger (org.apache.aries.jmx.Logger)6 InstanceNotFoundException (javax.management.InstanceNotFoundException)5 Activate (org.apache.felix.scr.annotations.Activate)5 IgniteStandardMXBean (org.apache.ignite.internal.mxbean.IgniteStandardMXBean)5 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)5 MBeanInfo (javax.management.MBeanInfo)4 OpenDataException (javax.management.openmbean.OpenDataException)4 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)3 CompositeType (javax.management.openmbean.CompositeType)3 OpenType (javax.management.openmbean.OpenType)3