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:org.dspace.kernel.DSpaceKernelManager.java

/**
 * Unregister an MBean if possible/*from   w w w. j  a  v  a 2  s  . com*/
 * @param mBeanName the bean name to use
 * @return true if the MBean was unregistered, false otherwise
 */
public static boolean unregisterMBean(String mBeanName) {
    String checkedMBeanName = DSpaceKernelManager.checkName(mBeanName);
    synchronized (mBeanName) {
        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        try {
            mbs.unregisterMBean(new ObjectName(checkedMBeanName));
            return true;
        } catch (InstanceNotFoundException ie) {
            //If this exception is thrown, the specified MBean is not currently registered
            //So, we'll ignore the error and return true
            return true;
        } catch (Exception e) {
            //log this issue as a System Warning. Also log the underlying error message.
            log.warn("Failed to unregister the MBean: " + checkedMBeanName, e);
            return false;
        }
    }
}

From source file:org.nuxeo.ecm.core.management.jtajca.internal.DefaultMonitorComponent.java

protected static void unbind(ObjectInstance instance) {
    MBeanServer mbs = Framework.getLocalService(ServerLocator.class).lookupServer();
    try {//from ww  w .jav  a 2s .  co m
        mbs.unregisterMBean(instance.getObjectName());
    } catch (MBeanRegistrationException | InstanceNotFoundException e) {
        throw new UnsupportedOperationException("Cannot unbind " + instance, e);
    }
}

From source file:hivemall.mix.metrics.MetricsRegistry.java

public static void unregisterMBeans(int port) {
    final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
    final ObjectName name = makeMBeanName("hivemall", MixServerMetricsMBean.class.getSimpleName(),
            "port=" + port);
    try {//from  www  . j av  a  2 s  .c o m
        server.unregisterMBean(name);
        logger.info("Unregistered MBean: " + name);
    } catch (Exception e) {
        logger.warn("Failed unregistering mbean: " + name);
    }
}

From source file:org.ofbiz.core.entity.transaction.DBCPConnectionFactory.java

private static void unregisterDatasourceFromJmx(BasicDataSource dataSource) {
    final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    try {/*from ww  w.  jav  a 2s. co  m*/
        mbs.unregisterMBean(ObjectName.getInstance(dataSource.getJmxName()));
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:org.apache.streams.util.ComponentUtils.java

/**
 * Removes all mbeans registered undered a specific domain.  Made specificly to clean up at unit tests
 * @param domain//from w  w w .j ava  2s. c  om
 */
public static void removeAllMBeansOfDomain(String domain) throws Exception {
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    domain = domain.endsWith(":") ? domain : domain + ":";
    ObjectName objectName = new ObjectName(domain + "*");
    Set<ObjectName> mbeanNames = mbs.queryNames(objectName, null);
    for (ObjectName name : mbeanNames) {
        mbs.unregisterMBean(name);
    }
}

From source file:gridool.metrics.GridNodeMetricsProvider.java

private static void unregisterMBeans() {
    final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
    final ObjectName name = GridUtils.makeMBeanName("gridool", "GridService", "GridLocalNodeMetrics");
    try {//from  www.  j a  v a2s .c  o  m
        server.unregisterMBean(name);
    } catch (InstanceNotFoundException inf) {
        LOG.warn("Failed unregistering mbean: " + name);
    } catch (MBeanRegistrationException re) {
        LOG.warn("Failed unregistering mbean: " + name);
    }
}

From source file:org.ofbiz.core.entity.transaction.DBCPConnectionFactory.java

private static void unregisterMBeanIfPresent() {
    // We want to make sure mBean will be unregistered
    final Properties dbcpProperties = loadDbcpProperties();
    if (dbcpProperties.containsKey(PROP_JMX) && Boolean.valueOf(dbcpProperties.getProperty(PROP_JMX))) {
        final String mBeanName = dbcpProperties.getProperty(PROP_MBEANNAME);
        try {//w w  w.ja v a2s .co m
            final ObjectName objectName = ObjectName.getInstance(dbcpProperties.getProperty(PROP_MBEANNAME));
            final MBeanServer platformMBeanServer = ManagementFactory.getPlatformMBeanServer();
            if (platformMBeanServer.isRegistered(objectName)) {
                platformMBeanServer.unregisterMBean(objectName);
            }
        } catch (Exception e) {
            log.error("Exception un-registering MBean data source " + mBeanName, e);
        }
    }
}

From source file:com.quinsoft.zeidon.utils.JoeUtils.java

public static void RegisterJmxBean(Object bean, String beanName, String jmxAppName) {
    try {/*ww w  .  j  a v  a 2 s  . c  om*/
        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();

        if (!StringUtils.isBlank(jmxAppName))
            beanName += ",app=" + jmxAppName;

        ObjectName name = new ObjectName(beanName);

        // Make sure the bean doesn't already exist.  If it does, unregister it.
        try {
            mbs.getMBeanInfo(name); // Throws InstanceNotFoundException if not found.
            mbs.unregisterMBean(name); // Unregister a bean if it exists.
        } catch (InstanceNotFoundException e) {
            // If we get here then the mbean isn't currently registered.  This is valid
            // so we'll ignore it.
        }

        mbs.registerMBean(bean, name);
    } catch (Exception e) {
        throw ZeidonException.wrapException(e).appendMessage("Bean Name = %s, app=%s", beanName, jmxAppName)
                .appendMessage("Bean class = %s", bean.getClass().getName());

    }

}

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./*w w  w  .  j a  v  a2 s.c o m*/
 * 
 * @param mbeanInterface The MBean interface this instance implements
 * @throws ServerRuntimeException
 */
public static void unregisterMBean(Class<?> mbeanInterface) {
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    try {
        ObjectName name = generateMBeanObjectName(mbeanInterface);
        if (mbs.isRegistered(name)) {
            logger.info("Unregistering mbean: " + name.toString());
            mbs.unregisterMBean(name);
        } else {
            logger.warn("Ignoring attempt to unregister unknown mbean: " + name.toString());
        }
    } catch (Exception e) {
        throw new ServerRuntimeException("Unable to unregister mbean: interface=" + mbeanInterface, 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./* ww w. j a v a2 s.  c om*/
 * 
 * @param mbeanInterface The MBean interface this instance implements
 * @param mbeanName A custom name for this MBean
 * @throws ServerRuntimeException
 */
public static void unregisterMBean(Class<?> mbeanInterface, String mbeanName) {
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    try {
        ObjectName name = generateMBeanObjectName(mbeanInterface.getName(), mbeanName);
        if (mbs.isRegistered(name)) {
            logger.info("Unregistering mbean: " + name.toString());
            mbs.unregisterMBean(name);
        } else {
            logger.warn("Ignoring attempt to unregister unknown mbean: " + name.toString());
        }
    } catch (Exception e) {
        throw new ServerRuntimeException(
                "Unable to unregister mbean: interface=" + mbeanInterface + " name=" + mbeanName, e);

    }
}