sub.update(subscribeQos);
}
log.info("Ignoring duplicate subscription '" +
((xmlKey.getOid()==null)?((xmlKey.getDomain()==null)?xmlKey.getQueryString():xmlKey.getDomain()):xmlKey.getOid()) +
"' as you have set multiSubscribe to false");
StatusQosData qos = new StatusQosData(glob, MethodName.SUBSCRIBE);
SubscriptionInfo i = (SubscriptionInfo)vec.elementAt(0);
qos.setState(Constants.STATE_WARN);
qos.setSubscriptionId(i.getSubscriptionId());
return qos.toXml();
}
}
SubscriptionInfo subsQuery = null;
if (xmlKey.isQuery()) { // fires event for query subscription, this needs to be remembered for a match check of future published messages
// if (true) { // fires event for query subscription, this needs to be remembered for a match check of future published messages
subsQuery = new SubscriptionInfo(glob, sessionInfo, xmlKey, subscribeQos);
returnOid = subsQuery.getSubscriptionId(); // XPath query
fireSubscribeEvent(subsQuery);
}
KeyData[] keyDataArr = queryMatchingKeys(sessionInfo, xmlKey, subscribeQos.getData());
for (int jj=0; jj<keyDataArr.length; jj++) {
KeyData xmlKeyExact = keyDataArr[jj];
if (xmlKeyExact == null && xmlKey.isExact()) // subscription on a yet unknown topic ...
xmlKeyExact = xmlKey;
else if (xmlKeyExact != null && xmlKey.isDomain()) {
xmlKeyExact.setQueryType(xmlKey.getQueryType());
}
SubscriptionInfo subs = null;
if (sessionInfo.getConnectQos().duplicateUpdates() == false) {
Vector vec = clientSubscriptions.getSubscriptionByOid(sessionInfo, xmlKeyExact.getOid(), true);
if (vec != null) {
if (vec.size() > 0) {
subs = (SubscriptionInfo)vec.firstElement();
if (log.isLoggable(Level.FINE)) log.fine("Session '" + sessionInfo.getId() +
"', topic '" + xmlKeyExact.getOid() + "' is subscribed " +
vec.size() + " times with duplicateUpdates==false");
}
if (vec.size() > 1)
log.severe("Internal problem for session '" + sessionInfo.getId() + "', message '" + xmlKeyExact.getOid() + "' is subscribed " + vec.size() + " times but duplicateUpdates==false!");
}
}
if (subs == null) {
if (subsQuery != null) {
subs = new SubscriptionInfo(glob, sessionInfo, subsQuery, xmlKeyExact);
subsQuery.addSubscription(subs);
}
else
subs = new SubscriptionInfo(glob, sessionInfo, xmlKeyExact, subscribeQos);
}
subscribeToOid(subs, false); // fires event for subscription
if (returnOid.equals("")) returnOid = subs.getSubscriptionId();
}
StatusQosData qos = null;
if (this.glob.isClusterManagerReady()) { // cluster support - forward message to master
try {
subscribeQos.setSubscriptionId(returnOid); // force the same subscriptionId on all cluster nodes
SubscribeReturnQos ret = glob.getClusterManager().forwardSubscribe(sessionInfo, xmlKey, subscribeQos);
if (ret != null)
qos = ret.getData();
//Thread.currentThread().dumpStack();
//if (ret != null) return ret.toXml();
}
catch (XmlBlasterException e) {
if (e.getErrorCode() == ErrorCode.RESOURCE_CONFIGURATION_PLUGINFAILED) {
this.glob.setUseCluster(false);
}
else {
e.printStackTrace();
throw e;
}
}
}
if (qos == null || qos.getSubscriptionId() == null || qos.getSubscriptionId().length() < 1) {
// The cluster subId is unique in another cluster node as well e.g.: "__subId:heron-2"
if (qos == null) qos = new StatusQosData(glob, MethodName.SUBSCRIBE);
qos.setSubscriptionId(returnOid);
}
if (log.isLoggable(Level.FINER)) log.finer("Leaving subscribe(oid='" + xmlKey.getOid() + "', queryType='" + xmlKey.getQueryType() +
"', query='" + xmlKey.getQueryString() + "', domain='" + xmlKey.getDomain() + "') from client '" +
sessionInfo.getId() + "' -> subscriptionId='" + qos.getSubscriptionId() + "'");
return qos.toXml();
}
catch (XmlBlasterException e) {
log.warning(e.getMessage());
throw e;
}