From 1c0b44f00ba57f5a7891ee1a278692a7cc1f205b Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 26 Oct 2009 16:58:42 +0300 Subject: [PATCH] IDEADEV-40851 (Version control: ApplicationPooledThreadControlledAlarms progress bar is shown endlessly on project closing) --- .../lifecycle/ControlledAlarmFactory.java | 16 ++++++++++++++++ .../vcs/changes/ChangesOnServerTracker.java | 3 ++- .../openapi/vcs/changes/ControlledCycle.java | 12 ++++++++---- .../vcs/changes/LazyRefreshingSelfQueue.java | 6 +++++- .../vcs/changes/RemoteRevisionsCache.java | 10 +++++----- .../vcs/changes/RemoteRevisionsNumbersCache.java | 10 ++++++++-- .../vcs/changes/RemoteRevisionsStateCache.java | 4 +++- 7 files changed, 47 insertions(+), 14 deletions(-) diff --git a/platform/vcs-impl/src/com/intellij/lifecycle/ControlledAlarmFactory.java b/platform/vcs-impl/src/com/intellij/lifecycle/ControlledAlarmFactory.java index 42a03f53c586..49ca1512b13a 100644 --- a/platform/vcs-impl/src/com/intellij/lifecycle/ControlledAlarmFactory.java +++ b/platform/vcs-impl/src/com/intellij/lifecycle/ControlledAlarmFactory.java @@ -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(); + } + }; + } } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangesOnServerTracker.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangesOnServerTracker.java index 0442150b4cd2..3690ba3ee9cd 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangesOnServerTracker.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangesOnServerTracker.java @@ -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 paths); boolean isUpToDate(final Change change); - boolean updateStep(); + boolean updateStep(final AtomicSectionsAware atomicSectionsAware); } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ControlledCycle.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ControlledCycle.java index 7f5d059a4488..89438d7bd134 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ControlledCycle.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ControlledCycle.java @@ -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 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); + } } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/LazyRefreshingSelfQueue.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/LazyRefreshingSelfQueue.java index b18ef6f89fb6..2d4cf89fa00d 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/LazyRefreshingSelfQueue.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/LazyRefreshingSelfQueue.java @@ -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 { } // called by outside timer or something - public void updateStep() { + public void updateStep(@NotNull final ProgressIndicator pi) { final List dirty = new LinkedList(); final long startTime = System.currentTimeMillis() - myUpdateInterval; @@ -97,6 +99,7 @@ public class LazyRefreshingSelfQueue { synchronized (myLock) { // get absolute while (! myQueue.isEmpty()) { + pi.checkCanceled(); final Pair pair = myQueue.get(0); if (pair.getFirst() == null) { dirty.add(myQueue.removeFirst().getSecond()); @@ -121,6 +124,7 @@ public class LazyRefreshingSelfQueue { LOG.debug("found something to update: " + (! dirty.isEmpty())); for (T t : dirty) { + ProgressManager.checkCanceled(); myUpdater.consume(t); synchronized (myLock) { if (myInProgress.remove(t)) { diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/RemoteRevisionsCache.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/RemoteRevisionsCache.java index 2912da950009..b0742e752e84 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/RemoteRevisionsCache.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/RemoteRevisionsCache.java @@ -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 } }); updateKinds(); - myControlledCycle = new ControlledCycle(project, new Getter() { - 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(); } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/RemoteRevisionsNumbersCache.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/RemoteRevisionsNumbersCache.java index b8baeebc929f..fd1e5d9c90aa 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/RemoteRevisionsNumbersCache.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/RemoteRevisionsNumbersCache.java @@ -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> list = new ArrayList>(); mySomethingChanged = false; synchronized (myLock) { list.addAll(myRefreshingQueues.values()); } LOG.debug("queues refresh started, queues: " + list.size()); + final ProgressIndicator pi = ControlledAlarmFactory.createProgressIndicator(atomicSectionsAware); for (LazyRefreshingSelfQueue 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(); diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/RemoteRevisionsStateCache.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/RemoteRevisionsStateCache.java index eb50f00bbbb0..8624beb02651 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/RemoteRevisionsStateCache.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/RemoteRevisionsStateCache.java @@ -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 dirty = new MultiMap(); final long oldPoint = System.currentTimeMillis() - DISCRETE; @@ -127,6 +128,7 @@ public class RemoteRevisionsStateCache implements ChangesOnServerTracker { final Map> results = new HashMap>(); for (VcsRoot vcsRoot : dirty.keySet()) { + atomicSectionsAware.checkShouldExit(); final TreeDiffProvider provider = vcsRoot.vcs.getTreeDiffProvider(); if (provider == null) continue;