Java MBean getMBeanServerId(final MBeanServer aMBeanServer)

Here you can find the source of getMBeanServerId(final MBeanServer aMBeanServer)

Description

Get the MBeanServerId of Agent ID for the provided MBeanServer.

License

Apache License

Parameter

Parameter Description
aMBeanServer MBeanServer whose Server ID/Agent ID is desired.

Return

MBeanServerId/Agent ID of provided MBeanServer.

Declaration

public static String getMBeanServerId(final MBeanServer aMBeanServer) 

Method Source Code

//package com.java2s;
/*/*from www. ja  v  a  2  s  .c  o  m*/
 * #%L
 * ch-commons-util
 * %%
 * Copyright (C) 2012 Cloudhopper by Twitter
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */

import javax.management.*;

public class Main {
    /**
     * Get the MBeanServerId of Agent ID for the provided MBeanServer.
     *
     * @param aMBeanServer MBeanServer whose Server ID/Agent ID is desired.
     * @return MBeanServerId/Agent ID of provided MBeanServer.
     */
    public static String getMBeanServerId(final MBeanServer aMBeanServer) {
        String serverId = null;
        final String SERVER_DELEGATE = "JMImplementation:type=MBeanServerDelegate";
        final String MBEAN_SERVER_ID_KEY = "MBeanServerId";
        try {
            ObjectName delegateObjName = new ObjectName(SERVER_DELEGATE);
            serverId = (String) aMBeanServer.getAttribute(delegateObjName,
                    MBEAN_SERVER_ID_KEY);
        } catch (MalformedObjectNameException malformedObjectNameException) {
            //System.err.println("Problems constructing MBean ObjectName: " + malformedObjectNameException.getMessage());
        } catch (AttributeNotFoundException noMatchingAttrException) {
            //System.err.println("Unable to find attribute " + MBEAN_SERVER_ID_KEY + " in MBean " + SERVER_DELEGATE + ": " + noMatchingAttrException);
        } catch (MBeanException mBeanException) {
            //System.err.println("Exception thrown by MBean's (" + SERVER_DELEGATE + "'s " + MBEAN_SERVER_ID_KEY + ") getter: " + mBeanException.getMessage());
        } catch (ReflectionException reflectionException) {
            //System.err.println("Exception thrown by MBean's (" + SERVER_DELEGATE + "'s " + MBEAN_SERVER_ID_KEY + ") setter: " + reflectionException.getMessage());
        } catch (InstanceNotFoundException noMBeanInstance) {
            //System.err.println("No instance of MBean " + SERVER_DELEGATE + " found in MBeanServer: " + noMBeanInstance.getMessage());
        }
        return serverId;
    }
}

Related

  1. getMBeanServer()
  2. getMBeanServerConnection(final JMXConnector connector)
  3. getMbeanServerConnection(final JMXConnector jmxConnector)
  4. getMBeanServerConnectionForJMXClient()
  5. getMBeanServerDelegateName()
  6. getMBeanServerObjectName()
  7. getOperation(MBeanInfo info, String opName)
  8. getProxy(MBeanServerConnection connection, ObjectName objectName, final Class objectClass)
  9. getServerId(MBeanServer server)