Example usage for javax.management MBeanServer unregisterMBean

List of usage examples for javax.management MBeanServer unregisterMBean

Introduction

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

Prototype

public void unregisterMBean(ObjectName name) throws InstanceNotFoundException, MBeanRegistrationException;

Source Link

Document

If this method successfully unregisters an MBean, a notification is sent as described above.

Usage

From source file:com.continuent.tungsten.common.jmx.JmxManager.java

/**
 * Server helper method to register a JMX MBean. MBeans are registered by a
 * combination of their MBean interface and the custom mbeanName argument.
 * The mbeanName permits multiple mBeans to be registered under the same
 * name.//from  w w w  .j a  v  a 2 s. c  o  m
 * 
 * @param mbean The MBean instance that should be registered
 * @param mbeanClass The base class for the mbean
 * @throws ServerRuntimeException
 */
public static void registerMBean(Object mbean, Class<?> mbeanClass) {
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    try {
        if (logger.isDebugEnabled())
            logger.debug("Registering mbean: " + mbean.getClass());

        ObjectName name = generateMBeanObjectName(mbeanClass);

        if (mbs.isRegistered(name))
            mbs.unregisterMBean(name);
        mbs.registerMBean(mbean, name);
    } catch (Exception e) {
        throw new ServerRuntimeException(
                String.format("Unable to register mbean for class %s because '%s'", mbeanClass.getName(), e),
                e);

    }
}

From source file:com.continuent.tungsten.common.jmx.JmxManager.java

/**
 * Server helper method to register a JMX MBean. MBeans are registered by a
 * combination of their MBean interface and the custom mbeanName argument.
 * The mbeanName permits multiple mBeans to be registered under the same
 * name.//from  w  w  w .  j  av  a 2 s.  c  o  m
 * 
 * @param mbean The MBean instance that should be registered
 * @param mbeanInterface The MBean interface this instance implements
 * @param mbeanName A custom name for this MBean
 * @throws ServerRuntimeException
 */
public static void registerMBean(Object mbean, Class<?> mbeanInterface, String mbeanName, boolean ignored) {
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    try {
        if (logger.isDebugEnabled())
            logger.debug("Registering mbean: " + mbean.getClass());

        ObjectName name = generateMBeanObjectName(mbeanInterface.getName(), mbeanName);

        if (mbs.isRegistered(name))
            mbs.unregisterMBean(name);
        mbs.registerMBean(mbean, name);
    } catch (Exception e) {
        throw new ServerRuntimeException("Unable to register mbean: class=" + mbean.getClass() + " interface="
                + mbeanInterface + " name=" + mbeanName, e);

    }
}

From source file:org.sonatype.nexus.apachehttpclient.PoolingClientConnectionManagerMBeanInstaller.java

/**
 * Unregisters the connection manager from JMX.
 *//*from  ww  w. j a v  a 2  s  . com*/
public synchronized void unregister() {
    if (jmxName != null) {
        try {
            final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
            server.unregisterMBean(jmxName);
        } catch (final Exception e) {
            LOGGER.warn("Failed to unregister mbean {} due to {}:{}", jmxName, e.getClass(), e.getMessage());
        } finally {
            jmxName = null;
        }
    }
}

From source file:org.sonatype.nexus.internal.httpclient.PoolingClientConnectionManagerMBeanInstaller.java

/**
 * Unregisters the connection manager from JMX.
 *//*from   ww w  . j  a  v a2s  .c o  m*/
synchronized void unregister() {
    if (jmxName != null) {
        try {
            final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
            server.unregisterMBean(jmxName);
        } catch (final Exception e) {
            LOGGER.warn("Failed to unregister mbean {} due to {}:{}", jmxName, e.getClass(), e.getMessage());
        } finally {
            jmxName = null;
        }
    }
}

From source file:org.eclipse.gyrex.monitoring.internal.MetricSetTracker.java

