Example usage for javax.management StandardMBean StandardMBean

List of usage examples for javax.management StandardMBean StandardMBean

Introduction

In this page you can find the example usage for javax.management StandardMBean StandardMBean.

Prototype

protected StandardMBean(Class<?> mbeanInterface, boolean isMXBean) 

Source Link

Document

Make a DynamicMBean out of this, using the specified mbeanInterface class, and choosing whether the resulting MBean is an MXBean.

Usage

From source file:org.apache.hadoop.yarn.server.security.CertificateLocalizationService.java

@Override
protected void serviceStart() throws Exception {
    localizationEventsHandler = createLocalizationEventsHandler();
    localizationEventsHandler.setDaemon(true);
    localizationEventsHandler.setName("CertificateLocalizationEvents handler");
    localizationEventsHandler.start();/*ww w. j  a  va 2  s . co  m*/

    StandardMBean mbean = new StandardMBean(this, CertificateLocalizationMBean.class);
    mbeanObjectName = MBeans.register(service.toString(), "CertificateLocalizer", mbean);

    super.serviceStart();
}

From source file:org.ops4j.gaderian.management.impl.MBeanRegistryImpl.java

/**
 * @throws InstanceAlreadyExistsException
 * @throws MBeanRegistrationException//from w  ww  .j  a  va2s . c o m
 * @throws NotCompliantMBeanException
 * @see MBeanRegistry#registerMBean(Object, Class, ObjectName)
 */
public ObjectInstance registerMBean(Object obj, Class managementInterface, ObjectName objectName)
        throws InstanceAlreadyExistsException, MBeanRegistrationException, NotCompliantMBeanException {
    ObjectInstance instance = null;
    try {
        if (_log.isDebugEnabled()) {
            _log.debug("Trying to register MBean " + objectName);
        }
        instance = _beanServer.registerMBean(obj, objectName);
    } catch (NotCompliantMBeanException e) {
        if (_log.isDebugEnabled()) {
            _log.debug("MBean " + objectName + " is not compliant. Registering" + " using StandardMBean");
        }
        if (DynamicMBean.class.isAssignableFrom(obj.getClass()) || managementInterface == null)
            throw e;
        // if the object is a Standard MBean that is surrounded by
        // a proxy or an interceptor it is not compliant since
        // the naming conventions are not fulfilled.
        // Now we use the StandardMBean class to adapt the MBean to the
        // DynamicMBean interface which is not restricted by these
        // naming conventions
        StandardMBean standardMBean = new StandardMBean(obj, managementInterface);
        instance = _beanServer.registerMBean(standardMBean, objectName);
    }
    _objectInstances.add(instance);
    return instance;
}

From source file:com.oracle.osgi.jmx.Activator.java

/**
 *///from  w ww.ja v a 2s.  c  o  m
