Search in sources :

Example 1 with ShutDownTracker

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

the class DumbServiceImpl method runBackgroundProcess.

private void runBackgroundProcess(@NotNull final ProgressIndicator visibleIndicator) {
    if (!myState.compareAndSet(State.SCHEDULED_TASKS, State.RUNNING_DUMB_TASKS))
        return;
    final ShutDownTracker shutdownTracker = ShutDownTracker.getInstance();
    final Thread self = Thread.currentThread();
    try {
        shutdownTracker.registerStopperThread(self);
        if (visibleIndicator instanceof ProgressIndicatorEx) {
            ((ProgressIndicatorEx) visibleIndicator).addStateDelegate(new AppIconProgress());
        }
        DumbModeTask task = null;
        while (true) {
            Pair<DumbModeTask, ProgressIndicatorEx> pair = getNextTask(task, visibleIndicator);
            if (pair == null)
                break;
            task = pair.first;
            ProgressIndicatorEx taskIndicator = pair.second;
            if (visibleIndicator instanceof ProgressIndicatorEx) {
                taskIndicator.addStateDelegate(new AbstractProgressIndicatorExBase() {

                    @Override
                    protected void delegateProgressChange(@NotNull IndicatorAction action) {
                        super.delegateProgressChange(action);
                        action.execute((ProgressIndicatorEx) visibleIndicator);
                    }
                });
            }
            try (AccessToken ignored = HeavyProcessLatch.INSTANCE.processStarted("Performing indexing tasks")) {
                runSingleTask(task, taskIndicator);
            }
        }
    } catch (Throwable unexpected) {
        LOG.error(unexpected);
    } finally {
        shutdownTracker.unregisterStopperThread(self);
    }
}
Also used : ShutDownTracker(com.intellij.openapi.util.ShutDownTracker) AbstractProgressIndicatorExBase(com.intellij.openapi.progress.util.AbstractProgressIndicatorExBase) ProgressIndicatorEx(com.intellij.openapi.wm.ex.ProgressIndicatorEx)

Aggregations

AbstractProgressIndicatorExBase (com.intellij.openapi.progress.util.AbstractProgressIndicatorExBase)1 ShutDownTracker (com.intellij.openapi.util.ShutDownTracker)1 ProgressIndicatorEx (com.intellij.openapi.wm.ex.ProgressIndicatorEx)1