Search in sources :

Example 1 with StandardProgressIndicatorBase

use of com.intellij.openapi.progress.util.StandardProgressIndicatorBase in project intellij-community by JetBrains.

the class JobLauncherImpl method invokeConcurrentlyUnderProgress.

@Override
public <T> boolean invokeConcurrentlyUnderProgress(@NotNull final List<T> things, ProgressIndicator progress, boolean runInReadAction, boolean failFastOnAcquireReadAction, @NotNull final Processor<? super T> thingProcessor) throws ProcessCanceledException {
    // supply our own indicator even if we haven't given one - to support cancellation
    // use StandardProgressIndicator by default to avoid assertion in SensitiveProgressWrapper() ctr later
    final ProgressIndicator wrapper = progress == null ? new StandardProgressIndicatorBase() : new SensitiveProgressWrapper(progress);
    Boolean result = processImmediatelyIfTooFew(things, wrapper, runInReadAction, thingProcessor);
    if (result != null)
        return result.booleanValue();
    HeavyProcessLatch.INSTANCE.stopThreadPrioritizing();
    List<ApplierCompleter<T>> failedSubTasks = Collections.synchronizedList(new ArrayList<>());
    ApplierCompleter<T> applier = new ApplierCompleter<>(null, runInReadAction, failFastOnAcquireReadAction, wrapper, things, thingProcessor, 0, things.size(), failedSubTasks, null);
    try {
        ForkJoinPool.commonPool().invoke(applier);
        if (applier.throwable != null)
            throw applier.throwable;
    } catch (ApplierCompleter.ComputationAbortedException e) {
        // one of the processors returned false
        return false;
    } catch (ApplicationUtil.CannotRunReadActionException e) {
        // failFastOnAcquireReadAction==true and one of the processors called runReadAction() during the pending write action
        throw e;
    } catch (ProcessCanceledException e) {
        // then task2 calls checkCancel() and get here
        return false;
    } catch (RuntimeException | Error e) {
        throw e;
    } catch (Throwable e) {
        throw new RuntimeException(e);
    }
    assert applier.isDone();
    return applier.completeTaskWhichFailToAcquireReadAction();
}
Also used : ApplicationUtil(com.intellij.openapi.application.ex.ApplicationUtil) StandardProgressIndicatorBase(com.intellij.openapi.progress.util.StandardProgressIndicatorBase) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 2 with StandardProgressIndicatorBase

use of com.intellij.openapi.progress.util.StandardProgressIndicatorBase in project intellij-community by JetBrains.

the class ClassInheritorsTest method testStressInPresenceOfPCEs.

public void testStressInPresenceOfPCEs() throws IOException {
    // no write action can go through while we test
    ApplicationManager.getApplication().assertIsDispatchThread();
    int N = 1000;
    PsiJavaFile file0 = (PsiJavaFile) myFixture.addFileToProject("C0.java", "class C0 { }");
    for (int i = 1; i < N; i++) {
        // 10 inheritors
        int extI = i - 1 - (i - 1) % 10;
        myFixture.addClass("class C" + i + " extends C" + extI + " { }");
    }
    PsiClass class0 = file0.getClasses()[0];
    int delayToCancel = 100;
    for (int i = 0; i < 1000; i++) {
        //System.out.println("i = " + i+ "; delayToCancel="+delayToCancel);
        StandardProgressIndicatorBase progress = new StandardProgressIndicatorBase();
        JobScheduler.getScheduler().schedule(progress::cancel, delayToCancel, TimeUnit.MILLISECONDS);
        try {
            Collections.nCopies(Runtime.getRuntime().availableProcessors(), "").stream().parallel().forEach(__ -> {
                Collection<PsiClass> inheritors = Collections.synchronizedSet(new THashSet<>());
                ProgressManager.getInstance().executeProcessUnderProgress(() -> {
                    boolean success = ClassInheritorsSearch.search(class0).forEach(new CommonProcessors.CollectProcessor<>(inheritors));
                    if (N - 1 != inheritors.size() || !success) {
                        assertEquals(N - 1, inheritors.size());
                    }
                }, progress);
            });
            myFixture.getPsiManager().dropResolveCaches();
            //System.out.println("Iterated all");
            delayToCancel--;
        } catch (ProcessCanceledException e) {
            //System.out.println("e = " + e);
            delayToCancel++;
        }
    }
}
Also used : StandardProgressIndicatorBase(com.intellij.openapi.progress.util.StandardProgressIndicatorBase) PsiClass(com.intellij.psi.PsiClass) PsiJavaFile(com.intellij.psi.PsiJavaFile) CommonProcessors(com.intellij.util.CommonProcessors) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Aggregations

ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)2 StandardProgressIndicatorBase (com.intellij.openapi.progress.util.StandardProgressIndicatorBase)2 ApplicationUtil (com.intellij.openapi.application.ex.ApplicationUtil)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 PsiClass (com.intellij.psi.PsiClass)1 PsiJavaFile (com.intellij.psi.PsiJavaFile)1 CommonProcessors (com.intellij.util.CommonProcessors)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1