Search in sources :

Example 1 with ProgressIndicatorBase

use of com.intellij.openapi.progress.util.ProgressIndicatorBase in project kotlin by JetBrains.

the class LongRunningReadTask method run.

/** Should be executed in GUI thread */
public final void run() {
    ApplicationManager.getApplication().assertIsDispatchThread();
    if (currentState != State.INITIALIZED) {
        throw new IllegalStateException("Task should be initialized with init() method");
    }
    if (requestInfo == null) {
        throw new IllegalStateException("Invalid request for task beginning");
    }
    currentState = State.STARTED;
    beforeRun();
    progressIndicator = new ProgressIndicatorBase();
    final RequestInfo requestInfoCopy = cloneRequestInfo(requestInfo);
    ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {

        @Override
        public void run() {
            runWithWriteActionPriority(progressIndicator, new Runnable() {

                @Override
                public void run() {
                    ResultData resultData = null;
                    try {
                        resultData = processRequest(requestInfoCopy);
                    } finally {
                        // Back to GUI thread for submitting result
                        final ResultData finalResult = resultData;
                        ApplicationManager.getApplication().invokeLater(new Runnable() {

                            @Override
                            public void run() {
                                resultReady(finalResult);
                            }
                        });
                    }
                }
            });
        }
    });
}
Also used : ProgressIndicatorBase(com.intellij.openapi.progress.util.ProgressIndicatorBase)

Example 2 with ProgressIndicatorBase

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

the class EditorNotificationsImpl method updateNotifications.

@Override
public void updateNotifications(@NotNull final VirtualFile file) {
    UIUtil.invokeLaterIfNeeded(() -> {
        ProgressIndicator indicator = getCurrentProgress(file);
        if (indicator != null) {
            indicator.cancel();
        }
        file.putUserData(CURRENT_UPDATES, null);
        if (myProject.isDisposed() || !file.isValid()) {
            return;
        }
        indicator = new ProgressIndicatorBase();
        final ReadTask task = createTask(indicator, file);
        if (task == null)
            return;
        file.putUserData(CURRENT_UPDATES, new WeakReference<>(indicator));
        if (ApplicationManager.getApplication().isUnitTestMode()) {
            ReadTask.Continuation continuation = task.performInReadAction(indicator);
            if (continuation != null) {
                continuation.getAction().run();
            }
        } else {
            ProgressIndicatorUtils.scheduleWithWriteActionPriority(indicator, ourExecutor, task);
        }
    });
}
Also used : ProgressIndicatorBase(com.intellij.openapi.progress.util.ProgressIndicatorBase) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) ReadTask(com.intellij.openapi.progress.util.ReadTask)

Example 3 with ProgressIndicatorBase

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

the class ProgressIndicatorTest method testThereIsNoDelayBetweenIndicatorCancelAndProgressManagerCheckCanceled.

public void testThereIsNoDelayBetweenIndicatorCancelAndProgressManagerCheckCanceled() throws Throwable {
    for (int i = 0; i < 100; i++) {
        final ProgressIndicatorBase indicator = new ProgressIndicatorBase();
        List<Thread> threads = ContainerUtil.map(Collections.nCopies(10, ""), s -> new Thread(() -> ProgressManager.getInstance().executeProcessUnderProgress(() -> {
            try {
                Thread.sleep(new Random().nextInt(100));
                indicator.cancel();
                ProgressManager.checkCanceled();
                fail("checkCanceled() must know about canceled indicator even from different thread");
            } catch (ProcessCanceledException ignored) {
            } catch (Throwable e) {
                exception = e;
            }
        }, indicator), "indicator test"));
        threads.forEach(Thread::start);
        ConcurrencyUtil.joinAll(threads);
    }
    if (exception != null)
        throw exception;
}
Also used : ProgressIndicatorBase(com.intellij.openapi.progress.util.ProgressIndicatorBase) Random(java.util.Random)

Example 4 with ProgressIndicatorBase

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

the class ProgressIndicatorTest method testNestedIndicatorsAreCanceledRight.

