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

项目:intellij-ce-playground    文件:TestStateStorage.java   
public TestStateStorage(Project project) {

    myFile = new File(getTestHistoryRoot(project).getPath() + "/testStateMap");
    FileUtilRt.createParentDirs(myFile);
    try {
      myMap = initializeMap();
    } catch (IOException e) {
      LOG.error(e);
    }
    myMapFlusher = FlushingDaemon.everyFiveSeconds(new Runnable() {
      @Override
      public void run() {
        flushMap();
      }
    });

    Disposer.register(project, this);
  }
项目:consulo    文件:ContentHashesSupport.java   
static void initContentHashesEnumerator() throws IOException {
  if (ourHashesWithFileType != null) return;
  synchronized (ContentHashesSupport.class) {
    if (ourHashesWithFileType != null) return;
    final File hashEnumeratorFile = new File(IndexInfrastructure.getPersistentIndexRoot(), "hashesWithFileType");
    try {
      ContentHashesUtil.HashEnumerator hashEnumerator = new ContentHashesUtil.HashEnumerator(hashEnumeratorFile, null);
      FlushingDaemon.everyFiveSeconds(ContentHashesSupport::flushContentHashes);
      ShutDownTracker.getInstance().registerShutdownTask(ContentHashesSupport::flushContentHashes);
      ourHashesWithFileType = hashEnumerator;
    }
    catch (IOException ex) {
      IOUtil.deleteAllFilesStartingWith(hashEnumeratorFile);
      throw ex;
    }
  }
}
项目:intellij-ce-playground    文件:ContentHashesSupport.java   
static void initContentHashesEnumerator() throws IOException {
  if (ourHashesWithFileType != null) return;
  synchronized (ContentHashesSupport.class) {
    if (ourHashesWithFileType != null) return;
    ContentHashesUtil.HashEnumerator hashEnumerator = null;
    final File hashEnumeratorFile = new File(IndexInfrastructure.getPersistentIndexRoot(), "hashesWithFileType");
    try {
      hashEnumerator = new ContentHashesUtil.HashEnumerator(hashEnumeratorFile, null);
      FlushingDaemon.everyFiveSeconds(new Runnable() {
        @Override
        public void run() {
          flushContentHashes();
        }
      });
      ShutDownTracker.getInstance().registerShutdownTask(new Runnable() {
        @Override
        public void run() {
          flushContentHashes();
        }
      });
      ourHashesWithFileType = hashEnumerator;
    } catch (IOException ex) {
      IOUtil.deleteAllFilesStartingWith(hashEnumeratorFile);
      throw ex;
    }
  }
}
项目:consulo    文件:TestStateStorage.java   
public TestStateStorage(Project project) {
  String directoryPath = getTestHistoryRoot(project).getPath();

  myFile = new File(directoryPath + "/testStateMap");
  FileUtilRt.createParentDirs(myFile);

  try {
    myMap = initializeMap();
  } catch (IOException e) {
    LOG.error(e);
  }
  myMapFlusher = FlushingDaemon.everyFiveSeconds(this::flushMap);
}
项目:consulo    文件:FileBasedIndexImpl.java   
@Override
protected IndexConfiguration finish() {
  try {
    state.finalizeFileTypeMappingForIndices();

    String rebuildNotification = null;
    if (currentVersionCorrupted) {
      rebuildNotification = "Index files on disk are corrupted. Indices will be rebuilt.";
    }
    else if (versionChanged.get()) {
      rebuildNotification = "Index file format has changed for some indices. These indices will be rebuilt.";
    }
    if (rebuildNotification != null && !ApplicationManager.getApplication().isHeadlessEnvironment() && Registry.is("ide.showIndexRebuildMessage")) {
      NOTIFICATIONS.createNotification("Index Rebuild", rebuildNotification, NotificationType.INFORMATION, null).notify(null);
    }

    state.freeze();
    myState = state; // memory barrier
    // check if rebuild was requested for any index during registration
    for (ID<?, ?> indexId : state.getIndexIDs()) {
      try {
        RebuildStatus.clearIndexIfNecessary(indexId, () -> clearIndex(indexId));
      }
      catch (StorageException e) {
        requestRebuild(indexId);
        LOG.error(e);
      }
    }

    registerIndexableSet(new AdditionalIndexableFileSet(), null);
    return state;
  }
  finally {
    ShutDownTracker.getInstance().registerShutdownTask(FileBasedIndexImpl.this::performShutdown);
    saveRegisteredIndicesAndDropUnregisteredOnes(state.getIndexIDs());

    myFlushingFuture = FlushingDaemon.everyFiveSeconds(new Runnable() {
      private int lastModCount;

      @Override
      public void run() {
        mySerializationManagerEx.flushNameStorage();

        if (lastModCount == myLocalModCount) {
          flushAllIndices(lastModCount);
        }
        lastModCount = myLocalModCount;
      }
    });
    myInitialized = true;  // this will ensure that all changes to component's state will be visible to other threads

    myChangedFilesCollector.ensureUpToDateAsync();
  }
}