@Override
public void removedService(final ServiceReference<MetricSet> reference,
        final MetricSetJmxRegistration metricSetJmxRegistration) {
    try {/* w  ww. j a  v a 2s  .  c  om*/
        // unregister MBean
        final MBeanServer beanServer = ManagementFactory.getPlatformMBeanServer();
        beanServer.unregisterMBean(metricSetJmxRegistration.objectName);
    } catch (final Exception e) {
        LOG.warn("Failed to unregister metric JMX registration {}. {}", metricSetJmxRegistration.objectName,
                ExceptionUtils.getRootCauseMessage(e));
    } finally {
        // unget service
        context.ungetService(reference);
    }
}

From source file:org.xwiki.management.internal.DefaultJMXBeanRegistration.java

@Override
public void unregisterMBean(String name) {
    // Make sure we never fail since XWiki should execute correctly even if it fail to unregister some MBean
    try {/*from  w ww  .j  a va2  s . c o m*/
        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        ObjectName oname = new ObjectName(OBJECTNAME_PREFIX + name);
        mbs.unregisterMBean(oname);
        this.logger.debug("Unregistered resource with name [{}]", name);
    } catch (Exception e) {
        // Failed to unregister the MBean, log a warning
        this.logger.warn("Failed to unregister resource with name [{}]. Reason = [{}]", name,
                ExceptionUtils.getMessage(e));
    }
}

From source file:org.rhq.enterprise.server.remote.RemoteSafeInvocationHandler.java

/**
 * Unregisters the MBean that was used to monitor the remote API processing.
 *
 * @param mbs the MBeanServer where the metrics MBean is registered
 *///from w w  w .j av a 2  s  .c  o m
public void unregisterMetricsMBean(MBeanServer mbs) {
    try {
        mbs.unregisterMBean(RemoteSafeInvocationHandlerMetricsMBean.OBJECTNAME_METRICS);
    } catch (Exception e) {
        log.warn("Failed to unregister the metrics object: " + e);
    }
}

From source file:com.github.stephanarts.cas.ticket.registry.ZMQTicketRegistry.java

/**
 * {@inheritDoc}//from  ww w. ja  v a 2  s  . c o m
 *
 */
@Override
public void destroy() throws Exception {
    this.provider.cleanup();
    this.registryBroker.cleanup();
    this.pacemaker.destroy();
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    mbs.unregisterMBean(this.mbeanName);
    return;
}

From source file:org.openmrs.module.jmx.impl.JMXServiceImpl.java

/**
 * @see org.openmrs.module.jmx.JMXService#unregisterBean(String)
 *///from  w w w . ja  v  a  2s .  c  o m
@Override
public void unregisterMBean(String folder, String name) {
    try {
        ObjectName objName = getObjectName(folder, name);
        MBeanServer beanServer = ManagementFactory.getPlatformMBeanServer();
        if (beanServer.isRegistered(objName))
            beanServer.unregisterMBean(objName);

        log.debug("Unregistered MBean: " + objName.toString());

    } catch (MalformedObjectNameException e) {
        log.error("Invalid MBean name", e);
    } catch (Exception e) {
        log.error("Unable to unregister MBean", e);
    }
}

From source file:org.openmrs.module.jmx.impl.JMXServiceImpl.java

/**
 * @see org.openmrs.module.jmx.JMXService#registerBean(String, Object)
 *//*from   www  .  j  ava 2 s.c o  m*/
@Override
public void registerMBean(String folder, String name, Object mbean) {
    Object proxiedBean = MBeanProxifier.getProxy(mbean);

    try {
        ObjectName objName = getObjectName(folder, name);
        MBeanServer beanServer = ManagementFactory.getPlatformMBeanServer();
        if (beanServer.isRegistered(objName))
            beanServer.unregisterMBean(objName);

        beanServer.registerMBean(proxiedBean, objName);

        log.debug("Registered MBean: " + objName.toString());

    } catch (MalformedObjectNameException e) {
        log.error("Invalid MBean name", e);
    } catch (Exception e) {
        log.error("Unable to register MBean", e);
    }
}