private void processCqEvent(CqEvent cqEvent) throws IOException {
    if (preloadLatch.getCount() > 0) waitForPreload();

    Operation operation = cqEvent.getQueryOperation();

    if (operation.isCreate() || operation.isUpdate()) {
      Indexable indexable =
          indexableFactory.createIndexable(cqEvent.getKey(), cqEvent.getNewValue());

      if (operation.isCreate()) searchEngine.insert(indexable);
      else if (operation.isUpdate()) searchEngine.update(indexable);
    } else if (operation.isDestroy()) {
      searchEngine.delete(indexableFactory.createKeyTerm(cqEvent.getKey()));
    }
  }
 public void onError(CqEvent cqEvent) {
   logger.debug("error on " + getClass() + " (a CqListener) ");
   throw new RuntimeException("error when interacting with region.", cqEvent.getThrowable());
 }
  /**
   * Given a List of QueryObjects known to be inconsistent as determined by validation, log where
   * the suspect objects are found by checking for it in 1) the expected List 2) the CQ history of
   * events 3) the select results 4) the localRegion
   *
   * @param inconsistencies A List of suspect QueryObjects to check in each location.
   * @param expected The expected List of objects for a query.
   * @param history The CQHistory for the query
   * @returns
   */
  private String getLocationString(List inconsistencies, List expected, CQHistory history) {
    StringBuffer aStr = new StringBuffer();
    for (int i = 0; i < inconsistencies.size(); i++) {
      QueryObject suspect = (QueryObject) (inconsistencies.get(i));

      // check the local region
      boolean found = false;
      Iterator it = aRegion.keySet().iterator();
      while (it.hasNext()) {
        Object key = it.next();
        Region.Entry entry = aRegion.getEntry(key);
        QueryObject qo = (QueryObject) (entry.getValue());
        if ((qo != null) && (qo.equals(suspect))) {
          found = true;
          aStr.append(
              qo.toStringAbbreviated()
                  + " was found in "
                  + aRegion.getFullPath()
                  + " at key "
                  + key
                  + "\n");
        }
      }
      if (!found) {
        aStr.append(
            suspect.toStringAbbreviated() + " was NOT found in " + aRegion.getFullPath() + "\n");
      }

      // seach for all occurrences in expected list
      found = false;
      it = expected.iterator();
      while (it.hasNext()) {
        QueryObject qo = (QueryObject) (it.next());
        if (qo.equals(suspect)) {
          found = true;
          aStr.append(qo.toStringAbbreviated() + " was found in expected results\n");
        }
      }
      if (!found) {
        aStr.append(suspect.toStringAbbreviated() + " was NOT found in expected results\n");
      }

      // seach for all occurrences in selectResults
      SelectResults selResults = history.getSelectResults();
      found = false;
      it = selResults.iterator();
      while (it.hasNext()) {
        QueryObject qo = (QueryObject) (it.next());
        if (qo.equals(suspect)) {
          found = true;
          aStr.append(qo.toStringAbbreviated() + " was found in SelectResults\n");
        }
      }
      if (!found) {
        aStr.append(suspect.toStringAbbreviated() + " was NOT found in SelectResults\n");
      }

      // seach for all occurrences in history
      found = false;
      List eventList = history.getEvents();
      for (int j = 0; j < eventList.size(); j++) {
        CqEvent event = (CqEvent) (eventList.get(j));
        QueryObject qo = (QueryObject) (event.getNewValue());
        if ((qo != null) && (qo.equals(suspect))) {
          found = true;
          aStr.append(
              qo.toStringAbbreviated()
                  + " was found in event history as new value "
                  + event
                  + "\n");
        }
      }
      if (!found) {
        aStr.append(suspect.toStringAbbreviated() + " was NOT found in CqEvent history\n");
      }
    }
    return aStr.toString();
  }