コード例 #1
0
  protected void doRun() throws Exception {
    SyncWatchEvent lastSyncWatchEvent = SyncWatchEventService.getLastSyncWatchEvent(_syncAccountId);

    if (lastSyncWatchEvent == null) {
      return;
    }

    long delta = System.currentTimeMillis() - lastSyncWatchEvent.getTimestamp();

    if (delta <= 500) {
      SyncEngineUtil.fireSyncEngineStateChanged(
          _syncAccountId, SyncEngineUtil.SYNC_ENGINE_STATE_PROCESSING);

      return;
    }

    if (_logger.isTraceEnabled()) {
      _logger.trace("Processing Sync watch events");
    }

    _pendingTypePKSyncFileIds.clear();

    List<SyncWatchEvent> syncWatchEvents = null;

    if (OSDetector.isApple()) {
      syncWatchEvents = SyncWatchEventService.findBySyncAccountId(_syncAccountId);
    } else {
      syncWatchEvents =
          SyncWatchEventService.findBySyncAccountId(_syncAccountId, "eventType", true);
    }

    for (SyncWatchEvent syncWatchEvent : syncWatchEvents) {
      processSyncWatchEvent(syncWatchEvent);
    }

    for (Map.Entry<String, List<SyncWatchEvent>> entry : _dependentSyncWatchEventsMaps.entrySet()) {

      SyncFile syncFile = SyncFileService.fetchSyncFile(entry.getKey());

      if ((syncFile != null) && (syncFile.getTypePK() > 0)) {
        for (SyncWatchEvent syncWatchEvent : entry.getValue()) {
          processSyncWatchEvent(syncWatchEvent);
        }
      }
    }

    SyncEngineUtil.fireSyncEngineStateChanged(
        _syncAccountId, SyncEngineUtil.SYNC_ENGINE_STATE_PROCESSED);

    _processedSyncWatchEventIds.clear();
  }
コード例 #2
0
  @Test
  public void testWatchEvent1() {
    SyncSiteWatchEventListener syncSiteWatchEventListener =
        new SyncSiteWatchEventListener(syncAccount.getSyncAccountId());

    String sourceFilePathName = FileUtil.getFilePathName(filePathName, "test-site1", "a.txt");

    syncSiteWatchEventListener.watchEvent(
        SyncWatchEvent.EVENT_TYPE_RENAME_FROM, Paths.get(sourceFilePathName));

    String targetFilePathName = FileUtil.getFilePathName(filePathName, "test-site2", "a.txt");

    syncSiteWatchEventListener.watchEvent(
        SyncWatchEvent.EVENT_TYPE_RENAME_TO, Paths.get(targetFilePathName));

    SyncWatchEvent lastSyncWatchEvent =
        SyncWatchEventService.getLastSyncWatchEvent(syncAccount.getSyncAccountId());

    Assert.assertEquals(SyncWatchEvent.EVENT_TYPE_CREATE, lastSyncWatchEvent.getEventType());
  }