diff --git a/platform/vcs-api/src/com/intellij/util/continuation/ContinuationContext.java b/platform/vcs-api/src/com/intellij/util/continuation/ContinuationContext.java deleted file mode 100644 index bd18428d3fff..000000000000 --- a/platform/vcs-api/src/com/intellij/util/continuation/ContinuationContext.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2000-2010 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.util.continuation; - -import com.intellij.util.Consumer; -import org.jetbrains.annotations.CalledInAny; - -import java.util.List; - -public interface ContinuationContext { - void suspend(); - - void ping(); - - @CalledInAny - void next(TaskDescriptor... next); - - @CalledInAny - void next(List next); - - @CalledInAny - void cancelEverything(); - - void addExceptionHandler(final Class clazz, final Consumer consumer); - - boolean handleException(final Exception e, boolean cancelEveryThing); -} diff --git a/platform/vcs-api/src/com/intellij/util/continuation/TaskData.java b/platform/vcs-api/src/com/intellij/util/continuation/TaskData.java deleted file mode 100644 index f19d7fb19daf..000000000000 --- a/platform/vcs-api/src/com/intellij/util/continuation/TaskData.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2000-2010 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.util.continuation; - -import org.jetbrains.annotations.NotNull; - -public class TaskData { - private final String myName; - @NotNull - private final Where myWhere; - - public TaskData(String name, @NotNull Where where) { - myName = name; - myWhere = where; - } - - public String getName() { - return myName; - } - - @NotNull - public Where getWhere() { - return myWhere; - } -} diff --git a/platform/vcs-api/src/com/intellij/util/continuation/TaskDescriptor.java b/platform/vcs-api/src/com/intellij/util/continuation/TaskDescriptor.java deleted file mode 100644 index 73db0a79d07d..000000000000 --- a/platform/vcs-api/src/com/intellij/util/continuation/TaskDescriptor.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright 2000-2010 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.util.continuation; - -import com.intellij.openapi.progress.ProcessCanceledException; -import com.intellij.openapi.progress.ProgressIndicator; -import com.intellij.openapi.progress.ProgressManager; -import com.intellij.openapi.progress.Task; -import org.jetbrains.annotations.NotNull; - -public abstract class TaskDescriptor { - private final String myName; - @NotNull private final Where myWhere; - - public TaskDescriptor(final String name, @NotNull final Where where) { - myName = name; - myWhere = where; - } - - public abstract void run(final ContinuationContext context); - - public String getName() { - return myName; - } - - @NotNull - public Where getWhere() { - return myWhere; - } - - public boolean isHaveMagicCure() { - return false; - } - - public void canceled() { - } - - public static TaskDescriptor createForBackgroundableTask(@NotNull final Task.Backgroundable backgroundable) { - return new TaskDescriptor(backgroundable.getTitle(), Where.POOLED) { - @Override - public void run(ContinuationContext context) { - final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator(); - try { - backgroundable.run(indicator); - } catch (ProcessCanceledException e) { - // - } - final boolean canceled = indicator.isCanceled(); - context.next(new TaskDescriptor("", Where.AWT) { - @Override - public void run(ContinuationContext context) { - if (canceled) { - backgroundable.onCancel(); - } else { - backgroundable.onSuccess(); - } - } - }); - } - }; - } -} diff --git a/platform/vcs-api/src/com/intellij/util/continuation/Where.java b/platform/vcs-api/src/com/intellij/util/continuation/Where.java deleted file mode 100644 index 778966506034..000000000000 --- a/platform/vcs-api/src/com/intellij/util/continuation/Where.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright 2000-2010 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.util.continuation; - -public enum Where { - AWT, - POOLED -} diff --git a/platform/vcs-impl/src/com/intellij/util/continuation/GeneralRunner.java b/platform/vcs-impl/src/com/intellij/util/continuation/GeneralRunner.java deleted file mode 100644 index 9dd6e3a8f7c6..000000000000 --- a/platform/vcs-impl/src/com/intellij/util/continuation/GeneralRunner.java +++ /dev/null @@ -1,148 +0,0 @@ -/* - * Copyright 2000-2012 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.util.continuation; - -import com.intellij.openapi.progress.ProgressIndicator; -import com.intellij.openapi.project.Project; -import com.intellij.util.Consumer; -import org.jetbrains.annotations.CalledInAny; -import org.jetbrains.annotations.Nullable; - -import java.util.*; - -abstract class GeneralRunner implements ContinuationContext { - protected final Project myProject; - protected final boolean myCancellable; - protected final List myQueue; - protected final Object myQueueLock; - private boolean myTriggerSuspend; - private ProgressIndicator myIndicator; - private final Map, Consumer> myHandlersMap; - - GeneralRunner(final Project project, boolean cancellable) { - myProject = project; - myCancellable = cancellable; - myQueueLock = new Object(); - myQueue = new LinkedList<>(); - myHandlersMap = new HashMap<>(); - myTriggerSuspend = false; - } - - public void addExceptionHandler(final Class clazz, final Consumer consumer) { - synchronized (myQueueLock) { - myHandlersMap.put(clazz, e -> { - if (!clazz.isAssignableFrom(e.getClass())) { - throw new RuntimeException(e); - } - //noinspection unchecked - consumer.consume((T)e); - }); - } - } - - protected void setIndicator(final ProgressIndicator indicator) { - synchronized (myQueueLock) { - myIndicator = indicator; - } - } - - @Override - public boolean handleException(Exception e, boolean cancelEveryThing) { - synchronized (myQueueLock) { - try { - final Class aClass = e.getClass(); - Consumer consumer = myHandlersMap.get(e.getClass()); - if (consumer != null) { - consumer.consume(e); - return true; - } - for (Map.Entry, Consumer> entry : myHandlersMap.entrySet()) { - if (entry.getKey().isAssignableFrom(aClass)) { - entry.getValue().consume(e); - return true; - } - } - } finally { - if (cancelEveryThing) { - cancelEverything(); - } - } - } - return false; - } - - @CalledInAny - public void cancelEverything() { - synchronized (myQueueLock) { - myQueue.forEach(TaskDescriptor::canceled); - myQueue.clear(); - myIndicator = null; - } - } - - public void suspend() { - synchronized (myQueueLock) { - myTriggerSuspend = true; - } - } - - protected boolean getSuspendFlag() { - synchronized (myQueueLock) { - return myTriggerSuspend; - } - } - - protected void clearSuspend() { - synchronized (myQueueLock) { - myTriggerSuspend = false; - } - } - - @CalledInAny - public void next(TaskDescriptor... next) { - synchronized (myQueueLock) { - myQueue.addAll(0, Arrays.asList(next)); - } - } - - public void next(List next) { - synchronized (myQueueLock) { - myQueue.addAll(0, next); - } - } - - public abstract void ping(); - - // null - no more tasks - @Nullable - protected TaskDescriptor getNextMatching() { - while (true) { - synchronized (myQueueLock) { - if (myQueue.isEmpty()) return null; - TaskDescriptor current = myQueue.remove(0); - if (current.isHaveMagicCure() || myIndicator == null || !myIndicator.isCanceled()) { - return current; - } - } - } - } - - public ProgressIndicator getIndicator() { - synchronized (myQueueLock) { - return myIndicator; - } - } -} diff --git a/platform/vcs-impl/src/com/intellij/util/continuation/SeparatePiecesRunner.java b/platform/vcs-impl/src/com/intellij/util/continuation/SeparatePiecesRunner.java deleted file mode 100644 index 29c5c2fed9f5..000000000000 --- a/platform/vcs-impl/src/com/intellij/util/continuation/SeparatePiecesRunner.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright 2000-2011 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.util.continuation; - -import com.intellij.openapi.progress.EmptyProgressIndicator; -import com.intellij.openapi.progress.ProgressIndicator; -import com.intellij.openapi.progress.ProgressManager; -import com.intellij.openapi.progress.impl.BackgroundableProcessIndicator; -import com.intellij.openapi.project.Project; -import com.intellij.util.ui.UIUtil; -import org.jetbrains.annotations.CalledInAwt; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.concurrent.atomic.AtomicReference; - -import static com.intellij.openapi.application.ApplicationManager.getApplication; - -public class SeparatePiecesRunner extends GeneralRunner { - private final AtomicReference myCurrentWrapper; - - public SeparatePiecesRunner(Project project, boolean cancellable) { - super(project, cancellable); - myCurrentWrapper = new AtomicReference<>(); - } - - @CalledInAwt - public void ping() { - clearSuspend(); - UIUtil.invokeLaterIfNeeded(this::pingImpl); - } - - @CalledInAwt - private void pingImpl() { - while (true) { - myCurrentWrapper.set(null); - // stop if project is being disposed - if (!myProject.isDefault() && !myProject.isOpen()) return; - if (getSuspendFlag()) return; - final TaskDescriptor current = getNextMatching(); - if (current == null) { - return; - } - - if (Where.AWT.equals(current.getWhere())) { - setIndicator(null); - try { - current.run(this); - } - catch (RuntimeException th) { - handleException(th, true); - } - } - else { - final TaskWrapper task = new TaskWrapper(myProject, current.getName(), myCancellable, current); - myCurrentWrapper.set(task); - setIndicator(getApplication().isUnitTestMode() ? new EmptyProgressIndicator() : new BackgroundableProcessIndicator(task)); - ProgressManager.getInstance().runProcessWithProgressAsynchronously(task, getIndicator()); - return; - } - } - } - - @Override - public void suspend() { - super.suspend(); - final TaskWrapper wrapper = myCurrentWrapper.get(); - if (wrapper != null){ - wrapper.mySuspended = true; - } - } - - class TaskWrapper extends ModalityIgnorantBackgroundableTask { - private final TaskDescriptor myTaskDescriptor; - private volatile boolean mySuspended; - - TaskWrapper(@Nullable Project project, - @NotNull String title, - boolean canBeCancelled, - TaskDescriptor taskDescriptor) { - super(project, title, canBeCancelled); - myTaskDescriptor = taskDescriptor; - mySuspended = false; - } - - @Override - protected void doInAwtIfFail(Exception e) { - doInAwtIfCancel(); - } - - @Override - protected void doInAwtIfCancel() { - onCancel(); - } - - @Override - protected void doInAwtIfSuccess() { - if (! mySuspended) { - ping(); - } - } - - @Override - protected void runImpl(@NotNull ProgressIndicator indicator) { - myTaskDescriptor.run(SeparatePiecesRunner.this); - } - } -}