예제 #1
0
 @Override
 public void run() {
   Date lastSync = new Date();
   ChangedCollections cols = getChangedCollections(lastSync);
   lastSync = cols.getLastSync();
   logger.info("DB lastSync: " + lastSync);
   while (!stopped) {
     try {
       Thread.sleep(freqMillisec);
     } catch (InterruptedException e) {
       stopped = true;
       continue;
     }
     synchronized (ccls) {
       if (ccls.isEmpty()) {
         continue;
       }
     }
     cols = getChangedCollections(lastSync);
     lastSync = cols.getLastSync();
     LinkedList<PushNotification> toNotify = new LinkedList<PushNotification>();
     synchronized (ccls) {
       for (ICollectionChangeListener ccl : ccls) {
         Set<SyncCollection> monitoredCollections = ccl.getMonitoredCollections();
         Set<SyncCollection> changes =
             getChangedCollections(ccl.getSession(), cols, monitoredCollections);
         if (!changes.isEmpty()) {
           toNotify.add(new PushNotification(changes, ccl));
         }
       }
     }
     for (PushNotification pn : toNotify) {
       pn.emit();
     }
   }
 }
예제 #2
0
  private Set<SyncCollection> getChangedCollections(
      BackendSession session, ChangedCollections cols, Set<SyncCollection> monitoredCollections) {
    Set<SyncCollection> ret = new HashSet<SyncCollection>();

    for (SyncCollection sc : cols.getChanged()) {
      int id;
      try {
        id = backend.getCollectionIdFor(session.getDevId(), sc.getCollectionPath());
        sc.setCollectionId(id);
        logger.info(
            "processing sc: id: " + sc.getCollectionId() + " name: " + sc.getCollectionPath());
        if (monitoredCollections.contains(sc)) {
          logger.info(
              "******** PUSH "
                  + sc.getCollectionId()
                  + " name: "
                  + sc.getCollectionPath()
                  + " ********");
          ret.add(sc);
        } else {
          logger.info("** " + sc.getCollectionId() + " modified but nobody cares **");
          for (SyncCollection mon : monitoredCollections) {
            logger.info("   * monitored: " + mon.getCollectionId());
          }
        }
      } catch (ActiveSyncException e) {
      }
    }

    for (SyncCollection toPush : ret) {
      try {
        String colName = toPush.getCollectionPath();
        int collectionId = backend.getCollectionIdFor(session.getDevId(), colName);
        toPush.setCollectionId(collectionId);
      } catch (ActiveSyncException e) {
      }
    }

    return ret;
  }