protected synchronized void registerServices() {
    PackageAdmin admin = (PackageAdmin) bundleContext
            .getService(bundleContext.getServiceReference(PackageAdmin.class.getCanonicalName()));
    StartLevel sl = (StartLevel) bundleContext
            .getService(bundleContext.getServiceReference(StartLevel.class.getCanonicalName()));
    try {
        framework = new StandardMBean(new Framework(bundleContext, admin, sl), FrameworkMBean.class);
    } catch (NotCompliantMBeanException e) {
        log.fatal("Unable to create StandardMBean for Framework", e);
        return;
    }
    try {
        bundleState = new StandardMBean(new BundleState(bundleContext, sl, admin), BundleStateMBean.class);
    } catch (NotCompliantMBeanException e) {
        log.fatal("Unable to create StandardMBean for BundleState", e);
        return;
    }
    try {
        serviceState = new StandardMBean(new ServiceState(bundleContext), ServiceStateMBean.class);
    } catch (NotCompliantMBeanException e) {
        log.fatal("Unable to create StandardMBean for ServiceState", e);
        return;
    }
    try {
        packageState = new StandardMBean(new PackageState(bundleContext, admin), PackageStateMBean.class);
    } catch (NotCompliantMBeanException e) {
        log.fatal("Unable to create StandardMBean for PackageState", e);
        return;
    }

    log.debug("Registering Framework with MBeanServer: " + mbeanServer + " with name: " + frameworkName);
    try {
        mbeanServer.registerMBean(framework, frameworkName);
    } catch (InstanceAlreadyExistsException e) {
        log.error("Cannot register OSGi framework MBean", e);
    } catch (MBeanRegistrationException e) {
        log.error("Cannot register OSGi framework MBean", e);
    } catch (NotCompliantMBeanException e) {
        log.error("Cannot register OSGi framework MBean", e);
    }

    log.debug("Registering bundle state monitor with MBeanServer: " + mbeanServer + " with name: "
            + bundlesStateName);
    try {
        mbeanServer.registerMBean(bundleState, bundlesStateName);
    } catch (InstanceAlreadyExistsException e) {
        log.error("Cannot register OSGi BundleStateMBean", e);
    } catch (MBeanRegistrationException e) {
        log.error("Cannot register OSGi BundleStateMBean", e);
    } catch (NotCompliantMBeanException e) {
        log.error("Cannot register OSGi BundleStateMBean", e);
    }

    log.debug("Registering services monitor with MBeanServer: " + mbeanServer + " with name: "
            + serviceStateName);
    try {
        mbeanServer.registerMBean(serviceState, serviceStateName);
    } catch (InstanceAlreadyExistsException e) {
        log.error("Cannot register OSGi ServiceStateMBean", e);
    } catch (MBeanRegistrationException e) {
        log.error("Cannot register OSGi ServiceStateMBean", e);
    } catch (NotCompliantMBeanException e) {
        log.error("Cannot register OSGi ServiceStateMBean", e);
    }

    log.debug("Registering packages monitor with MBeanServer: " + mbeanServer + " with name: "
            + packageStateName);
    try {
        mbeanServer.registerMBean(packageState, packageStateName);
    } catch (InstanceAlreadyExistsException e) {
        log.error("Cannot register OSGi PackageStateMBean", e);
    } catch (MBeanRegistrationException e) {
        log.error("Cannot register OSGi PackageStateMBean", e);
    } catch (NotCompliantMBeanException e) {
        log.error("Cannot register OSGi PackageStateMBean", e);
    }

    configAdminTracker = new ServiceTracker(bundleContext, "org.osgi.service.cm.ConfigurationAdmin",
            new ConfigAdminTracker());
    permissionAdminTracker = new ServiceTracker(bundleContext,
            "org.osgi.service.permissionadmin.PermissionAdmin", new PermissionAdminTracker());
    provisioningServiceTracker = new ServiceTracker(bundleContext,
            "org.osgi.service.provisioning.ProvisioningService", new ProvisioningServiceTracker());
    userAdminTracker = new ServiceTracker(bundleContext, "org.osgi.service.useradmin.UserAdmin",
            new UserAdminTracker());
    configAdminTracker.open();
    permissionAdminTracker.open();
    provisioningServiceTracker.open();
    userAdminTracker.open();
    servicesRegistered.set(true);
}

From source file:dk.netarkivet.common.management.SingleMBeanObject.java

/**
 * Registers this object as a standard MBean, with a name generated from
 * domain given in constructor and the nameProperties hashTable.
 *
 * @throws IllegalState if bean is already registered.
 * @throws IOFailure    on trouble registering.
 *///  w  ww .j a v a  2 s  .  c o m
public void register() {
    try {
        name = new ObjectName(domain, nameProperties);
        mBeanServer.registerMBean(new StandardMBean(exposedObject, asInterface), name);
        log.trace("Registered mbean '" + name + "'");
    } catch (InstanceAlreadyExistsException e) {
        String msg = "this MBean '" + name + "' is already registered on " + "the MBeanServer";
        log.warn(msg, e);
        throw new IllegalState(msg, e);
    } catch (JMException e) {
        throw new IOFailure("Unable to register MBean '" + name + "'", e);
    }
}