public void testNestedIndicatorsAreCanceledRight() {
    checkCanceledCalled = false;
    ProgressManager.getInstance().executeProcessUnderProgress(() -> {
        assertFalse(CoreProgressManager.threadsUnderCanceledIndicator.contains(Thread.currentThread()));
        ProgressIndicator indicator = ProgressIndicatorProvider.getGlobalProgressIndicator();
        assertTrue(indicator != null && !indicator.isCanceled());
        indicator.cancel();
        assertTrue(CoreProgressManager.threadsUnderCanceledIndicator.contains(Thread.currentThread()));
        assertTrue(indicator.isCanceled());
        final ProgressIndicatorEx nested = new ProgressIndicatorBase();
        nested.addStateDelegate(new ProgressIndicatorStub() {

            @Override
            public void checkCanceled() throws ProcessCanceledException {
                checkCanceledCalled = true;
                throw new RuntimeException("must not call checkCanceled()");
            }
        });
        ProgressManager.getInstance().executeProcessUnderProgress(() -> {
            assertFalse(CoreProgressManager.threadsUnderCanceledIndicator.contains(Thread.currentThread()));
            ProgressIndicator indicator2 = ProgressIndicatorProvider.getGlobalProgressIndicator();
            assertTrue(indicator2 != null && !indicator2.isCanceled());
            assertSame(indicator2, nested);
            ProgressManager.checkCanceled();
        }, nested);
        ProgressIndicator indicator3 = ProgressIndicatorProvider.getGlobalProgressIndicator();
        assertSame(indicator, indicator3);
        assertTrue(CoreProgressManager.threadsUnderCanceledIndicator.contains(Thread.currentThread()));
    }, new EmptyProgressIndicator());
    assertFalse(checkCanceledCalled);
}
Also used : ProgressIndicatorBase(com.intellij.openapi.progress.util.ProgressIndicatorBase) DelegatingProgressIndicator(com.intellij.ide.util.DelegatingProgressIndicator) BombedProgressIndicator(com.intellij.testFramework.BombedProgressIndicator) DaemonProgressIndicator(com.intellij.codeInsight.daemon.impl.DaemonProgressIndicator) ProgressIndicatorEx(com.intellij.openapi.wm.ex.ProgressIndicatorEx)

Example 5 with ProgressIndicatorBase

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

the class ProgressIndicatorTest method testProgressManagerCheckCanceledWorksRightAfterIndicatorBeenCanceled.

public void testProgressManagerCheckCanceledWorksRightAfterIndicatorBeenCanceled() {
    for (int i = 0; i < 1000; i++) {
        final ProgressIndicatorBase indicator = new ProgressIndicatorBase();
        ProgressManager.getInstance().runProcess(() -> {
            ProgressManager.checkCanceled();
            try {
                indicator.cancel();
                ProgressManager.checkCanceled();
                fail("checkCanceled() must have caught just canceled indicator");
            } catch (ProcessCanceledException ignored) {
            }
        }, indicator);
    }
}
Also used : ProgressIndicatorBase(com.intellij.openapi.progress.util.ProgressIndicatorBase)

Aggregations

ProgressIndicatorBase (com.intellij.openapi.progress.util.ProgressIndicatorBase)25 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)8 DaemonProgressIndicator (com.intellij.codeInsight.daemon.impl.DaemonProgressIndicator)6 DelegatingProgressIndicator (com.intellij.ide.util.DelegatingProgressIndicator)6 ReadTask (com.intellij.openapi.progress.util.ReadTask)6 BombedProgressIndicator (com.intellij.testFramework.BombedProgressIndicator)6 NotNull (org.jetbrains.annotations.NotNull)5 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 ApplicationManager (com.intellij.openapi.application.ApplicationManager)3 ModalityState (com.intellij.openapi.application.ModalityState)3 Logger (com.intellij.openapi.diagnostic.Logger)3 Project (com.intellij.openapi.project.Project)3 Ref (com.intellij.openapi.util.Ref)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 CommonBundle (com.intellij.CommonBundle)2 com.intellij.find (com.intellij.find)2 ShowUsagesAction (com.intellij.find.actions.ShowUsagesAction)2 Disposable (com.intellij.openapi.Disposable)2 com.intellij.openapi.actionSystem (com.intellij.openapi.actionSystem)2