The Configuration Manager Proxy subscriptions API

View and work with active subscriptions.

This task is part of the larger task of developing Configuration Manager Proxy (CMP) applications, and describes one of the advanced features of the CMP.

You can use the CMP to show and delete the set of active subscriptions in the domain. The following example gives information on all subscriptions to topics with names that begin with the string "shares".

import java.util.Enumeration;
import com.ibm.broker.config.proxy.*;

public class QuerySubscriptions {

  public static void main(String[] args) {

    ConfigManagerProxy cmp = null;
    BrokerProxy bp = null;
    TopologyProxy tp = null;
    try {
      ConfigManagerConnectionParameters cmcp =
         new MQConfigManagerConnectionParameters(
           "localhost",
           1414,
           "");
      cmp = ConfigManagerProxy.getInstance(cmcp);
      tp = cmp.getTopology();
      bp = tp.getBrokerByName("BROKER_A");   
    } catch (ConfigManagerProxyException cmpex) {
      System.out.println("Error connecting: "+cmpex);
    }
        
    if (cmp != null) {
      System.out.println("Connected to Config Manager!");
      querySubscriptionsByTopic(cmp, "shares%");
      cmp.disconnect();
    }
  }

  private static void querySubscriptionsByTopic(
    ConfigManagerProxy cmp,
    String topic)
  {
    try {
      SubscriptionQuery sq = bp.createSubscriptionQuery();
      sq.setString(SubscriptionParameters.TOPIC, topic); // set the topic
      SubscriptionsProxy matchingSubscriptions = sq.executeQuery();
        
            
      Enumeration e = matchingSubscriptions.elements();
      int matches = matchingSubscriptions.getSize();
      System.out.println("Found "+matches+" matches:");

      while (e.hasMoreElements()) {
        Subscription thisSub = (Subscription)e.nextElement();
        System.out.println("-----");
        System.out.println("Broker="+thisSub.getBroker());
        System.out.println("Topic="+thisSub.getTopicName());
        System.out.println("Client="+thisSub.getClient());
        System.out.println("Filter="+thisSub.getFilter());
        System.out.println("Reg date="
          +thisSub.getRegistrationDate());
        System.out.println("User="+thisSub.getUser());
        System.out.println("Sub point="
          +thisSub.getSubscriptionPoint());
      }
    } catch (ConfigManagerProxyException e) {
      e.printStackTrace();
    }
  }
}

The class that queries the set of active subscriptions is SubscriptionsQuery(), which defines the query that is used to filter the subscriptions. The parameters that you define in SubscriptionsParameters and SubscriptionsParameters.MQ can be set on an instance of the class to build up a query. You can include the % character to denote wildcard characters in parameters of type string.

The parameters SubscriptionsParameters.STARTDATE and SubscriptionsParameters.ENDDATE are of type GregorianCalendar. Use these parameters to constrain the registration time of the matching subscriptions.

In the preceding example, only the topic parameter, of type string, is set is shares%. This setting tells the CMP to return all subscriptions whose topic name begins with "shares".

The query is issued when you call the SubscriptionQuery.executeQuery() method. It returns an instance of SubscriptionsProxy, which represents the results of the query. Because this class inherits from the class AdministeredObject, the attributes of this object are supplied asynchronously by the Configuration Manager. Therefore, the methods that interrogate the SubscriptionsProxy attributes can temporarily block while the CMP waits for the information to arrive.

The class Subscription, and its subclass MQSubscription which represents an individual match from the query, is a small data structure that is used for convenience by the SubscriptionsProxy, and does not block or throw exceptions.

Even though SubscriptionsProxy objects are of AdministeredObject type, you cannot register AdministeredObjectListeners against them. This characteristic means that when the results of a query are returned from the Configuration Manager, you are not notified if the set of matching subscriptions changes, unless you resubmit the query. The consequence of this behavior is that the results of subscriptions queries are guaranteed correct only at the time the original query was made.

You can delete subscriptions using the SubscriptionsProxy.deleteSubscriptions() method. Because SubscriptionsProxy objects cannot have AdministeredObjectListeners, the outcome of such an action is published to listeners of the ConfigManagerProxy object.

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

Copyright IBM Corporation 1999, 2009Copyright IBM Corporation 1999, 2009.
Last updated : 2009-01-07 15:21:49

ae33120_