public void addXPathQuery(
      String xpathExpression, String subscriptionId, SubscriptionState subscribeRequest)
      throws RuntimeException {
    index++;
    counter++;
    if (WSMGParameter.debugYFilter) logger.debug("QueryExp=" + xpathExpression);

    Integer yFilterIdObj = xPathToYFilterId.get(xpathExpression);
    int yFilterId = -1;
    if (yFilterIdObj != null) {
      yFilterId = yFilterIdObj.intValue();
    } else {
      Query query = XPQuery.parseQuery(xpathExpression, index);
      if (query == null) {
        throw new RuntimeException("Invalid XPath expression:" + xpathExpression);
      }
      if (WSMGParameter.debugYFilter)
        logger.debug("addSubscription " + xpathExpression + " query :" + query);
      yFilterId = yfilter.addQuery(query);
      if (WSMGParameter.debugYFilter) yfilter.printQueryIndex();
      xPathToYFilterId.put(xpathExpression, Integer.valueOf(yFilterId));
      yFilterIdToXPath.put(new Integer(yFilterId), xpathExpression);
      yFilterIdToQuery.put(yFilterId, query);
    }
    if (WSMGParameter.debugYFilter) logger.debug("YFilterId=" + yFilterId);

    consumerListmanager.addToConsumerList(xpathExpression, subscribeRequest, subscriptionId);
  }
  public List<ConsumerInfo> getMatchingConsumerList(String messageString) {
    List<ConsumerInfo> matchingConsumerList = new LinkedList<ConsumerInfo>();
    XMLTree tree = new XMLTree(new java.io.StringReader(messageString));
    if (WSMGParameter.debugYFilter) tree.print();
    yfilter.setEventSequence(tree.getEvents());
    yfilter.startParsing();

    // print the matched queries //
    if (SystemGlobals.hasQueries) {
      if (WSMGParameter.debugYFilter) yfilter.printQueryResults(System.out);

    } else {
      System.out.println("no match");
      return matchingConsumerList;
    }

    Iterator<Integer> it = (Iterator<Integer>) yfilter.getMatchedQueries().iterator();
    while (it.hasNext()) {
      Integer qid = it.next();

      String xpath = yFilterIdToXPath.get(qid);
      ConsumerList consumerList = consumerListmanager.getConsumerListByToken(xpath);

      if (consumerList != null) { // has subscription to this topic
        matchingConsumerList.addAll(consumerList.getConsumerList());
      }
    }
    yfilter.clear();
    return matchingConsumerList;
  }
  public int removeSubscription(String subscriptionId) {

    String xPath = consumerListmanager.getTokenBySubscriptionId(subscriptionId);
    int result = consumerListmanager.removeFromConsumerList(subscriptionId, xPath);
    if (result == 0) {
      return 0;
    }
    int currentConsumerCount = consumerListmanager.getConsumerListByToken(xPath).size();
    if (currentConsumerCount == 0) {
      Integer yFilterId = xPathToYFilterId.get(xPath);
      Query q = yFilterIdToQuery.get(yFilterId);
      yfilter.deleteQuery(q, q.getQueryId());
      yFilterIdToQuery.remove(yFilterId);
    }
    counter--;
    return result;
  }