Connecting to a Configuration Manager using the Configuration Manager Proxy

Connect a CMP application to a Configuration Manager to send requests about resources in the broker domain.

Before you start

Before starting this step, you must have completed Configuring an environment for developing and running Configuration Manager Proxy applications.

Consider the following program ConnectToConfigManager.java. It attempts to connect to a Configuration Manager that is running on the default queue manager of the local machine.
import com.ibm.broker.config.proxy.*;

public class ConfigManagerRunStateChecker {

    public static void main(String[] args) {
        displayConfigManagerRunState("localhost", 1414, "");
    }

    public static void displayConfigManagerRunState(String hostname,
                                                    int port,
                                                    String qmgr) {
        ConfigManagerProxy cmp = null;
        try {
            ConfigManagerConnectionParameters cmcp =
                new MQConfigManagerConnectionParameters(hostname, port, qmgr);
            cmp = ConfigManagerProxy.getInstance(cmcp);
            String configManagerName = cmp.getName();
            
            System.out.println("Configuration Manager '"+configManagerName+
                "' is available!");
            cmp.disconnect();
        } catch (ConfigManagerProxyException ex) {
            System.out.println("Configuration Manager is NOT available"+
                " because "+ex);
        }
    }
}

The first line of the program requests Java to import the CMP classes. All CMP classes are in the com.ibm.broker.config.proxy package.

The first line inside the try block of the displayConfigManagerRunState() method instantiates a ConfigManagerConnectionParameters object. This method is an interface which states that implementing classes are able to provide the parameters to connect to a Configuration Manager.

The only class that implements this interface is MQConfigManagerConnectionParameters, which defines a set of WebSphere® MQ connection parameters. The constructor used here takes three parameters:
  1. The host name of the Configuration Manager machine
  2. The port on which the WebSphere MQ listener service for the Configuration Manager is listening
  3. The name of the queue manager that is associated with the Configuration Manager

When you have defined this object, you can connect to the queue manager with those characteristics. The connection is achieved by the static getInstance() factory method just inside the try block. When a valid handle to the Configuration Manager is obtained, the application attempts to discover the name of the Configuration Manager (cmp.getName()) and display it.

getName(), and other methods that request information from the Configuration Manager, block until the information is supplied, or a timeout occurs. Therefore, if the Configuration Manager is not running, the application hangs for a period. You can control the timeout period by using the ConfigManagerProxy.setRetryCharacteristics() method. Typically, blocking only occurs when a given resource is accessed for the first time within an application.

Finally, the disconnect() method is called. This method frees up resources associated with the connection in both the CMP and Configuration Manager.

When a ConfigManagerProxy handle is first returned from the getInstance() method, the Configuration Manager service is not necessarily running. It is only when the application attempts to make use of the handle (by calling getName() in this example) that the application can be assured that a two-way connection with the Configuration Manager is active.

Related tasks
Configuring an environment for developing and running Configuration Manager Proxy applications
Related information
Configuration Manager Proxy API
Notices | Trademarks | Downloads | Library | Support | Feedback

Copyright IBM Corporation 1999, 2009Copyright IBM Corporation 1999, 2009. All Rights Reserved.
Last updated : 2009-01-07 15:40:20

ae33030_