From source file:ddf.catalog.cache.solr.impl.SolrCache.java

private void configureMBean() {
    LOGGER.info("Registering Cache Manager Service MBean");
    mbeanServer = ManagementFactory.getPlatformMBeanServer();

    try {//from www. j  a  v  a  2  s .  c  o m
        try {

            mbeanServer.registerMBean(new StandardMBean(this, SolrCacheMBean.class), objectName);
        } catch (InstanceAlreadyExistsException e) {
            LOGGER.info("Re-registering Cache Manager MBean");
            mbeanServer.unregisterMBean(objectName);
            mbeanServer.registerMBean(new StandardMBean(this, SolrCacheMBean.class), objectName);
        }
    } catch (Exception e) {
        LOGGER.warn("Could not register MBean.", e);
    }
}

From source file:org.apache.servicemix.nmr.management.ManagementAgent.java

private Object getTypeSpecificManagedObject(Object object) throws NotCompliantMBeanException {
    return object instanceof ManagedEndpoint ? object
            : object instanceof Nameable ? new StandardMBean(object, ((Nameable) object).getPrimaryInterface())
                    : null;//w  w w  . j av a 2  s .c om
}

From source file:org.codice.ddf.ui.admin.api.impl.SystemPropertiesAdmin.java

private void configureMBean() {
    mbeanServer = ManagementFactory.getPlatformMBeanServer();

    try {//  w w  w . j  av a  2  s .c om
        objectName = new ObjectName(SystemPropertiesAdminMBean.OBJECT_NAME);
    } catch (MalformedObjectNameException e) {
        LOGGER.debug("Exception while creating object name: " + SystemPropertiesAdminMBean.OBJECT_NAME, e);
    }

    try {
        try {
            mbeanServer.registerMBean(new StandardMBean(this, SystemPropertiesAdminMBean.class), objectName);
        } catch (InstanceAlreadyExistsException e) {
            mbeanServer.unregisterMBean(objectName);
            mbeanServer.registerMBean(new StandardMBean(this, SystemPropertiesAdminMBean.class), objectName);
        }
    } catch (Exception e) {
        LOGGER.info("Could not register mbean.", e);
    }
}

From source file:org.apache.hadoop.hdfs.server.namenode.AvatarNode.java

public void registerMBean() {
    StandardMBean avatarNodeBean;
    try {//  w w w  . jav a 2s  .com
        avatarNodeBean = new StandardMBean(this, AvatarNodeStatusMBean.class);
        MBeanUtil.registerMBean("AvatarNode", "AvatarNodeState", avatarNodeBean);
    } catch (NotCompliantMBeanException mex) {
        LOG.error("Error registering mbean with JMX", mex);
    }
}

From source file:org.codice.ddf.admin.core.impl.SystemPropertiesAdmin.java

private void registerSystemPropertiesAdminMBean() throws MBeanRegistrationException, NotCompliantMBeanException,
        InstanceNotFoundException, InstanceAlreadyExistsException {
    try {//from  w  ww .  j  a  va2  s  .com
        mbeanServer.registerMBean(new StandardMBean(this, SystemPropertiesAdminMBean.class), objectName);
    } catch (InstanceAlreadyExistsException e) {
        mbeanServer.unregisterMBean(objectName);
        mbeanServer.registerMBean(new StandardMBean(this, SystemPropertiesAdminMBean.class), objectName);
    }
}

From source file:org.apache.hadoop.raid.RaidNode.java

public void registerMBean() {
    StandardMBean bean;//from ww  w .  j a  v a 2  s .  c  o m
    try {
        beanName = VersionInfo.registerJMX("RaidNode");
        bean = new StandardMBean(this, RaidNodeStatusMBean.class);
        raidnodeMXBeanName = MBeanUtil.registerMBean("RaidNode", "RaidNodeState", bean);
    } catch (NotCompliantMBeanException e) {
        e.printStackTrace();
    }
    LOG.info("Registered RaidNodeStatusMBean");
}