Sun Java System Message Queue 4.2 Developer's Guide for JMX Clients

Obtaining a JMX Connector Without Using an Admin Connection Factory

The generic (non–Message Queue) way of obtaining a JMX connector, as described in the JMX Specification, is by invoking the static connect method of the standard JMX class JMXConnectorFactory (see Example 2–3). Client applications may choose to use this method instead of an admin connection factory in order to avoid dependency on Message Queue–specific classes.


Example 2–3 Obtaining a JMX Connector Without Using an Admin Connection Factory

import java.util.HashMap;
import javax.management.remote.*;


//  Provide credentials required by server for user authentication
    HashMap   environment = new HashMap();
    String[]  credentials = new String[] {"AliBaba", "sesame"};
    environment.put (JMXConnector.CREDENTIALS, credentials);
//  Get JMXServiceURL of JMX Connector (must be known in advance)
    JMXServiceURL  url 
        = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:9999/server");
//  Get JMX connector
    JMXConnector  jmxc = JMXConnectorFactory.connect(url, environment);
//  Get MBean server connection
    MBeanServerConnection  mbsc = jmxc.getMBeanServerConnection();


The JMXConnectorFactory.connect method accepts two parameters: