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.
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.
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.