/**
* Does the xmlBlaster subscribe.
*/
private void subscribe() {
try {
SubscribeKey sk = null;
String qStr = null;
if (oid.length() > 0) {
sk = new SubscribeKey(glob, oid);
qStr = oid;
}
else if (xpath.length() > 0) {
sk = new SubscribeKey(glob, xpath, Constants.XPATH);
qStr = xpath;
}
if (domain.length() > 0) { // cluster routing information
if (sk == null) sk = new SubscribeKey(glob, "", Constants.DOMAIN); // usually never
sk.setDomain(domain);
qStr = domain;
}
SubscribeQos sq = new SubscribeQos(glob);
sq.setWantInitialUpdate(initialUpdate);
sq.setWantUpdateOneway(updateOneway);
sq.setMultiSubscribe(multiSubscribe);
sq.setPersistent(persistentSubscribe);
sq.setWantNotify(notifyOnErase);
sq.setWantLocal(local);
sq.setWantContent(wantContent);
HistoryQos historyQos = new HistoryQos(glob);
historyQos.setNumEntries(historyNumUpdates);
historyQos.setNewestFirst(historyNewestFirst);
sq.setHistoryQos(historyQos);
if (filterQuery.length() > 0) {
AccessFilterQos filter = new AccessFilterQos(glob, filterType, filterVersion, filterQuery);
sq.addAccessFilter(filter);
}
if (clientPropertyMap != null) {
Iterator it = clientPropertyMap.keySet().iterator();
while (it.hasNext()) {
String key = (String)it.next();
sq.addClientProperty(key, clientPropertyMap.get(key).toString());
}
}
log.info("SubscribeKey=\n" + sk.toXml());
log.info("SubscribeQos=\n" + sq.toXml());
if (firstConnect && (interactive && !autoSubscribe)) {
Global.waitOnKeyboardHit("Hit a key to subscribe '" + qStr + "'");
}
firstConnect = false;
this.srq = con.subscribe(sk, sq);
subscribeServerId = con.getConnectReturnQos().getSecretSessionId() + con.getConnectReturnQos().getServerInstanceId();
log.info("Subscribed on topic '" + ((oid.length() > 0) ? oid : xpath) +
"', got subscription id='" + this.srq.getSubscriptionId() + "'\n" + this.srq.toXml());
if (log.isLoggable(Level.FINEST)) log.finest("Subscribed: " + sk.toXml() + sq.toXml() + srq.toXml());
}
catch (XmlBlasterException e) {
log.severe(e.getMessage());
}
}