Sun GlassFish Message Queue 4.4 Developer's Guide for JMX Clients

Obtaining a JMX Connector from an Admin Connection Factory

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–1 Obtaining a JMX Connector from an Admin Connection Factory

import javax.management.remote.*;
import com.sun.messaging.AdminConnectionFactory;


//  Create admin 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 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.


Example 2–2 Configuring an Admin Connection Factory

import javax.management.remote.*;
import com.sun.messaging.AdminConnectionFactory;


//  Create admin 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();