As defined in the JMX Specification, client applications obtain MBeans through an MBean server connection, accessed by means of a JMX connector. Message Queue brokers use the standard JMX infrastructure provided with the Java Development Kit (JDK) 1.5, which uses remote method invocation (RMI) for communicating between client and server. Once you obtain a JMX connector, you can use it to obtain an MBean server connection with which to access the attributes, operations, and notifications of individual MBeans. This infrastructure is describe in JMX Connection Infrastructure in Sun Java System Message Queue 4.3 Administration Guide.
For convenience, Message Queue provides an admin connection factory (class AdminConnectionFactory), similar in spirit to the familiar Message Queue connection factory, for creating JMX connectors with a minimum of effort. It is also possible to dispense with this convenience class and obtain a JMX connector using standard JMX classes instead. The following sections illustrate these two techniques. While Message Queue client applications are free to use either method, the first is simpler and is recommended.
The Message Queue convenience class AdminConnectionFactory (defined in package com.sun.messaging) encapsulates a predefined set of configuration properties and hides details, such as the JMX Service URL, involved in obtaining a JMX connector. Example 2–1 shows the most straightforward use, obtaining a JMX connector at the default broker Port Mapper port 7676 on host localhost, with the user name and password both set to the default value of admin. After obtaining the connector, its getMBeanServerConnection method is called to obtain an MBean server connection for interacting with Message Queue MBeans.
Example 2–2 shows how to reconfigure an admin connection factory's properties to nondefault values. Instead of using the default broker address (localhost:7676), the code shown here uses the connection factory's setProperty method to reconfigure it to connect to a broker at port 9898 on host otherhost. (The names of the connection factory's configuration properties are defined as static constants in the Message Queue utility class AdminConnectionConfiguration, defined in package com.sun.messaging.) The arguments to the factory's createConnection method are then used to supply a user name and password other than the defaults.
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.
The JMXConnectorFactory.connect method accepts two parameters:
The JMX service URL is an address used for obtaining the JMX connector. It can either specify the location of a JMX connector stub in an RMI registry or contain a connector stub as a serialized object. These options, and the format of the address, are described in The JMX Service URL in Sun Java System Message Queue 4.3 Administration Guide
An optional environment parameter.
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.