Java 类com.intellij.openapi.vfs.newvfs.persistent.RefreshWorker 实例源码

项目:intellij-ce-playground    文件:RefreshSessionImpl.java   
public void cancel() {
  myCancelled = true;

  RefreshWorker worker = myWorker;
  if (worker != null) {
    worker.cancel();
  }
}
项目:intellij-ce-playground    文件:LocalFileSystemTest.java   
public static void doTestInterruptedRefresh(@NotNull File top) throws Exception {
  File sub = IoTestUtil.createTestDir(top, "sub");
  File subSub = IoTestUtil.createTestDir(sub, "sub_sub");
  File file1 = IoTestUtil.createTestFile(sub, "sub_file_to_stop_at");
  File file2 = IoTestUtil.createTestFile(subSub, "sub_sub_file");
  LocalFileSystem lfs = LocalFileSystem.getInstance();
  NewVirtualFile topDir = (NewVirtualFile)lfs.refreshAndFindFileByIoFile(top);
  assertNotNull(topDir);
  NewVirtualFile subFile1 = (NewVirtualFile)lfs.refreshAndFindFileByIoFile(file1);
  assertNotNull(subFile1);
  NewVirtualFile subFile2 = (NewVirtualFile)lfs.refreshAndFindFileByIoFile(file2);
  assertNotNull(subFile2);
  topDir.refresh(false, true);
  assertFalse(topDir.isDirty());
  assertFalse(subFile1.isDirty());
  assertFalse(subFile2.isDirty());

  try {
    subFile1.markDirty();
    subFile2.markDirty();
    RefreshWorker.setCancellingCondition(file -> "sub_file_to_stop_at".equals(file.getName()));
    topDir.refresh(false, true);
    // should remain dirty after aborted refresh
    assertTrue(subFile1.isDirty());
    assertTrue(subFile2.isDirty());

    RefreshWorker.setCancellingCondition(null);
    topDir.refresh(false, true);
    assertFalse(topDir.isDirty());
    assertFalse(subFile1.isDirty());
    assertFalse(subFile2.isDirty());
  }
  finally {
    RefreshWorker.setCancellingCondition(null);
  }
}
项目:tools-idea    文件:RefreshSessionImpl.java   
public void cancel() {
  myCancelled = true;

  RefreshWorker worker = myWorker;
  if (worker != null) {
    worker.cancel();
  }
}
项目:consulo    文件:RefreshSessionImpl.java   
void cancel() {
  myCancelled = true;

  RefreshWorker worker = myWorker;
  if (worker != null) {
    worker.cancel();
  }
}
项目:intellij-ce-playground    文件:RefreshSessionImpl.java   
public void scan() {
  List<VirtualFile> workQueue = myWorkQueue;
  myWorkQueue = new ArrayList<VirtualFile>();
  boolean haveEventsToFire = myFinishRunnable != null || !myEvents.isEmpty();

  if (!workQueue.isEmpty()) {
    final LocalFileSystem fileSystem = LocalFileSystem.getInstance();
    final FileWatcher watcher;
    if (fileSystem instanceof LocalFileSystemImpl) {
      LocalFileSystemImpl fs = (LocalFileSystemImpl)fileSystem;
      fs.markSuspiciousFilesDirty(workQueue);
      watcher = fs.getFileWatcher();
    }
    else {
      watcher = null;
    }

    long t = 0;
    if (LOG.isDebugEnabled()) {
      LOG.debug("scanning " + workQueue);
      t = System.currentTimeMillis();
    }

    for (VirtualFile file : workQueue) {
      if (myCancelled) break;

      NewVirtualFile nvf = (NewVirtualFile)file;
      if (!myIsRecursive && (!myIsAsync || (watcher != null && !watcher.isWatched(nvf)))) {
        // we're unable to definitely refresh synchronously by means of file watcher.
        nvf.markDirty();
      }

      RefreshWorker worker = myWorker = new RefreshWorker(nvf, myIsRecursive);
      worker.scan();
      List<VFileEvent> events = worker.getEvents();
      if (myEvents.addAll(events)) {
        haveEventsToFire = true;
      }
    }

    if (t != 0) {
      t = System.currentTimeMillis() - t;
      LOG.debug((myCancelled ? "cancelled, " : "done, ") + t + " ms, events " + myEvents);
    }
  }

  myWorker = null;
  iHaveEventsToFire = haveEventsToFire;
}
项目:tools-idea    文件:RefreshSessionImpl.java   
public void scan() {
  List<VirtualFile> workQueue = myWorkQueue;
  myWorkQueue = new ArrayList<VirtualFile>();
  boolean haveEventsToFire = myFinishRunnable != null || !myEvents.isEmpty();

  if (!workQueue.isEmpty()) {
    LocalFileSystemImpl fs = (LocalFileSystemImpl)LocalFileSystem.getInstance();
    fs.markSuspiciousFilesDirty(workQueue);
    FileWatcher watcher = fs.getFileWatcher();

    long t = 0;
    if (LOG.isDebugEnabled()) {
      LOG.debug("scanning " + workQueue);
      t = System.currentTimeMillis();
    }

    for (VirtualFile file : workQueue) {
      if (myCancelled) break;

      NewVirtualFile nvf = (NewVirtualFile)file;
      if (!myIsRecursive && (!myIsAsync || !watcher.isWatched(nvf))) {
        // we're unable to definitely refresh synchronously by means of file watcher.
        nvf.markDirty();
      }

      RefreshWorker worker = myWorker = new RefreshWorker(nvf, myIsRecursive);
      worker.scan();
      List<VFileEvent> events = worker.getEvents();
      if (myEvents.addAll(events)) {
        haveEventsToFire = true;
      }
    }

    if (t != 0) {
      t = System.currentTimeMillis() - t;
      LOG.debug((myCancelled ? "cancelled, " : "done, ") + t + " ms, events " + myEvents);
    }
  }

  myWorker = null;
  iHaveEventsToFire = haveEventsToFire;
}
项目:consulo    文件:LocalFileSystemTest.java   
public static void doTestInterruptedRefresh(@Nonnull File top) throws Exception {
  File sub = IoTestUtil.createTestDir(top, "sub");
  File subSub = IoTestUtil.createTestDir(sub, "sub_sub");
  File file1 = IoTestUtil.createTestFile(sub, "sub_file_to_stop_at");
  File file2 = IoTestUtil.createTestFile(subSub, "sub_sub_file");
  LocalFileSystem lfs = LocalFileSystem.getInstance();
  NewVirtualFile topDir = (NewVirtualFile)lfs.refreshAndFindFileByIoFile(top);
  assertNotNull(topDir);
  NewVirtualFile subFile1 = (NewVirtualFile)lfs.refreshAndFindFileByIoFile(file1);
  assertNotNull(subFile1);
  NewVirtualFile subFile2 = (NewVirtualFile)lfs.refreshAndFindFileByIoFile(file2);
  assertNotNull(subFile2);
  topDir.refresh(false, true);
  assertFalse(topDir.isDirty());
  assertFalse(subFile1.isDirty());
  assertFalse(subFile2.isDirty());

  try {
    subFile1.markDirty();
    subFile2.markDirty();
    RefreshWorker.setCancellingCondition(new Function<VirtualFile, Boolean>() {
      @Override
      public Boolean fun(VirtualFile file) {
        return "sub_file_to_stop_at".equals(file.getName());
      }
    });
    topDir.refresh(false, true);
    // should remain dirty after aborted refresh
    assertTrue(subFile1.isDirty());
    assertTrue(subFile2.isDirty());

    RefreshWorker.setCancellingCondition(null);
    topDir.refresh(false, true);
    assertFalse(topDir.isDirty());
    assertFalse(subFile1.isDirty());
    assertFalse(subFile2.isDirty());
  }
  finally {
    RefreshWorker.setCancellingCondition(null);
  }
}
项目:consulo    文件:RefreshSessionImpl.java   
public void scan() {
  List<VirtualFile> workQueue = myWorkQueue;
  myWorkQueue = new ArrayList<>();
  boolean haveEventsToFire = myFinishRunnable != null || !myEvents.isEmpty();

  if (!workQueue.isEmpty()) {
    LocalFileSystem fs = LocalFileSystem.getInstance();
    if (fs instanceof LocalFileSystemImpl) {
      ((LocalFileSystemImpl)fs).markSuspiciousFilesDirty(workQueue);
    }

    long t = 0;
    if (LOG.isTraceEnabled()) {
      LOG.trace("scanning " + workQueue);
      t = System.currentTimeMillis();
    }

    int count = 0;
    refresh: do {
      if (LOG.isTraceEnabled()) LOG.trace("try=" + count);

      for (VirtualFile file : workQueue) {
        if (myCancelled) break refresh;

        NewVirtualFile nvf = (NewVirtualFile)file;
        if (!myIsRecursive && !myIsAsync) {
          nvf.markDirty();  // always scan when non-recursive AND synchronous - needed e.g. when refreshing project files on open
        }

        RefreshWorker worker = new RefreshWorker(nvf, myIsRecursive);
        myWorker = worker;
        worker.scan();
        haveEventsToFire |= myEvents.addAll(worker.getEvents());
      }

      count++;
      if (LOG.isTraceEnabled()) LOG.trace("events=" + myEvents.size());
    }
    while (!myCancelled && myIsRecursive && count < 3 && workQueue.stream().anyMatch(f -> ((NewVirtualFile)f).isDirty()));

    if (t != 0) {
      t = System.currentTimeMillis() - t;
      LOG.trace((myCancelled ? "cancelled, " : "done, ") + t + " ms, events " + myEvents);
    }
  }

  myWorker = null;
  myHaveEventsToFire = haveEventsToFire;
}