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);
}
});
}
}
});
}
});
}
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);
}
});
}
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;
}
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);
}
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);
}
}
Aggregations