Example usage for javax.management.remote JMXConnectorFactory newJMXConnector

List of usage examples for javax.management.remote JMXConnectorFactory newJMXConnector

Introduction

In this page you can find the example usage for javax.management.remote JMXConnectorFactory newJMXConnector.

Prototype

public static JMXConnector newJMXConnector(JMXServiceURL serviceURL, Map<String, ?> environment)
        throws IOException 

Source Link

Document

Creates a connector client for the connector server at the given address.

Usage

From source file:org.apache.hadoop.hbase.TestJMXListener.java

@Test
public void testStop() throws Exception {
    MiniHBaseCluster cluster = UTIL.getHBaseCluster();
    LOG.info("shutdown hbase cluster...");
    cluster.shutdown();//w  w w . jav  a  2s.c  o  m
    LOG.info("wait for the hbase cluster shutdown...");
    cluster.waitUntilShutDown();

    JMXConnector connector = JMXConnectorFactory
            .newJMXConnector(JMXListener.buildJMXServiceURL(connectorPort, connectorPort), null);
    expectedEx.expect(IOException.class);
    connector.connect();

}

From source file:org.opennms.jmxconfiggenerator.jmxconfig.JmxDatacollectionConfiggenerator.java

/**
 * This method gets the JmxConnector to connect with the given jmxServiceURL.
 *
 * @param username may be null/*from   w ww.  j a v a  2s . co  m*/
 * @param password may be null
 * @param jmxServiceURL should not be null!
 * @return a jmxConnector
 * @throws IOException if the connection to the given jmxServiceURL fails (e.g. authentication failure or not reachable)
 */
private JMXConnector getJmxConnector(String username, String password, JMXServiceURL jmxServiceURL)
        throws IOException {
    JMXConnector jmxConnector;
    if (username != null && password != null) {
        jmxConnector = JMXConnectorFactory.newJMXConnector(jmxServiceURL, null);
        HashMap<String, String[]> env = new HashMap<String, String[]>();
        String[] credentials = new String[] { username, password };
        env.put("jmx.remote.credentials", credentials);
        jmxConnector.connect(env);
    } else {
        jmxConnector = JMXConnectorFactory.connect(jmxServiceURL);
        jmxConnector.connect();
    }
    return jmxConnector;
}