Search in sources :

Example 26 with StandardMBean

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

the class BasicDataSource method jmxRegister.

private void jmxRegister() {
    // Return immediately if this DataSource has already been registered
    if (registeredJmxObjectName != null) {
        return;
    }
    // Return immediately if no JMX name has been specified
    final String requestedName = getJmxName();
    if (requestedName == null) {
        return;
    }
    registeredJmxObjectName = registerJmxObjectName(requestedName, null);
    try {
        final StandardMBean standardMBean = new StandardMBean(this, DataSourceMXBean.class);
        registeredJmxObjectName.registerMBean(standardMBean);
    } catch (final NotCompliantMBeanException e) {
        log.warn("The requested JMX name [" + requestedName + "] was not valid and will be ignored.");
    }
}
Also used : StandardMBean(javax.management.StandardMBean) NotCompliantMBeanException(javax.management.NotCompliantMBeanException)

Example 27 with StandardMBean

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

the class MBeanHolder method create.

static <T> MBeanHolder create(final T mbean, final ObjectName requestedObjectName) {
    if (mbean instanceof DynamicMBean) {
        return new MBeanHolder(mbean, requestedObjectName);
    } else if (mbean == null) {
        return null;
    }
    Class<?> mbeanClass = mbean.getClass();
    // This is all in aid of getting new StandardMBean to work.
    @SuppressWarnings("unchecked") Class<T> mbeanInterface = (Class<T>) getMBeanInterface(mbeanClass);
    if (mbeanInterface == null) {
        return null;
    }
    if (mbeanInterface.getName().equals(mbeanClass.getName().concat("MBean")) || mbeanInterface.getName().equals(mbeanClass.getName().concat("MXBean"))) {
        return new MBeanHolder(mbean, requestedObjectName);
    }
    try {
        StandardMBean stdMbean = new RegistrableStandardEmitterMBean(mbean, mbeanInterface);
        return new MBeanHolder(stdMbean, requestedObjectName);
    } catch (NotCompliantMBeanException e) {
        LoggerFactory.getLogger(MBeanHolder.class).error("create: Cannot create StandardMBean for " + mbean + " of type " + mbeanClass + " for interface " + mbeanInterface, e);
        return null;
    }
}
Also used : DynamicMBean(javax.management.DynamicMBean) StandardMBean(javax.management.StandardMBean) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) RegistrableStandardEmitterMBean(org.apache.aries.jmx.util.shared.RegistrableStandardEmitterMBean)

Example 28 with StandardMBean

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

the class ProvisioningServiceMBeanHandlerTest method testConstructInjectMBean.

@Test
public void testConstructInjectMBean() {
    BundleContext bundleContext = mock(BundleContext.class);
    Logger agentLogger = mock(Logger.class);
    JMXAgentContext agentContext = new JMXAgentContext(bundleContext, null, agentLogger);
    ProvisioningService provService = mock(ProvisioningService.class);
    ProvisioningServiceMBeanHandler handler = new ProvisioningServiceMBeanHandler(agentContext);
    StandardMBean mbean = handler.constructInjectMBean(provService);
    assertNotNull(mbean);
}
Also used : StandardMBean(javax.management.StandardMBean) ProvisioningService(org.osgi.service.provisioning.ProvisioningService) JMXAgentContext(org.apache.aries.jmx.agent.JMXAgentContext) Logger(org.apache.aries.jmx.Logger) BundleContext(org.osgi.framework.BundleContext) Test(org.junit.Test)

Example 29 with StandardMBean

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

the class UserAdminMBeanHandler method constructInjectMBean.

/**
 * @see org.apache.aries.jmx.AbstractCompendiumHandler#constructInjectMBean(java.lang.Object)
 */
@Override
protected StandardMBean constructInjectMBean(Object targetService) {
    UserAdminMBean uaMBean = new UserAdmin((org.osgi.service.useradmin.UserAdmin) targetService);
    StandardMBean mbean = null;
    try {
        mbean = new StandardMBean(uaMBean, UserAdminMBean.class);
    } catch (NotCompliantMBeanException e) {
        Logger logger = agentContext.getLogger();
        logger.log(LogService.LOG_ERROR, "Not compliant MBean", e);
    }
    return mbean;
}
Also used : StandardMBean(javax.management.StandardMBean) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) UserAdminMBean(org.osgi.jmx.service.useradmin.UserAdminMBean) Logger(org.apache.aries.jmx.Logger)

Example 30 with StandardMBean

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

the class ConfigurationAdminMBeanHandlerTest method testConstructInjectMBean.

@Test
public void testConstructInjectMBean() {
    BundleContext bundleContext = mock(BundleContext.class);
    Logger agentLogger = mock(Logger.class);
    JMXAgentContext agentContext = new JMXAgentContext(bundleContext, null, agentLogger);
    ConfigurationAdmin cAdmin = mock(ConfigurationAdmin.class);
    ConfigurationAdminMBeanHandler handler = new ConfigurationAdminMBeanHandler(agentContext);
    StandardMBean mbean = handler.constructInjectMBean(cAdmin);
    assertNotNull(mbean);
}
Also used : StandardMBean(javax.management.StandardMBean) JMXAgentContext(org.apache.aries.jmx.agent.JMXAgentContext) Logger(org.apache.aries.jmx.Logger) ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin) BundleContext(org.osgi.framework.BundleContext) Test(org.junit.Test)

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