Search in sources :

Example 61 with StandardMBean

use of javax.management.StandardMBean in project atlasdb by palantir.

the class JMXUtils method registerMBeanWeakRefPlusCatchAndLogExceptions.

/**
 * You must retain a reference to the returned {@link DynamicMBean} for as
 * long as you wish this bean to be registered.
 * <p>
 * Some mbeans have references to some pretty big classes and we have no
 * good way to de-register these beans because these objects don't have good
 * life-cyle management.
 * <p>
 * This method will register your mbean with JMX but JMX will hold onto it
 * weakly so the large object may be GC'ed as usual.
 * <p>
 * When there is no more reference to the underlying MBean from anywhere
 * else it may be freed. If this happens, the next call to this objectName
 * will fail with an {@link IllegalStateException}. When this happens, this
 * objectName will also be unregisterd with
 * {@link #unregisterMBeanCatchAndLogExceptions(String)}
 * <p>
 * Because of the weird JMX naming conventions, this method uses
 * {@link StandardMBean} to proxy the bean as a {@link DynamicMBean} to get
 * it through the framework
 *
 * @return the DynamicMBean whose lifecycle controls how long this bean is
 *         registered. null will be returned if this bean is not regsitered
 *         correctly
 */
public static <T> DynamicMBean registerMBeanWeakRefPlusCatchAndLogExceptions(final T mbean, final Class<T> clazz, final String objectName) {
    final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
    try {
        final DynamicMBean bean = new StandardMBean(mbean, clazz);
        final DynamicMBean weakMBean = new WeakMBeanHandler(objectName, bean);
        final ObjectName on = new ObjectName(objectName);
        server.registerMBean(weakMBean, on);
        return bean;
    } catch (final Exception e) {
        AssertUtils.assertAndLogWithException(log, false, "Failed to register mbean for name " + objectName, e);
        return null;
    }
}
Also used : DynamicMBean(javax.management.DynamicMBean) StandardMBean(javax.management.StandardMBean) AttributeNotFoundException(javax.management.AttributeNotFoundException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ReflectionException(javax.management.ReflectionException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) MBeanException(javax.management.MBeanException) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 62 with StandardMBean

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

the class SchedulerJMXHelper method registerMBeans.

/**
 * {@inheritDoc}
 */
@Override
public void registerMBeans(final MBeanServer mbs) {
    // Register the Scheduler runtime MBean into the MBean server
    try {
        this.schedulerRuntimeMBean = new RuntimeDataMBeanImpl(dbManager);
        final ObjectName name = new ObjectName(RUNTIMEDATA_MBEAN_NAME);
        mbs.registerMBean(this.schedulerRuntimeMBean, name);
        String dataBaseName = PASchedulerProperties.SCHEDULER_HOME.getValueAsString() + System.getProperty("file.separator") + PASchedulerProperties.SCHEDULER_RRD_DATABASE_NAME.getValueAsString();
        FileUtils.forceMkdir(new File(dataBaseName).getParentFile());
        if (PASchedulerProperties.SCHEDULER_DB_HIBERNATE_DROPDB.getValueAsBoolean()) {
            // dropping the RDD data base
            File rrdDataBase = new File(dataBaseName);
            if (rrdDataBase.exists()) {
                rrdDataBase.delete();
            }
        }
        setDataStore(new RRDDataStore((StandardMBean) schedulerRuntimeMBean, dataBaseName, PASchedulerProperties.SCHEDULER_RRD_STEP.getValueAsInt(), Logger.getLogger(SchedulerJMXHelper.class)));
    } catch (Exception e) {
        LOGGER.error("Unable to register the RuntimeDataMBean", e);
    }
    // Register the MyAccount MBean into the MBean server
    try {
        final MyAccountMBeanImpl myAccountMBean = new MyAccountMBeanImpl(this.accountsManager);
        final ObjectName name = new ObjectName(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(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(MANAGEMENT_MBEAN_NAME);
        mbs.registerMBean(managementMBean, name);
    } catch (Exception e) {
        LOGGER.error("Unable to register the ManagementMBean", e);
    }
}
Also used : AllAccountsMBeanImpl(org.ow2.proactive.scheduler.core.jmx.mbean.AllAccountsMBeanImpl) MyAccountMBeanImpl(org.ow2.proactive.scheduler.core.jmx.mbean.MyAccountMBeanImpl) RuntimeDataMBeanImpl(org.ow2.proactive.scheduler.core.jmx.mbean.RuntimeDataMBeanImpl) StandardMBean(javax.management.StandardMBean) ManagementMBeanImpl(org.ow2.proactive.scheduler.core.jmx.mbean.ManagementMBeanImpl) RRDDataStore(org.ow2.proactive.jmx.RRDDataStore) File(java.io.File) ObjectName(javax.management.ObjectName)

Example 63 with StandardMBean

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

the class JmxUtilsTests method isMBeanWithStandardMBeanInherited.

@Test
void isMBeanWithStandardMBeanInherited() throws NotCompliantMBeanException {
    StandardMBean mbean = new StandardMBeanImpl();
    assertThat(JmxUtils.isMBean(mbean.getClass())).as("Standard MBean not detected correctly").isTrue();
}
Also used : StandardMBean(javax.management.StandardMBean) Test(org.junit.jupiter.api.Test)

Example 64 with StandardMBean

use of javax.management.StandardMBean in project aries by apache.

the class JMXAgentImpl method registerMBeans.

/**
 * @see org.apache.aries.jmx.agent.JMXAgent#registerMBeans(javax.management.MBeanServer)
 */
public synchronized void registerMBeans(final MBeanServer server) {
    for (MBeanHandler mbeanHandler : mbeansHandlers.keySet()) {
        if (mbeansHandlers.get(mbeanHandler) == Boolean.TRUE) {
            String name = mbeanHandler.getName();
            StandardMBean mbean = mbeanHandler.getMbean();
            if (mbean != null) {
                try {
                    logger.log(LogService.LOG_INFO, "Registering " + mbean.getMBeanInterface().getName() + " to MBeanServer " + server + " with name " + name);
                    server.registerMBean(mbean, new ObjectName(name));
                } catch (InstanceAlreadyExistsException e) {
                    logger.log(LogService.LOG_ERROR, "MBean is already registered", e);
                } catch (MBeanRegistrationException e) {
                    logger.log(LogService.LOG_ERROR, "Can't register MBean", e);
                } catch (NotCompliantMBeanException e) {
                    logger.log(LogService.LOG_ERROR, "MBean is not compliant MBean", e);
                } catch (MalformedObjectNameException e) {
                    logger.log(LogService.LOG_ERROR, "Try to register with no valid objectname", e);
                } catch (NullPointerException e) {
                    logger.log(LogService.LOG_ERROR, "Name of objectname can't be null", e);
                }
            }
        }
    }
    mbeanServers.put(server, Boolean.TRUE);
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) StandardMBean(javax.management.StandardMBean) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) ConfigurationAdminMBeanHandler(org.apache.aries.jmx.cm.ConfigurationAdminMBeanHandler) ProvisioningServiceMBeanHandler(org.apache.aries.jmx.provisioning.ProvisioningServiceMBeanHandler) MBeanHandler(org.apache.aries.jmx.MBeanHandler) PackageStateMBeanHandler(org.apache.aries.jmx.framework.PackageStateMBeanHandler) PermissionAdminMBeanHandler(org.apache.aries.jmx.permissionadmin.PermissionAdminMBeanHandler) BundleStateMBeanHandler(org.apache.aries.jmx.framework.BundleStateMBeanHandler) UserAdminMBeanHandler(org.apache.aries.jmx.useradmin.UserAdminMBeanHandler) FrameworkMBeanHandler(org.apache.aries.jmx.framework.FrameworkMBeanHandler) BundleWiringStateMBeanHandler(org.apache.aries.jmx.framework.wiring.BundleWiringStateMBeanHandler) ServiceStateMBeanHandler(org.apache.aries.jmx.framework.ServiceStateMBeanHandler) MBeanRegistrationException(javax.management.MBeanRegistrationException) ObjectName(javax.management.ObjectName)

Example 65 with StandardMBean

use of javax.management.StandardMBean in project aries by apache.

the class JMXAgentImpl method registerMBean.

/**
 * @see org.apache.aries.jmx.agent.JMXAgent#registerMBean(org.apache.aries.jmx.MBeanHandler)
 */
public synchronized void registerMBean(final MBeanHandler mBeanHandler) {
    for (MBeanServer server : mbeanServers.keySet()) {
        String name = mBeanHandler.getName();
        StandardMBean mbean = mBeanHandler.getMbean();
        try {
            logger.log(LogService.LOG_INFO, "Registering " + mbean.getMBeanInterface().getName() + " to MBeanServer " + server + " with name " + name);
            server.registerMBean(mbean, new ObjectName(name));
        } catch (InstanceAlreadyExistsException e) {
            logger.log(LogService.LOG_ERROR, "MBean is already registered", e);
        } catch (MBeanRegistrationException e) {
            logger.log(LogService.LOG_ERROR, "Can't register MBean", e);
        } catch (NotCompliantMBeanException e) {
            logger.log(LogService.LOG_ERROR, "MBean is not compliant MBean, Stopping registration", e);
            return;
        } catch (MalformedObjectNameException e) {
            logger.log(LogService.LOG_ERROR, "Try to register with no valid objectname, Stopping registration", e);
            return;
        } catch (NullPointerException e) {
            logger.log(LogService.LOG_ERROR, "Name of objectname can't be null, Stopping registration", e);
            return;
        }
    }
    mbeansHandlers.put(mBeanHandler, Boolean.TRUE);
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) StandardMBean(javax.management.StandardMBean) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) MBeanRegistrationException(javax.management.MBeanRegistrationException) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

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