The Message Queue convenience class AdminConnectionFactory (defined in package com.sun.messaging) encapsulates a predefined set of configuration properties and hides the details involved in creating a JMX connector. Example 2–1 shows the most straightforward use, creating a connector at the default port 7676 on host localhost, with the user name and password both set to the default value of admin. After creating the connector, its getMBeanServerConnection method is called to obtain a server connection for interacting with Message Queue MBeans.
import javax.management.remote.*; import com.sun.messaging.AdminConnectionFactory; // Create administration connection factory for default host and port (localhost:7676) AdminConnectionFactory acf = new AdminConnectionFactory(); // Get JMX connector using default user name (admin) and password (admin) JMXConnector jmxc = acf.createConnection(); // Get MBean server connection MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
Example 2–2 shows how to reconfigure an administration 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.
import javax.management.remote.*; import com.sun.messaging.AdminConnectionFactory; // Create administration connection factory AdminConnectionFactory acf = new AdminConnectionFactory(); // Configure for specific broker address acf.setProperty(AdminConnectionConfiguration.imqAddress, "otherhost:9898"); // Get JMX connector, supplying user name and password JMXConnector jmxc = acf.createConnection("AliBaba", "sesame"); // Get MBean server connection MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();