Unregister the MBean represented by the object name. - Java javax.management

Java examples for javax.management:MBean

Description

Unregister the MBean represented by the object name.

Demo Code

/**/*from www .  ja  va  2 s  .c om*/
 * Copyright 2010-2013 lazydog.org.
 *
 * This file is part of repository.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
//package com.java2s;

import java.lang.management.ManagementFactory;

import javax.management.MBeanException;
import javax.management.MBeanServer;

import javax.management.ObjectName;

public class Main {
    /**
     * Unregister the MBean represented by the object name.
     *
     * @param  objectName  the MBean object name.
     *
     * @throws  MBeanException  if unable to unregister the MBean.
     */
    public static void unregister(ObjectName objectName)
            throws MBeanException {

        try {

            // Get the MBean server.
            MBeanServer mBeanServer = ManagementFactory
                    .getPlatformMBeanServer();

            // Check if the MBean is registered with the MBean server.
            if (mBeanServer.isRegistered(objectName)) {

                // Unregister the MBean with the MBean server.
                mBeanServer.unregisterMBean(objectName);
            }
        } catch (Exception e) {
            throw new MBeanException(e, "Unable to unregister the MBean "
                    + objectName.getCanonicalName() + ".");
        }
    }
}

Related Tutorials