Example usage for javax.management MBeanServerFactory releaseMBeanServer

List of usage examples for javax.management MBeanServerFactory releaseMBeanServer

Introduction

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

Prototype

public static void releaseMBeanServer(MBeanServer mbeanServer) 

Source Link

Document

Remove internal MBeanServerFactory references to a created MBeanServer.

Usage

From source file:Main.java

/**
 * Resets MBeanServerFactory and ManagementFactory to a known consistent state.
 * This involves releasing all currently registered MBeanServers and resetting
 * the platformMBeanServer to null.// ww  w  . ja v a 2  s . co  m
 */
public static void resetMBeanServers() throws Exception {
    for (MBeanServer server : MBeanServerFactory.findMBeanServer(null)) {
        MBeanServerFactory.releaseMBeanServer(server);
    }
    Field field = ManagementFactory.class.getDeclaredField("platformMBeanServer");
    field.setAccessible(true);
    field.set(null, null);
}

From source file:org.apache.geode.admin.jmx.internal.MBeanUtil.java

/**
 * Unregisters all GemFire MBeans and then releases the MBeanServer for garbage collection.
 *///from   w ww  .  j ava2s  .com
static void releaseMBeanServer() {
    try {
        // unregister all GemFire mbeans...
        Iterator iter = mbeanServer.queryNames(null, null).iterator();
        while (iter.hasNext()) {
            ObjectName name = (ObjectName) iter.next();
            if (name.getDomain().startsWith(DEFAULT_DOMAIN)) {
                unregisterMBean(name);
            }
        }

        // last, release the mbean server...
        MBeanServerFactory.releaseMBeanServer(mbeanServer);
        mbeanServer = null;
    } catch (JMRuntimeException e) {
        logStackTrace(Level.WARN, e);
    }
    /*
     * See #42391. Cleaning up the static maps which might be still holding references to
     * ManagedResources
     */
    synchronized (MBeanUtil.managedResources) {
        MBeanUtil.managedResources.clear();
    }
    synchronized (refreshClients) {
        refreshClients.clear();
    }
    /*
     * See #42391. Cleaning up the static maps which might be still holding references to
     * ManagedResources
     */
    synchronized (MBeanUtil.managedResources) {
        MBeanUtil.managedResources.clear();
    }
    synchronized (refreshClients) {
        refreshClients.clear();
    }
}

From source file:org.mule.management.agents.JmxAgent.java

public void dispose() {
    if (mBeanServer != null) {
        for (Iterator iterator = registeredMBeans.iterator(); iterator.hasNext();) {
            ObjectName objectName = (ObjectName) iterator.next();
            try {
                mBeanServer.unregisterMBean(objectName);
            } catch (Exception e) {
                logger.warn("Failed to unregister MBean: " + objectName + ". Error is: " + e.getMessage());
            }/*from  w w w . ja  v  a 2s .  c o m*/
        }
        if (serverCreated) {
            MBeanServerFactory.releaseMBeanServer(mBeanServer);
        }
        mBeanServer = null;
    }
}

From source file:org.mule.module.management.agent.AbstractJmxAgent.java

/**
 * {@inheritDoc}//from   w  w  w .  j av  a2  s  . co  m
 */
public void dispose() {
    unregisterMBeansIfNecessary();
    unregisterListeners();
    if (serverCreated.get()) {
        MBeanServerFactory.releaseMBeanServer(mBeanServer);
    }
    mBeanServer = null;
    serverCreated.compareAndSet(true, false);
    initialized.set(false);
}

From source file:org.springframework.jmx.support.MBeanServerFactoryBean.java

/**
 * Unregisters the {@code MBeanServer} instance, if necessary.
 *//*w ww . j  a  v  a  2 s  . c  o  m*/
@Override
public void destroy() {
    if (this.newlyRegistered) {
        MBeanServerFactory.releaseMBeanServer(this.server);
    }
}