配置管理器代理预订 API

这是开发配置管理器代理(CMP)应用程序中较大任务的一部分,并且是 CMP 的某项高级功能。

您可以使用 CMP 来在域中显示和删除活动预订集。 下列示例给出了的所有主题(其名称以字符串“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();
}
}
}

查询活动预订集的方法是 ConfigManagerProxy.getSubscriptions(),它定义了用于过滤预订的查询。主题、代理、用户标识和 subscriptionPoint 参数是字符串,可以包含表示通配符字符的 % 字符。

startDateendDate 参数是类型 GregorianCalendar,可用于约束匹配预订的注册时间。对于该方法的所有参数,空值或在字符串变量中的空值都表示“不使用该属性过滤”。

在先前的示例中,仅有提供给该方法的非空参数是主题字符串shares%,它告诉 CMP 要返回主题名称以“share”开头的所有预订。

从该方法返回的是表示查询结果的 SubscriptionsProxy 的实例。由于该类继承自 AdministeredObject,因此从配置管理器异步提供该对象的属性,所以在 CMP 等待信息到达期间,询问其属性的方法可能暂时阻止。

请注意,预订对象表示来自查询的单个匹配,它是由 SubscriptionsProxy 出于方便而使用小型数据结构,因此不阻止或抛出异常。

虽然是 AdministeredObject 类型,但 SubscriptionsProxy 对象无法在其上注册 AdministeredObjectListeners。 这表示一旦从配置管理器返回查询结果,除非重新提交查询,否则当匹配预定更改时,就无法获得通知。该行为的结果是在最初提交查询时就保证预定查询的结果只能是正确的。

使用 SubscriptionsProxy.deleteSubscriptions() 方法可以删除预订。 由于 SubscriptionsProxy 对象无法具有 AdministeredObjectListeners,因此这类操作的结果会发布至 ConfigManagerProxy 对象的侦听器。

相关任务
配置用于开发和运行配置管理器应用程序的环境
配置管理器代理的高级功能
声明 | 商标 | 下载 | | 支持 | 反馈
Copyright IBM Corporation 1999, 2006 最后更新:2006/05/19
ae33120_