Managing broker domains using the Configuration Manager Proxy

Before you start

Before starting this topic, you must have completed Connecting to a Configuration Manager using the Configuration Manager Proxy.

Using the CMP it is possible to change the state of objects in the domain– that is, create, delete, modify, and deploy objects stored within the Configuration Manager. The following example attempts to set the long description field of a broker called B1:
import com.ibm.broker.config.proxy.*;

public class SetLongDescription {

  public static void main(String[] args) {
        
    ConfigManagerProxy cmp = null;
    try {
      ConfigManagerConnectionParameters cmcp =
         new MQConfigManagerConnectionParameters(
           "localhost",
           1414,
           "");
      cmp = ConfigManagerProxy.getInstance(cmcp);   
    } catch (ConfigManagerProxyException cmpex) {
      System.out.println("Error connecting: "+cmpex);
    }
        
    if (cmp != null) {
      System.out.println("Connected to Config Manager!");
      describeBroker(cmp, "B1", "this is my broker");
      cmp.disconnect();
    }
  }

  private static void describeBroker(ConfigManagerProxy cmp,
                                     String brokerName,
                                     String newDesc)
  {
  	BrokerProxy b = null;
    try {
      TopologyProxy topology = cmp.getTopology();
      if (topology != null) {
        b = topology.getBrokerByName(brokerName);
      }
    } catch(ConfigManagerProxyPropertyNotInitializedException
                                                      ex) {
        System.err.println("Comms problem! "+ex);
    }
    
    if (b != null) {
      try {
      	 b.setLongDescription(newDesc);
      } catch (ConfigManagerProxyException ex) {
      	System.err.println("Could not send request to CM: "+ex);
      }
    } else {
      System.err.println("Broker "+brokerName+" not found");
    }  
  }
}
The setLongDescription() method works by asking the Configuration Manager to modify a (key, value) property of the broker B1, where the key name represents the long description tag, and the value is the new long description. So an alternative to calling setLongDescription() is:
Properties p = new Properties();

p.setProperty(AttributeConstants.LONG_DESCRIPTION_PROPERTY,
              newDesc);

b.setProperties(p);
When the request to change properties is sent to the Configuration Manager, The CMP’s internal properties tables are not updated until the Configuration Manager reports that its copy of the attributes has been changed successfully. This is done in order to keep all copies of the information consistent. This process is shown below.


Note, that if the current user does not have the necessary permissions, as SetLongDescription.java works it is not possible to determine if the request gets rejected by the Configuration Manager. The CMP method to set the long description field throws a ConfigManagerProxyException if, and only if, the message to perform the operation can not be sent to the Configuration Manager. This means that output from the program is exactly the same, even if the Configuration Manager can not change the required property.

The reason for this is that the Configuration Manager processes requests from the CMP asynchronously, and so it could theoretically be a considerable time until the action is performed at the Configuration Manager. If methods such as the one described within this topic did not return control to the program until the completion codes became available, the performance of the CMP application would be wholly dependent on the performance of the Configuration Manager.

Next:

The design of most state-changing CMP methods is to return immediately without informing the calling application of the outcome of the request. To discover this information refer to Checking the results of broker domain management using the Configuration Manager Proxy

Related tasks
Configuring an environment for developing and running Configuration Manager Proxy applications
Connecting to a Configuration Manager using the Configuration Manager Proxy