mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[jeka] cleaner code and debug info in the dumb mode area
This commit is contained in:
@@ -157,24 +157,7 @@ class CacheUpdateRunner {
|
||||
Runnable process = new MyRunnable(innerIndicator, queue, ref, progressUpdater, processInReadAction, application);
|
||||
futures[i] = ApplicationManager.getApplication().executeOnPooledThread(getProcessWrapper(process));
|
||||
}
|
||||
try {
|
||||
for (Future<?> future : futures) {
|
||||
future.get();
|
||||
}
|
||||
|
||||
boolean allFinished = true;
|
||||
for (Ref ref : finishedRefs) {
|
||||
if (!(Boolean)ref.get()) {
|
||||
allFinished = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
isFinished.set(allFinished);
|
||||
|
||||
}
|
||||
catch (Throwable throwable) {
|
||||
LOG.error(throwable);
|
||||
}
|
||||
isFinished.set(waitForAll(finishedRefs, futures));
|
||||
}
|
||||
}
|
||||
finally {
|
||||
@@ -184,6 +167,28 @@ class CacheUpdateRunner {
|
||||
return isFinished.get();
|
||||
}
|
||||
|
||||
private static boolean waitForAll(Ref[] finishedRefs, Future<?>[] futures) {
|
||||
try {
|
||||
for (Future<?> future : futures) {
|
||||
future.get();
|
||||
}
|
||||
|
||||
boolean allFinished = true;
|
||||
for (Ref ref : finishedRefs) {
|
||||
if (!(Boolean)ref.get()) {
|
||||
allFinished = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return allFinished;
|
||||
|
||||
}
|
||||
catch (Throwable throwable) {
|
||||
LOG.error(throwable);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private class MyRunnable implements Runnable {
|
||||
private final ProgressIndicatorBase myInnerIndicator;
|
||||
private final FileContentQueue myQueue;
|
||||
@@ -210,7 +215,7 @@ class CacheUpdateRunner {
|
||||
if (myProject.isDisposed()) return;
|
||||
if (myInnerIndicator.isCanceled()) return;
|
||||
|
||||
final FileContent fileContent = myQueue.take();
|
||||
final FileContent fileContent = myQueue.take(myInnerIndicator);
|
||||
if (fileContent == null) {
|
||||
myFinished.set(Boolean.TRUE);
|
||||
return;
|
||||
|
||||
@@ -358,30 +358,12 @@ public class DumbServiceImpl extends DumbService {
|
||||
}
|
||||
finally {
|
||||
myProcessedItems += count;
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("Scheduling checkNextUpdateFromQueue");
|
||||
}
|
||||
UIUtil.invokeLaterIfNeeded(new DumbAwareRunnable() {
|
||||
public void run() {
|
||||
IndexUpdateRunnable nextUpdateRunnable = null;
|
||||
try {
|
||||
nextUpdateRunnable = myUpdatesQueue.isEmpty()? null : 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<CacheUpdateRunner>(nextUpdateRunnable.myAction));
|
||||
}
|
||||
}
|
||||
catch (Throwable e) {
|
||||
myActionQueue.offer(NULL_ACTION);
|
||||
LOG.info(e);
|
||||
}
|
||||
finally {
|
||||
if (nextUpdateRunnable == null) {
|
||||
updateFinished();
|
||||
}
|
||||
}
|
||||
checkNextUpdateFromQueue();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -406,6 +388,33 @@ public class DumbServiceImpl extends DumbService {
|
||||
while (updateRunner != null);
|
||||
}
|
||||
|
||||
private void checkNextUpdateFromQueue() {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("Inside checkNextUpdateFromQueue");
|
||||
}
|
||||
IndexUpdateRunnable nextUpdateRunnable = null;
|
||||
try {
|
||||
nextUpdateRunnable = myUpdatesQueue.isEmpty()? null : 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<CacheUpdateRunner>(nextUpdateRunnable.myAction));
|
||||
}
|
||||
}
|
||||
catch (Throwable e) {
|
||||
myActionQueue.offer(NULL_ACTION);
|
||||
LOG.info(e);
|
||||
}
|
||||
finally {
|
||||
if (nextUpdateRunnable == null) {
|
||||
updateFinished();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.progress.ProcessCanceledException;
|
||||
import com.intellij.openapi.progress.ProgressIndicator;
|
||||
import com.intellij.openapi.progress.ProgressManager;
|
||||
import com.intellij.openapi.vfs.InvalidVirtualFileAccessException;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -51,7 +50,7 @@ public class FileContentQueue {
|
||||
private final Queue<FileContent> myPushbackBuffer = new ArrayDeque<FileContent>();
|
||||
private volatile boolean myContentLoadingThreadTerminated = false;
|
||||
|
||||
public void queue(final Collection<VirtualFile> files, @Nullable final ProgressIndicator indicator) {
|
||||
public void queue(final Collection<VirtualFile> files, @NotNull final ProgressIndicator indicator) {
|
||||
final Runnable contentLoadingRunnable = new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
@@ -59,7 +58,7 @@ public class FileContentQueue {
|
||||
if (indicator != null) {
|
||||
indicator.checkCanceled();
|
||||
}
|
||||
addLast(file);
|
||||
addLast(file, indicator);
|
||||
}
|
||||
|
||||
// put end-of-queue marker only if not canceled
|
||||
@@ -85,11 +84,11 @@ public class FileContentQueue {
|
||||
ApplicationManager.getApplication().executeOnPooledThread(contentLoadingRunnable);
|
||||
}
|
||||
|
||||
private void addLast(VirtualFile file) throws InterruptedException {
|
||||
private void addLast(VirtualFile file, @NotNull final ProgressIndicator indicator) throws InterruptedException {
|
||||
FileContent content = new FileContent(file);
|
||||
|
||||
if (file.isValid() && !file.isDirectory()) {
|
||||
if (!doLoadContent(content)) {
|
||||
if (!doLoadContent(content, indicator)) {
|
||||
content.setEmptyContent();
|
||||
}
|
||||
}
|
||||
@@ -100,17 +99,14 @@ public class FileContentQueue {
|
||||
myQueue.put(content);
|
||||
}
|
||||
|
||||
private boolean doLoadContent(final FileContent content) throws InterruptedException {
|
||||
final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
|
||||
private boolean doLoadContent(final FileContent content, @NotNull final ProgressIndicator indicator) throws InterruptedException {
|
||||
final long contentLength = content.getLength();
|
||||
|
||||
boolean counterUpdated = false;
|
||||
try {
|
||||
synchronized (this) {
|
||||
while (myTotalSize > SIZE_THRESHOLD) {
|
||||
if (indicator != null) {
|
||||
indicator.checkCanceled();
|
||||
}
|
||||
indicator.checkCanceled();
|
||||
wait(300L);
|
||||
}
|
||||
myTotalSize += contentLength;
|
||||
@@ -144,21 +140,17 @@ public class FileContentQueue {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public FileContent take() {
|
||||
|
||||
public FileContent take(@NotNull ProgressIndicator indicator) {
|
||||
FileContent content = doTake();
|
||||
if (content != null) {
|
||||
final long length = content.getLength();
|
||||
while (true) {
|
||||
final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
|
||||
if (indicator != null) {
|
||||
try {
|
||||
indicator.checkCanceled();
|
||||
}
|
||||
catch (ProcessCanceledException e) {
|
||||
pushback(content);
|
||||
throw e;
|
||||
}
|
||||
try {
|
||||
indicator.checkCanceled();
|
||||
}
|
||||
catch (ProcessCanceledException e) {
|
||||
pushback(content);
|
||||
throw e;
|
||||
}
|
||||
synchronized (this) {
|
||||
boolean requestingLargeSize = length > LARGE_SIZE_REQUEST_THRESHOLD;
|
||||
|
||||
Reference in New Issue
Block a user