IDEADEV-40851 (Version control: ApplicationPooledThreadControlledAlarms progress bar is shown endlessly on project closing)

This commit is contained in:
unknown
2009-10-26 16:58:42 +03:00
parent a74f72258c
commit 1c0b44f00b
7 changed files with 47 additions and 14 deletions
@@ -18,6 +18,8 @@ package com.intellij.lifecycle;
import com.intellij.openapi.application.Application;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.progress.EmptyProgressIndicator;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull;
@@ -131,4 +133,18 @@ public class ControlledAlarmFactory {
return false;
}
}
public static ProgressIndicator createProgressIndicator(final AtomicSectionsAware atomicSectionsAware) {
return new EmptyProgressIndicator() {
@Override
public boolean isCanceled() {
return atomicSectionsAware.shouldExitAsap();
}
@Override
public void checkCanceled() {
atomicSectionsAware.checkShouldExit();
}
};
}
}
@@ -15,6 +15,7 @@
*/
package com.intellij.openapi.vcs.changes;
import com.intellij.lifecycle.AtomicSectionsAware;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.vcs.AbstractVcs;
import com.intellij.openapi.vcs.VcsListener;
@@ -25,5 +26,5 @@ public interface ChangesOnServerTracker extends PlusMinus<Pair<String, AbstractV
// todo add vcs parameter???
void invalidate(final Collection<String> paths);
boolean isUpToDate(final Change change);
boolean updateStep();
boolean updateStep(final AtomicSectionsAware atomicSectionsAware);
}
@@ -15,12 +15,12 @@
*/
package com.intellij.openapi.vcs.changes;
import com.intellij.lifecycle.AtomicSectionsAware;
import com.intellij.lifecycle.ControlledAlarmFactory;
import com.intellij.lifecycle.SlowlyClosingAlarm;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.progress.ProcessCanceledException;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Getter;
import com.intellij.util.Alarm;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -36,15 +36,15 @@ public class ControlledCycle implements Runnable {
private final AtomicBoolean myActive;
public ControlledCycle(final Project project, final Getter<Boolean> runnable) {
public ControlledCycle(final Project project, final MyCallback callback) {
myActive = new AtomicBoolean(false);
myRunnable = new Runnable() {
boolean shouldBeContinued = true;
public void run() {
try {
shouldBeContinued = Boolean.TRUE.equals(runnable.get());
shouldBeContinued = callback.call(myControlledAlarm);
} catch (ProcessCanceledException e) {
//
return;
} catch (RuntimeException e) {
LOG.info(e);
}
@@ -74,4 +74,8 @@ public class ControlledCycle implements Runnable {
//
}
}
public interface MyCallback {
boolean call(final AtomicSectionsAware atomicSectionsAware);
}
}
@@ -16,6 +16,8 @@
package com.intellij.openapi.vcs.changes;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.util.Pair;
import com.intellij.util.Consumer;
@@ -76,7 +78,7 @@ public class LazyRefreshingSelfQueue<T> {
}
// called by outside timer or something
public void updateStep() {
public void updateStep(@NotNull final ProgressIndicator pi) {
final List<T> dirty = new LinkedList<T>();
final long startTime = System.currentTimeMillis() - myUpdateInterval;
@@ -97,6 +99,7 @@ public class LazyRefreshingSelfQueue<T> {
synchronized (myLock) {
// get absolute
while (! myQueue.isEmpty()) {
pi.checkCanceled();
final Pair<Long, T> pair = myQueue.get(0);
if (pair.getFirst() == null) {
dirty.add(myQueue.removeFirst().getSecond());
@@ -121,6 +124,7 @@ public class LazyRefreshingSelfQueue<T> {
LOG.debug("found something to update: " + (! dirty.isEmpty()));
for (T t : dirty) {
ProgressManager.checkCanceled();
myUpdater.consume(t);
synchronized (myLock) {
if (myInProgress.remove(t)) {
@@ -15,12 +15,12 @@
*/
package com.intellij.openapi.vcs.changes;
import com.intellij.lifecycle.AtomicSectionsAware;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.Getter;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.vcs.*;
import com.intellij.openapi.vcs.changes.ui.RemoteStatusChangeNodeDecorator;
@@ -72,12 +72,12 @@ public class RemoteRevisionsCache implements PlusMinus<Pair<String, AbstractVcs>
}
});
updateKinds();
myControlledCycle = new ControlledCycle(project, new Getter<Boolean>() {
public Boolean get() {
myControlledCycle = new ControlledCycle(project, new ControlledCycle.MyCallback() {
public boolean call(final AtomicSectionsAware atomicSectionsAware) {
final boolean shouldBeDone = VcsConfiguration.getInstance(myProject).CHECK_LOCALLY_CHANGED_CONFLICTS_IN_BACKGROUND;
if (shouldBeDone) {
boolean somethingChanged = myRemoteRevisionsNumbersCache.updateStep();
somethingChanged |= myRemoteRevisionsStateCache.updateStep();
boolean somethingChanged = myRemoteRevisionsNumbersCache.updateStep(atomicSectionsAware);
somethingChanged |= myRemoteRevisionsStateCache.updateStep(atomicSectionsAware);
if (somethingChanged) {
myProject.getMessageBus().syncPublisher(REMOTE_VERSION_CHANGED).run();
}
@@ -15,7 +15,10 @@
*/
package com.intellij.openapi.vcs.changes;
import com.intellij.lifecycle.AtomicSectionsAware;
import com.intellij.lifecycle.ControlledAlarmFactory;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.util.Pair;
@@ -82,15 +85,17 @@ public class RemoteRevisionsNumbersCache implements ChangesOnServerTracker {
myVcsManager = ProjectLevelVcsManager.getInstance(project);
}
public boolean updateStep() {
public boolean updateStep(final AtomicSectionsAware atomicSectionsAware) {
final List<LazyRefreshingSelfQueue<String>> list = new ArrayList<LazyRefreshingSelfQueue<String>>();
mySomethingChanged = false;
synchronized (myLock) {
list.addAll(myRefreshingQueues.values());
}
LOG.debug("queues refresh started, queues: " + list.size());
final ProgressIndicator pi = ControlledAlarmFactory.createProgressIndicator(atomicSectionsAware);
for (LazyRefreshingSelfQueue<String> queue : list) {
queue.updateStep();
atomicSectionsAware.checkShouldExit();
queue.updateStep(pi);
}
return mySomethingChanged;
}
@@ -210,6 +215,7 @@ public class RemoteRevisionsNumbersCache implements ChangesOnServerTracker {
public void consume(String s) {
LOG.debug("update for: " + s);
//todo check canceled
final VirtualFile vf = myLfs.refreshAndFindFileByIoFile(new File(s));
final ItemLatestState state;
final DiffProvider diffProvider = myVcsRoot.vcs.getDiffProvider();
@@ -15,6 +15,7 @@
*/
package com.intellij.openapi.vcs.changes;
import com.intellij.lifecycle.AtomicSectionsAware;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.vcs.*;
@@ -93,7 +94,7 @@ public class RemoteRevisionsStateCache implements ChangesOnServerTracker {
}
}
public boolean updateStep() {
public boolean updateStep(final AtomicSectionsAware atomicSectionsAware) {
final MultiMap<VcsRoot, String> dirty = new MultiMap<VcsRoot, String>();
final long oldPoint = System.currentTimeMillis() - DISCRETE;
@@ -127,6 +128,7 @@ public class RemoteRevisionsStateCache implements ChangesOnServerTracker {
final Map<String, Pair<Boolean, VcsRoot>> results = new HashMap<String, Pair<Boolean, VcsRoot>>();
for (VcsRoot vcsRoot : dirty.keySet()) {
atomicSectionsAware.checkShouldExit();
final TreeDiffProvider provider = vcsRoot.vcs.getTreeDiffProvider();
if (provider == null) continue;