Before you start
Before starting this step, you must have completed Connecting to a Configuration Manager using the Configuration Manager Proxy.
Collectively known as administered objects these objects provide the bulk of the interface to the Configuration Manager, and as such are fundamental to understanding the Configuration Manager Proxy API.
Java class | Class function |
---|---|
TopologyProxy | Describes the pub/sub topology. |
CollectiveProxy | Describes pub/sub collectives. |
BrokerProxy | Describes brokers. |
ExecutionGroupProxy | Describes execution groups. |
MessageFlowProxy | Describes message flows that have already been deployed to execution groups; does NOT describe message flows in the Broker Application Development perspective of the toolkit. |
TopicProxy | Describes topics. |
TopicRootProxy | Describes the root of the topic hierarchy. |
LogProxy | Describes the broker’s event log for the current user. |
SubscriptionsProxy | Describes a subset of the active subscriptions. |
ConfigManagerProxy | Describes the Configuration Manager itself. |
Declared in each administered object is a set of public methods that programs can use to enquire and manipulate properties of the underlying Configuration Manager object to which the instance refers. For example, on a BrokerProxy object that refers to broker B1, it is possible to invoke methods that cause the broker to reveal its run-state, or cause it to start all its message flows and so on.
To access an administered object, and make use of its API, it is necessary to first request a handle to it from the object that logically owns it. For example, as brokers logically own execution groups, in order to gain a handle to execution group EG1 running on broker B1 the application needs to ask the BrokerProxy object represented by B1 for a handle to the ExecutionGroupProxy object represented by EG1.
import com.ibm.broker.config.proxy.*; public class GetMessageFlowRunState { 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!"); displayMessageFlowRunState(cmp, "B1", "EG1", "MF1"); cmp.disconnect(); } } private static void displayMessageFlowRunState( ConfigManagerProxy cmp, String brokerName, String egName, String flowName) { try { TopologyProxy topology = cmp.getTopology(); if (topology != null) { BrokerProxy b = topology.getBrokerByName(brokerName); if (b != null) { ExecutionGroupProxy eg = b.getExecutionGroupByName(egName); if (eg != null) { MessageFlowProxy mf = eg.getMessageFlowByName(flowName); if (mf != null) { boolean isRunning = mf.isRunning(); System.out.print("Flow "+flowName+" on " + egName+" on "+brokerName+" is "); if (isRunning) { System.out.println("running"); } else { System.out.println("stopped"); } } else { System.err.println("No such flow "+flowName); } } else { System.err.println("No such exegrp "+egName+"!"); } } else { System.err.println("No such broker "+brokerName); } } else { System.err.println("Topology not available!"); } } catch(ConfigManagerProxyPropertyNotInitializedException ex) { System.err.println("Comms problem! "+ex); } } }The method that does most of the work is displayMessageFlowRunState(). This method takes the valid ConfigManagerProxy handle gained previously and discovers the run-state of the message flow as follows:
import java.util.Enumeration; import com.ibm.broker.config.proxy.*; public class DisplayBrokerNames { 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!"); displayBrokerNames(cmp); cmp.disconnect(); } } private static void displayBrokerNames(ConfigManagerProxy cmp) { try { TopologyProxy topology = cmp.getTopology(); if (topology != null) { Enumeration allBrokers = topology.getBrokers(null); while (allBrokers.hasMoreElements()) { BrokerProxy thisBroker = (BrokerProxy) allBrokers.nextElement(); System.out.println("Broker "+thisBroker.getName()); } } } catch(ConfigManagerProxyPropertyNotInitializedException ex) { System.err.println("Comms problem! "+ex); } } }The key method is TopologyProxy.getBrokers(Properties). When supplied with a null argument, it returns an Enumeration of all the BrokerProxy objects in the domain. The program uses this method to look at each BrokerProxy in turn and display its name.
The Properties argument of TopologyProxy.getBrokers(Properties) can be used to exactly specify the characteristics of the brokers that are sought. It is possible to do this for nearly all of the methods that return administered objects, and is a powerful way of filtering those objects with which the program needs to work.
Examples of those characteristics that can be used to filter object look ups are the run-state and short description, as well as more obvious properties such as the name and UUID. In order to write logic to achieve this, it is necessary for you to understand how each administered object stores its information.
The properties of each administered object are stored locally inside the object using a hash table, where each property is represented as a {key, value} tuple. Each key is the name of an attribute (for example, name) and each value is the value (for example, BROKER1).
Each key name must be expressed using a constant from the AttributeConstants class (com.ibm.broker.config.proxy). A complete set of keys and possible values for each administered object is described in the Java documentation for the AttributesConstant class, or by using the Show raw property table for this object function in the Configuration Manager Proxy API Exerciser sample program. The latter displays the complete list of {key, value} pairs for each administered object.
Properties p = new Properties(); p.setProperty(AttributeConstants.OBJECT_RUNSTATE_PROPERTY, AttributeConstants.OBJECT_RUNSTATE_RUNNING); Enumeration e = executionGroup.getMessageFlows(p);Providing that the variable executionGroup is a valid ExecutionGroupProxy object, the returned enumeration only contains running message flows (OBJECT_RUN_STATE_PROPERTY equal to OBJECT_RUNSTATE_RUNNING).
Properties p = new Properties(); p.setProperty(AttributeConstants.NAME_PROPERTY, "shares"); TopicProxy t = topicProxy.getTopic(p);is an alternative to:
TopicProxy t = topicProxy.getTopicByName("shares");
If multiple {key, value} pairs are added to a property filter, all properties must be present in the child object in order for an object to match. It is not possible to perform a logical OR, or a logical NOT, on a filter without writing specific application code to do this.
When AdministeredObjects are first instantiated in an application, the CMP asks the Configuration Manager for the current set of properties for that object. This happens asynchronously, which means that the first time a property is requested there may be a pause while the CMP waits for the information to be supplied by the Configuration Manager. If the information does not arrive within a certain time (for example, if the Configuration Manager is not running), a ConfigManagerProxyPropertyNotInitializedException is thrown. The maximum time that the CMP waits is determined by the ConfigManagerProxy.setRetryCharacteristics() method.
Notices |
Trademarks |
Downloads |
Library |
Support |
Feedback
![]() ![]() |
ae33040_ |