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

Obtaining a JMX Connector Without Using an Administration 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 administration connection factory in order to avoid dependency on Message Queue–specific classes.

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

import java.util.HashMap;

//  Provide credentials required by server for user authentication
    HashMap   environment = new HashMap();
    String[]  credentials = new String[] {"AliBaba", "sesame"};
    environment.put (JMXConnector.CREDENTIALS, credentials);
//  Create 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:

The service URL is a string whose syntax is described in the next section; the environment parameter is a hash map mapping attribute names to their corresponding values. In particular, the CREDENTIALS attribute specifies the authentication credentials (user name and password) to be used in establishing a connection. The hash-map key for this attribute is defined as a static constant, CREDENTIALS, in the JMXConnector interface; the corresponding value is a 2–element string array containing the user name at index 0 and the password at index 1.