mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
vcs: Removed unused "TaskDescriptor" and related api
This commit is contained in:
@@ -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<TaskDescriptor> next);
|
||||
|
||||
@CalledInAny
|
||||
void cancelEverything();
|
||||
|
||||
<T extends Exception> void addExceptionHandler(final Class<T> clazz, final Consumer<T> consumer);
|
||||
|
||||
boolean handleException(final Exception e, boolean cancelEveryThing);
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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<TaskDescriptor> myQueue;
|
||||
protected final Object myQueueLock;
|
||||
private boolean myTriggerSuspend;
|
||||
private ProgressIndicator myIndicator;
|
||||
private final Map<Class<? extends Exception>, Consumer<Exception>> myHandlersMap;
|
||||
|
||||
GeneralRunner(final Project project, boolean cancellable) {
|
||||
myProject = project;
|
||||
myCancellable = cancellable;
|
||||
myQueueLock = new Object();
|
||||
myQueue = new LinkedList<>();
|
||||
myHandlersMap = new HashMap<>();
|
||||
myTriggerSuspend = false;
|
||||
}
|
||||
|
||||
public <T extends Exception> void addExceptionHandler(final Class<T> clazz, final Consumer<T> 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<? extends Exception> aClass = e.getClass();
|
||||
Consumer<Exception> consumer = myHandlersMap.get(e.getClass());
|
||||
if (consumer != null) {
|
||||
consumer.consume(e);
|
||||
return true;
|
||||
}
|
||||
for (Map.Entry<Class<? extends Exception>, Consumer<Exception>> 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<TaskDescriptor> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<TaskWrapper> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user