Java MBean getMBeanServerConnection(final JMXConnector connector)

Here you can find the source of getMBeanServerConnection(final JMXConnector connector)

Description

get M Bean Server Connection

License

Apache License

Declaration

public static MBeanServerConnection getMBeanServerConnection(final JMXConnector connector) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.Map;

import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;

import javax.management.remote.JMXServiceURL;

public class Main {
    public static MBeanServerConnection getMBeanServerConnection(final JMXConnector connector) {
        try {//from  w ww.j a va 2s.c o  m
            return connector.getMBeanServerConnection();
        } catch (Exception ex) {
            throw new RuntimeException("Failed to get MBeanServerConnection from [" + connector + "]", ex);
        }
    }

    public static MBeanServerConnection getMBeanServerConnection(final CharSequence jmxUrl) {
        try {
            return getJMXConnection(jmxUrl).getMBeanServerConnection();
        } catch (Exception ex) {
            throw new RuntimeException("Failed to get MBeanServerConnection from [" + jmxUrl + "]", ex);
        }
    }

    /**
     * Acquires a connected JMX connection
     * @param jmxUrl The JMXServiceURL of the service to connec to
     * @return a JMXConnector
     */
    public static JMXConnector getJMXConnection(CharSequence jmxUrl) {
        return getJMXConnection(jmxUrl, true, null);
    }

    /**
     * Acquires a JMX connection
     * @param jmxUrl The JMXServiceURL of the service to connec to
     * @param connect If true, the returned connector will be connected
     * @param environment a set of attributes to determine how the connection is made. Can be null.
     * @return a JMXConnector
     */
    public static JMXConnector getJMXConnection(CharSequence jmxUrl, boolean connect, Map<String, ?> environment) {
        if (jmxUrl == null)
            throw new IllegalArgumentException("The passed JMXServiceURL was null", new Throwable());
        try {

            JMXConnector connector = JMXConnectorFactory
                    .newJMXConnector(new JMXServiceURL(jmxUrl.toString().trim()), environment);
            if (connect) {
                connector.connect();
            }
            return connector;
        } catch (Exception e) {
            e.printStackTrace(System.err);
            throw new RuntimeException("Failed to acquire JMXConnection to [" + jmxUrl + "]", e);
        }
    }
}

Related

  1. getMbeanServer()
  2. getMBeanServer()
  3. getMBeanServer()
  4. getMBeanServer()
  5. getMBeanServer()
  6. getMbeanServerConnection(final JMXConnector jmxConnector)
  7. getMBeanServerConnectionForJMXClient()
  8. getMBeanServerDelegateName()
  9. getMBeanServerId(final MBeanServer aMBeanServer)