Exemplo n.º 1
0
 @Override
 public IListenerRegistration addChangeListener(ICollectionChangeListener ccl) {
   ListenerRegistration ret = new ListenerRegistration(ccl, registeredListeners);
   synchronized (registeredListeners) {
     registeredListeners.add(ccl);
   }
   logger.info(
       "[" + ccl.getSession().getLoginAtDomain() + "] change listener registered on backend");
   return ret;
 }
Exemplo n.º 2
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();
     }
   }
 }