From 64ea8411ed1149e41bbf6768b2b8b08b1316ab30 Mon Sep 17 00:00:00 2001 From: Eugene Zhuravlev Date: Tue, 10 Jul 2012 19:14:32 +0200 Subject: [PATCH] more robust way of clearing dumb mode flag --- .../openapi/project/DumbServiceImpl.java | 62 ++++++++++--------- 1 file changed, 34 insertions(+), 28 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/project/DumbServiceImpl.java b/platform/platform-impl/src/com/intellij/openapi/project/DumbServiceImpl.java index 138cf398fe7a..76797c6f7201 100644 --- a/platform/platform-impl/src/com/intellij/openapi/project/DumbServiceImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/project/DumbServiceImpl.java @@ -45,7 +45,8 @@ import org.jetbrains.annotations.TestOnly; import javax.swing.*; import java.util.ArrayList; import java.util.Collection; -import java.util.concurrent.ArrayBlockingQueue; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.TimeUnit; public class DumbServiceImpl extends DumbService { @@ -285,7 +286,7 @@ public class DumbServiceImpl extends DumbService { ProgressManager.getInstance().run(new Task.Backgroundable(myProject, IdeBundle.message("progress.indexing"), false) { - private final ArrayBlockingQueue> myActionQueue = new ArrayBlockingQueue>(1); + private final BlockingQueue> myActionQueue = new LinkedBlockingQueue>(); // /*no override for interfaces in jdk 1.5 */ @Override public void run(@NotNull final ProgressIndicator indicator) { @@ -361,45 +362,50 @@ public class DumbServiceImpl extends DumbService { myProcessedItems += count; UIUtil.invokeLaterIfNeeded(new DumbAwareRunnable() { public void run() { - if (myUpdatesQueue.isEmpty()) { - // really terminate the task - myActionQueue.offer(NULL_ACTION); - updateFinished(); + IndexUpdateRunnable nextUpdateRunnable = null; + try { + nextUpdateRunnable = myUpdatesQueue.pullFirst(); + if (nextUpdateRunnable == null) { + // really terminate the task + myActionQueue.offer(NULL_ACTION); + } + else { + //run next dumb action + // run next action under already existing progress indicator + myActionQueue.offer(new Ref(nextUpdateRunnable.myAction)); + } } - else { - //run next dumb action - final IndexUpdateRunnable nextUpdateRunnable = myUpdatesQueue.pullFirst(); - // run next action under already existing progress indicator - if (!myActionQueue.offer(new Ref(nextUpdateRunnable.myAction))) { - LOG.error("Action queue rejected next updateRunnable!"); - nextUpdateRunnable.run(); + catch (Throwable e) { + myActionQueue.offer(NULL_ACTION); + LOG.info(e); + } + finally { + if (nextUpdateRunnable == null) { + updateFinished(); } } } }); // try to obtain the next action or terminate if no actions left - try { - Ref ref; - do { + Ref ref = null; + do { + try { ref = myActionQueue.poll(500, TimeUnit.MILLISECONDS); - updateRunner = ref != null? ref.get() : null; - if (myProject.isDisposed()) { - // just terminate the progress task - break; - } } - while (ref == null); - } - catch (InterruptedException ignored) { - LOG.info(ignored); - break; + catch (InterruptedException e) { + LOG.info(e); + } + updateRunner = ref != null? ref.get() : null; + if (myProject.isDisposed()) { + // just terminate the progress task + break; + } } + while (ref == null); } } while (updateRunner != null); - // make it impossible to add actions to the queue anymore - myActionQueue.offer(NULL_ACTION); } });