Search in sources :

Example 1 with ConcurrentIntObjectMap

use of com.intellij.util.containers.ConcurrentIntObjectMap in project intellij-community by JetBrains.

the class RefResolveServiceImpl method processBatch.

private void processBatch(@NotNull final ProgressIndicator indicator, @NotNull Set<VirtualFile> files) {
    assert !myApplication.isDispatchThread();
    final int resolvedInPreviousBatch = this.resolvedInPreviousBatch;
    final int totalSize = files.size() + resolvedInPreviousBatch;
    final ConcurrentIntObjectMap<int[]> fileToForwardIds = ContainerUtil.createConcurrentIntObjectMap();
    final Set<VirtualFile> toProcess = Collections.synchronizedSet(files);
    indicator.setIndeterminate(false);
    ProgressIndicatorUtils.forceWriteActionPriority(indicator, (Disposable) indicator);
    long start = System.currentTimeMillis();
    Processor<VirtualFile> processor = file -> {
        double fraction = 1 - toProcess.size() * 1.0 / totalSize;
        indicator.setFraction(fraction);
        try {
            if (!file.isDirectory() && toResolve(file, myProject)) {
                int fileId = getAbsId(file);
                int i = totalSize - toProcess.size();
                indicator.setText(i + "/" + totalSize + ": Resolving " + file.getPresentableUrl());
                int[] forwardIds = processFile(file, fileId, indicator);
                if (forwardIds == null) {
                    return false;
                }
                fileToForwardIds.put(fileId, forwardIds);
            }
            toProcess.remove(file);
            return true;
        } catch (RuntimeException e) {
            indicator.checkCanceled();
        }
        return true;
    };
    boolean success = true;
    try {
        success = processFilesConcurrently(files, indicator, processor);
    } finally {
        this.resolvedInPreviousBatch = toProcess.isEmpty() ? 0 : totalSize - toProcess.size();
        queue(toProcess, "re-added after fail. success=" + success);
        storeIds(fileToForwardIds);
        long end = System.currentTimeMillis();
        log("Resolved batch of " + (totalSize - toProcess.size()) + " from " + totalSize + " files in " + ((end - start) / 1000) + "sec. (Gap: " + storage.gap + ")");
        synchronized (filesToResolve) {
            upToDate = filesToResolve.isEmpty();
            log("upToDate = " + upToDate);
            if (upToDate) {
                for (Listener listener : myListeners) {
                    listener.allFilesResolved();
                }
            }
        }
    }
}
Also used : NewVirtualFile(com.intellij.openapi.vfs.newvfs.NewVirtualFile) PowerSaveMode(com.intellij.ide.PowerSaveMode) ApplicationEx(com.intellij.openapi.application.ex.ApplicationEx) Future(java.util.concurrent.Future) Task(com.intellij.openapi.progress.Task) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Disposer(com.intellij.openapi.util.Disposer) FileUtil(com.intellij.openapi.util.io.FileUtil) Logger(com.intellij.openapi.diagnostic.Logger) Module(com.intellij.openapi.module.Module) VFileEvent(com.intellij.openapi.vfs.newvfs.events.VFileEvent) DateFormat(java.text.DateFormat) ProgressManager(com.intellij.openapi.progress.ProgressManager) com.intellij.openapi.project(com.intellij.openapi.project) JavaSourceRootType(org.jetbrains.jps.model.java.JavaSourceRootType) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PersistentFS(com.intellij.openapi.vfs.newvfs.persistent.PersistentFS) Nullable(org.jetbrains.annotations.Nullable) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) PsiUtilCore(com.intellij.psi.util.PsiUtilCore) Function(com.intellij.util.Function) Processor(com.intellij.util.Processor) ConcurrentBitSet(com.intellij.util.containers.ConcurrentBitSet) gnu.trove(gnu.trove) com.intellij.psi(com.intellij.psi) NotNull(org.jetbrains.annotations.NotNull) ProgressIndicatorBase(com.intellij.openapi.progress.util.ProgressIndicatorBase) java.util(java.util) ArrayUtil(com.intellij.util.ArrayUtil) PathManager(com.intellij.openapi.application.PathManager) ApplicationUtil(com.intellij.openapi.application.ex.ApplicationUtil) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) FutureTask(java.util.concurrent.FutureTask) ProgressManagerImpl(com.intellij.openapi.progress.impl.ProgressManagerImpl) Callable(java.util.concurrent.Callable) ProgressIndicatorUtils(com.intellij.openapi.progress.util.ProgressIndicatorUtils) ContainerUtil(com.intellij.util.containers.ContainerUtil) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) FSRecords(com.intellij.openapi.vfs.newvfs.persistent.FSRecords) StartupManager(com.intellij.openapi.startup.StartupManager) BackgroundableProcessIndicator(com.intellij.openapi.progress.impl.BackgroundableProcessIndicator) StdFileTypes(com.intellij.openapi.fileTypes.StdFileTypes) NewVirtualFile(com.intellij.openapi.vfs.newvfs.NewVirtualFile) StringUtil(com.intellij.openapi.util.text.StringUtil) FileWriter(java.io.FileWriter) IOException(java.io.IOException) ConcurrentIntObjectMap(com.intellij.util.containers.ConcurrentIntObjectMap) Disposable(com.intellij.openapi.Disposable) File(java.io.File) AtomicLong(java.util.concurrent.atomic.AtomicLong) ExceptionUtil(com.intellij.util.ExceptionUtil) ApplicationAdapter(com.intellij.openapi.application.ApplicationAdapter) BulkFileListener(com.intellij.openapi.vfs.newvfs.BulkFileListener) com.intellij.openapi.vfs(com.intellij.openapi.vfs) MessageBus(com.intellij.util.messages.MessageBus) HeavyProcessLatch(com.intellij.util.io.storage.HeavyProcessLatch) EmptyRunnable(com.intellij.openapi.util.EmptyRunnable) BulkFileListener(com.intellij.openapi.vfs.newvfs.BulkFileListener)

Aggregations

PowerSaveMode (com.intellij.ide.PowerSaveMode)1 Disposable (com.intellij.openapi.Disposable)1 ApplicationAdapter (com.intellij.openapi.application.ApplicationAdapter)1 PathManager (com.intellij.openapi.application.PathManager)1 ApplicationEx (com.intellij.openapi.application.ex.ApplicationEx)1 ApplicationUtil (com.intellij.openapi.application.ex.ApplicationUtil)1 Logger (com.intellij.openapi.diagnostic.Logger)1 StdFileTypes (com.intellij.openapi.fileTypes.StdFileTypes)1 Module (com.intellij.openapi.module.Module)1 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 ProgressManager (com.intellij.openapi.progress.ProgressManager)1 Task (com.intellij.openapi.progress.Task)1 BackgroundableProcessIndicator (com.intellij.openapi.progress.impl.BackgroundableProcessIndicator)1 ProgressManagerImpl (com.intellij.openapi.progress.impl.ProgressManagerImpl)1 ProgressIndicatorBase (com.intellij.openapi.progress.util.ProgressIndicatorBase)1 ProgressIndicatorUtils (com.intellij.openapi.progress.util.ProgressIndicatorUtils)1 com.intellij.openapi.project (com.intellij.openapi.project)1 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)1 StartupManager (com.intellij.openapi.startup.StartupManager)1