The Configuration Manager Proxy subscriptions API

This is part of the larger task of developing Configuration Manager Proxy (CMP) applications and is 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;
    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!");
      querySubscriptionsByTopic(cmp, "shares%");
      cmp.disconnect();
    }
  }

  private static void querySubscriptionsByTopic(
    ConfigManagerProxy cmp,
    String topic)
  {
    try {
      SubscriptionsProxy matchingSubscriptions =
        cmp.getSubscriptions(topic, // filter by topic
                             null, // don't filter by broker
                             null, // don't filter by username
                             null, // don't filter by sub point
                             null, // no start date,
                             null); // no end date
            
      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 method that queries the set of active subscriptions is ConfigManagerProxy.getSubscriptions(), which defines the query used to filter the subscriptions. The topic, broker, user ID, and subscriptionPoint parameters are strings which can include the % character to denote wild card characters.

The startDate and endDate parameters are of type GregorianCalendar, which can be used to constrain the registration time of the matching subscriptions. For all parameters to this method, a null value or, in the case of the string arguments, an empty value means "do not filter by this attribute".

In the preceding example, the only non-null parameter that is supplied to this method is the topic string shares%, that tells the CMP to return all subscriptions whose topic name begins with "shares".

Returned from this method is an instance of SubscriptionsProxy which represents the results of the query. As this class inherits from AdministeredObject, the attributes of this object are supplied asynchronously from the Configuration Manager and so the methods that interrogate its attributes can block temporarily while the CMP waits for the information to arrive.

Note that the Subscription object, which represents an individual match from the query, is a small data structure used for convenience by the SubscriptionsProxy and as such does not block or throw exceptions.

Despite being of AdministeredObject type, SubscriptionsProxy objects cannot have AdministeredObjectListeners registered against them. This means that once 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.

It is possible to delete subscriptions using the SubscriptionsProxy.deleteSubscriptions() method. As 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