JobUtil -> JobLauncher component

This commit is contained in:
Evgeny Pasynkov
2012-06-13 15:04:41 +02:00
parent 73e89b44d2
commit f77d9c9ec7
17 changed files with 303 additions and 209 deletions
@@ -68,8 +68,8 @@ Full thread dump Java HotSpot(TM) 64-Bit Server VM (17.1-b03-307 mixed mode):
at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:206)
at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.doRun(PassExecutorService.java:340)
at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.run(PassExecutorService.java:316)
at com.intellij.concurrency.JobUtil$3.call(JobUtil.java:134)
at com.intellij.concurrency.JobUtil$3.call(JobUtil.java:131)
at com.intellij.concurrency.JobLauncher$3.call(JobUtil.java:134)
at com.intellij.concurrency.JobLauncher$3.call(JobUtil.java:131)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at com.intellij.concurrency.PrioritizedFutureTask.access$101(PrioritizedFutureTask.java:31)
@@ -724,8 +724,8 @@ Java stack information for the threads listed above:
at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:206)
at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.doRun(PassExecutorService.java:340)
at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.run(PassExecutorService.java:316)
at com.intellij.concurrency.JobUtil$3.call(JobUtil.java:134)
at com.intellij.concurrency.JobUtil$3.call(JobUtil.java:131)
at com.intellij.concurrency.JobLauncher$3.call(JobUtil.java:134)
at com.intellij.concurrency.JobLauncher$3.call(JobUtil.java:131)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at com.intellij.concurrency.PrioritizedFutureTask.access$101(PrioritizedFutureTask.java:31)
@@ -0,0 +1,54 @@
/*
* 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.concurrency;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.progress.ProcessCanceledException;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.util.Consumer;
import com.intellij.util.Processor;
import org.jetbrains.annotations.NotNull;
import java.util.List;
import java.util.concurrent.Future;
public abstract class JobLauncher {
public static JobLauncher getInstance() {
return ServiceManager.getService(JobLauncher.class);
}
/**
* Schedules concurrent execution of #thingProcessor over each element of #things and waits for completion
* With checkCanceled in each thread delegated to our current progress
*
* @param things to process concurrently
* @param progress
* @param failFastOnAcquireReadAction if true, returns false when failed to acquire read action
* @param thingProcessor to be invoked concurrently on each element from the collection
* @return false if tasks have been canceled
* or at least one processor returned false
* or threw exception
* or we were unable to start read action in at least one thread
* @throws ProcessCanceledException if at least one task has thrown ProcessCanceledException
*/
public abstract <T> boolean invokeConcurrentlyUnderProgress(@NotNull List<T> things,
ProgressIndicator progress,
boolean failFastOnAcquireReadAction,
@NotNull final Processor<T> thingProcessor) throws ProcessCanceledException;
public abstract Job<Void> submitToJobThread(int priority, @NotNull final Runnable action);
public abstract Job<Void> submitToJobThread(int priority, @NotNull final Runnable action, Consumer<Future> onDoneCallback);
}
@@ -24,7 +24,7 @@ import com.intellij.codeInsight.daemon.impl.analysis.HighlightInfoHolder;
import com.intellij.codeInsight.daemon.impl.analysis.HighlightLevelUtil;
import com.intellij.codeInsight.problems.ProblemImpl;
import com.intellij.codeInsight.problems.WolfTheProblemSolverImpl;
import com.intellij.concurrency.JobUtil;
import com.intellij.concurrency.JobLauncher;
import com.intellij.injected.editor.DocumentWindow;
import com.intellij.lang.Language;
import com.intellij.lang.annotation.HighlightSeverity;
@@ -319,14 +319,14 @@ public class GeneralHighlightingPass extends ProgressableTextEditorHighlightingP
}
}
};
if (!JobUtil.invokeConcurrentlyUnderProgress(new ArrayList<PsiElement>(hosts), progress, false, new Processor<PsiElement>() {
@Override
public boolean process(PsiElement element) {
progress.checkCanceled();
InjectedLanguageUtil.enumerate(element, myFile, false, visitor);
return true;
}
})) throw new ProcessCanceledException();
if (!JobLauncher.getInstance().invokeConcurrentlyUnderProgress(new ArrayList<PsiElement>(hosts), progress, false, new Processor<PsiElement>() {
@Override
public boolean process(PsiElement element) {
progress.checkCanceled();
InjectedLanguageUtil.enumerate(element, myFile, false, visitor);
return true;
}
})) throw new ProcessCanceledException();
}
// returns false if canceled
@@ -337,59 +337,76 @@ public class GeneralHighlightingPass extends ProgressableTextEditorHighlightingP
final InjectedLanguageManager injectedLanguageManager = InjectedLanguageManager.getInstance(myProject);
final TextAttributes injectedAttributes = myGlobalScheme.getAttributes(EditorColors.INJECTED_LANGUAGE_FRAGMENT);
return JobUtil.invokeConcurrentlyUnderProgress(new ArrayList<PsiFile>(injectedFiles), progress, myFailFastOnAcquireReadAction, new Processor<PsiFile>() {
@Override
public boolean process(final PsiFile injectedPsi) {
DocumentWindow documentWindow = (DocumentWindow)PsiDocumentManager.getInstance(myProject).getCachedDocument(injectedPsi);
if (documentWindow == null) return true;
Place places = InjectedLanguageUtil.getShreds(injectedPsi);
for (PsiLanguageInjectionHost.Shred place : places) {
TextRange textRange = place.getRangeInsideHost().shiftRight(place.getHost().getTextRange().getStartOffset());
if (textRange.isEmpty()) continue;
String desc = injectedPsi.getLanguage().getDisplayName() + ": " + injectedPsi.getText();
HighlightInfo info = HighlightInfo.createHighlightInfo(HighlightInfoType.INJECTED_LANGUAGE_BACKGROUND, textRange, null, desc, injectedAttributes);
info.fromInjection = true;
outInfos.add(info);
}
return JobLauncher.getInstance().invokeConcurrentlyUnderProgress(new ArrayList<PsiFile>(injectedFiles), progress, myFailFastOnAcquireReadAction,
new Processor<PsiFile>() {
@Override
public boolean process(final PsiFile injectedPsi) {
DocumentWindow documentWindow =
(DocumentWindow)PsiDocumentManager.getInstance(myProject)
.getCachedDocument(injectedPsi);
if (documentWindow == null) return true;
Place places = InjectedLanguageUtil.getShreds(injectedPsi);
for (PsiLanguageInjectionHost.Shred place : places) {
TextRange textRange = place.getRangeInsideHost()
.shiftRight(place.getHost().getTextRange().getStartOffset());
if (textRange.isEmpty()) continue;
String desc =
injectedPsi.getLanguage().getDisplayName() + ": " + injectedPsi.getText();
HighlightInfo info = HighlightInfo
.createHighlightInfo(HighlightInfoType.INJECTED_LANGUAGE_BACKGROUND,
textRange, null, desc, injectedAttributes);
info.fromInjection = true;
outInfos.add(info);
}
HighlightInfoHolder holder = createInfoHolder(injectedPsi);
runHighlightVisitorsForInjected(injectedPsi, holder, progress);
for (int i = 0; i < holder.size(); i++) {
HighlightInfo info = holder.get(i);
final int startOffset = documentWindow.injectedToHost(info.startOffset);
final TextRange fixedTextRange = getFixedTextRange(documentWindow, startOffset);
addPatchedInfos(info, injectedPsi, documentWindow, injectedLanguageManager, fixedTextRange, outInfos);
}
holder.clear();
highlightInjectedSyntax(injectedPsi, holder);
for (int i = 0; i < holder.size(); i++) {
HighlightInfo info = holder.get(i);
final int startOffset = info.startOffset;
final TextRange fixedTextRange = getFixedTextRange(documentWindow, startOffset);
if (fixedTextRange == null) {
info.fromInjection = true;
outInfos.add(info);
}
else {
HighlightInfo patched =
new HighlightInfo(info.forcedTextAttributes, info.forcedTextAttributesKey, info.type,
fixedTextRange.getStartOffset(), fixedTextRange.getEndOffset(),
info.description, info.toolTip, info.type.getSeverity(null), info.isAfterEndOfLine, null, false);
patched.fromInjection = true;
outInfos.add(patched);
}
}
HighlightInfoHolder holder = createInfoHolder(injectedPsi);
runHighlightVisitorsForInjected(injectedPsi, holder, progress);
for (int i = 0; i < holder.size(); i++) {
HighlightInfo info = holder.get(i);
final int startOffset = documentWindow.injectedToHost(info.startOffset);
final TextRange fixedTextRange =
getFixedTextRange(documentWindow, startOffset);
addPatchedInfos(info, injectedPsi, documentWindow, injectedLanguageManager,
fixedTextRange, outInfos);
}
holder.clear();
highlightInjectedSyntax(injectedPsi, holder);
for (int i = 0; i < holder.size(); i++) {
HighlightInfo info = holder.get(i);
final int startOffset = info.startOffset;
final TextRange fixedTextRange =
getFixedTextRange(documentWindow, startOffset);
if (fixedTextRange == null) {
info.fromInjection = true;
outInfos.add(info);
}
else {
HighlightInfo patched =
new HighlightInfo(info.forcedTextAttributes, info.forcedTextAttributesKey,
info.type,
fixedTextRange.getStartOffset(),
fixedTextRange.getEndOffset(),
info.description, info.toolTip,
info.type.getSeverity(null), info.isAfterEndOfLine, null,
false);
patched.fromInjection = true;
outInfos.add(patched);
}
}
if (!isDumbMode()) {
List<HighlightInfo> todos = new ArrayList<HighlightInfo>();
highlightTodos(injectedPsi, injectedPsi.getText(), 0, injectedPsi.getTextLength(), progress, myPriorityRange, todos, todos);
for (HighlightInfo info : todos) {
addPatchedInfos(info, injectedPsi, documentWindow, injectedLanguageManager, null, outInfos);
}
}
return true;
}
});
if (!isDumbMode()) {
List<HighlightInfo> todos = new ArrayList<HighlightInfo>();
highlightTodos(injectedPsi, injectedPsi.getText(), 0,
injectedPsi.getTextLength(), progress, myPriorityRange, todos,
todos);
for (HighlightInfo info : todos) {
addPatchedInfos(info, injectedPsi, documentWindow, injectedLanguageManager,
null, outInfos);
}
}
return true;
}
});
}
private static TextRange getFixedTextRange(@NotNull DocumentWindow documentWindow, int startOffset) {
@@ -25,7 +25,7 @@ import com.intellij.codeInsight.intention.EmptyIntentionAction;
import com.intellij.codeInspection.*;
import com.intellij.codeInspection.ex.*;
import com.intellij.codeInspection.ui.ProblemDescriptionNode;
import com.intellij.concurrency.JobUtil;
import com.intellij.concurrency.JobLauncher;
import com.intellij.injected.editor.DocumentWindow;
import com.intellij.lang.Language;
import com.intellij.lang.annotation.HighlightSeverity;
@@ -300,39 +300,44 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass
final ArrayList<InspectionContext> init = new ArrayList<InspectionContext>();
List<Map.Entry<LocalInspectionToolWrapper, Collection<String>>> entries = new ArrayList<Map.Entry<LocalInspectionToolWrapper, Collection<String>>>(tools.entrySet());
boolean result = JobUtil.invokeConcurrentlyUnderProgress(entries, indicator, myFailFastOnAcquireReadAction, new Processor<Map.Entry<LocalInspectionToolWrapper, Collection<String>>>() {
@Override
public boolean process(final Map.Entry<LocalInspectionToolWrapper, Collection<String>> pair) {
indicator.checkCanceled();
boolean result = JobLauncher.getInstance().invokeConcurrentlyUnderProgress(entries, indicator, myFailFastOnAcquireReadAction,
new Processor<Map.Entry<LocalInspectionToolWrapper, Collection<String>>>() {
@Override
public boolean process(final Map.Entry<LocalInspectionToolWrapper, Collection<String>> pair) {
indicator.checkCanceled();
ApplicationManager.getApplication().assertReadAccessAllowed();
final LocalInspectionToolWrapper wrapper = pair.getKey();
LocalInspectionTool tool = wrapper.getTool();
final boolean[] applyIncrementally = {isOnTheFly};
ProblemsHolder holder = new ProblemsHolder(iManager, myFile, isOnTheFly) {
@Override
public void registerProblem(@NotNull ProblemDescriptor descriptor) {
super.registerProblem(descriptor);
if (applyIncrementally[0]) {
addDescriptorIncrementally(descriptor, wrapper, indicator);
}
}
};
Set<String> languages = (Set<String>)pair.getValue();
PsiElementVisitor visitor = createVisitorAndAcceptElements(tool, holder, isOnTheFly, session, elements, languages);
ApplicationManager.getApplication().assertReadAccessAllowed();
final LocalInspectionToolWrapper wrapper = pair.getKey();
LocalInspectionTool tool = wrapper.getTool();
final boolean[] applyIncrementally = {isOnTheFly};
ProblemsHolder holder =
new ProblemsHolder(iManager, myFile, isOnTheFly) {
@Override
public void registerProblem(@NotNull ProblemDescriptor descriptor) {
super.registerProblem(descriptor);
if (applyIncrementally[0]) {
addDescriptorIncrementally(descriptor, wrapper, indicator);
}
}
};
Set<String> languages = (Set<String>)pair.getValue();
PsiElementVisitor visitor =
createVisitorAndAcceptElements(tool, holder, isOnTheFly, session,
elements, languages);
synchronized (init) {
init.add(new InspectionContext(wrapper, holder, visitor, languages));
}
advanceProgress(1);
synchronized (init) {
init.add(new InspectionContext(wrapper, holder, visitor, languages));
}
advanceProgress(1);
if (holder.hasResults()) {
appendDescriptors(myFile, holder.getResults(), wrapper);
}
applyIncrementally[0] = false; // do not apply incrementally outside visible range
return true;
}
});
if (holder.hasResults()) {
appendDescriptors(myFile, holder.getResults(), wrapper);
}
applyIncrementally[0] =
false; // do not apply incrementally outside visible range
return true;
}
});
if (!result) throw new ProcessCanceledException();
inspectInjectedPsi(elements, isOnTheFly, indicator, iManager, true, checkDumbAwareness, wrappers);
return init;
@@ -381,7 +386,7 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass
return true;
}
};
boolean result = JobUtil.invokeConcurrentlyUnderProgress(init, indicator, myFailFastOnAcquireReadAction, processor);
boolean result = JobLauncher.getInstance().invokeConcurrentlyUnderProgress(init, indicator, myFailFastOnAcquireReadAction, processor);
if (!result) {
throw new ProcessCanceledException();
}
@@ -416,13 +421,15 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass
});
}
if (injected.isEmpty()) return;
if (!JobUtil.invokeConcurrentlyUnderProgress(new ArrayList<PsiFile>(injected), indicator, myFailFastOnAcquireReadAction, new Processor<PsiFile>() {
@Override
public boolean process(final PsiFile injectedPsi) {
doInspectInjectedPsi(injectedPsi, onTheFly, indicator, iManager, inVisibleRange, wrappers, checkDumbAwareness);
return true;
}
})) throw new ProcessCanceledException();
if (!JobLauncher.getInstance().invokeConcurrentlyUnderProgress(new ArrayList<PsiFile>(injected), indicator, myFailFastOnAcquireReadAction,
new Processor<PsiFile>() {
@Override
public boolean process(final PsiFile injectedPsi) {
doInspectInjectedPsi(injectedPsi, onTheFly, indicator, iManager, inVisibleRange,
wrappers, checkDumbAwareness);
return true;
}
})) throw new ProcessCanceledException();
}
@Nullable
@@ -20,7 +20,7 @@ import com.intellij.codeHighlighting.HighlightingPass;
import com.intellij.codeHighlighting.TextEditorHighlightingPass;
import com.intellij.concurrency.Job;
import com.intellij.concurrency.JobImpl;
import com.intellij.concurrency.JobUtil;
import com.intellij.concurrency.JobLauncher;
import com.intellij.injected.editor.EditorWindow;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.application.ApplicationManager;
@@ -271,7 +271,7 @@ public abstract class PassExecutorService implements Disposable {
private void submit(final ScheduledPass pass) {
if (!pass.myUpdateProgress.isCanceled()) {
Job<Void> job = JobUtil.submitToJobThread(pass.myJobPriority, pass, new Consumer<Future>() {
Job<Void> job = JobLauncher.getInstance().submitToJobThread(pass.myJobPriority, pass, new Consumer<Future>() {
@Override
public void consume(Future future) {
try {
@@ -27,7 +27,7 @@ package com.intellij.codeInsight.highlighting;
import com.intellij.codeInsight.CodeInsightSettings;
import com.intellij.codeInsight.hint.EditorFragmentComponent;
import com.intellij.concurrency.Job;
import com.intellij.concurrency.JobUtil;
import com.intellij.concurrency.JobLauncher;
import com.intellij.injected.editor.EditorWindow;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ModalityState;
@@ -109,7 +109,7 @@ public class BraceHighlightingHandler {
final Project project = editor.getProject();
if (project == null) return;
final int offset = editor.getCaretModel().getOffset();
JobUtil.submitToJobThread(Job.DEFAULT_PRIORITY, new Runnable() {
JobLauncher.getInstance().submitToJobThread(Job.DEFAULT_PRIORITY, new Runnable() {
public void run() {
final PsiFile injected;
try {
@@ -132,7 +132,7 @@ public class BraceHighlightingHandler {
});
throw e;
}
ApplicationManager.getApplication().invokeLater(new DumbAwareRunnable(){
ApplicationManager.getApplication().invokeLater(new DumbAwareRunnable() {
public void run() {
try {
if (!isReallyDisposed(editor, project)) {
@@ -25,7 +25,7 @@ import com.intellij.codeInspection.lang.GlobalInspectionContextExtension;
import com.intellij.codeInspection.lang.InspectionExtensionsFactory;
import com.intellij.codeInspection.reference.*;
import com.intellij.codeInspection.ui.InspectionResultsView;
import com.intellij.concurrency.JobUtil;
import com.intellij.concurrency.JobLauncher;
import com.intellij.lang.injection.InjectedLanguageManager;
import com.intellij.notification.NotificationGroup;
import com.intellij.openapi.actionSystem.ToggleAction;
@@ -601,19 +601,19 @@ public class GlobalInspectionContextImpl extends UserDataHolderBase implements G
}
pass.doInspectInBatch((InspectionManagerEx)manager, lTools);
JobUtil.invokeConcurrentlyUnderProgress(globalSimpleTools, myProgressIndicator, false, new Processor<Tools>() {
@Override
public boolean process(Tools tools) {
GlobalInspectionToolWrapper toolWrapper = (GlobalInspectionToolWrapper)tools.getTool();
GlobalSimpleInspectionTool tool = (GlobalSimpleInspectionTool)toolWrapper.getTool();
ProblemsHolder problemsHolder = new ProblemsHolder(manager, file, false);
GlobalInspectionToolWrapper problemDescriptionProcessor = getProblemDescriptionProcessor(toolWrapper, map);
tool.checkFile(file, manager, problemsHolder, GlobalInspectionContextImpl.this, problemDescriptionProcessor);
LocalInspectionToolWrapper.addProblemDescriptors(problemsHolder.getResults(), false, GlobalInspectionContextImpl.this, null,
CONVERT, toolWrapper);
return true;
}
});
JobLauncher.getInstance().invokeConcurrentlyUnderProgress(globalSimpleTools, myProgressIndicator, false, new Processor<Tools>() {
@Override
public boolean process(Tools tools) {
GlobalInspectionToolWrapper toolWrapper = (GlobalInspectionToolWrapper)tools.getTool();
GlobalSimpleInspectionTool tool = (GlobalSimpleInspectionTool)toolWrapper.getTool();
ProblemsHolder problemsHolder = new ProblemsHolder(manager, file, false);
GlobalInspectionToolWrapper problemDescriptionProcessor = getProblemDescriptionProcessor(toolWrapper, map);
tool.checkFile(file, manager, problemsHolder, GlobalInspectionContextImpl.this, problemDescriptionProcessor);
LocalInspectionToolWrapper.addProblemDescriptors(problemsHolder.getResults(), false, GlobalInspectionContextImpl.this, null,
CONVERT, toolWrapper);
return true;
}
});
}
catch (ProcessCanceledException e) {
throw e;
@@ -15,7 +15,7 @@
*/
package com.intellij.ide.util.gotoByName;
import com.intellij.concurrency.JobUtil;
import com.intellij.concurrency.JobLauncher;
import com.intellij.diagnostic.PluginException;
import com.intellij.ide.plugins.PluginManager;
import com.intellij.ide.util.NavigationItemListCellRenderer;
@@ -32,7 +32,6 @@ import com.intellij.util.ArrayUtil;
import com.intellij.util.Processor;
import com.intellij.util.containers.ConcurrentHashSet;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.ui.UIUtil;
import javax.swing.*;
import java.awt.*;
@@ -66,26 +65,27 @@ public abstract class ContributorsBasedGotoByModel implements ChooseByNameModel
public String[] getNames(final boolean checkBoxState) {
final Set<String> names = new ConcurrentHashSet<String>();
JobUtil.invokeConcurrentlyUnderProgress(filterDumb(myContributors), ProgressManager.getInstance().getProgressIndicator(), false, new Processor<ChooseByNameContributor>() {
@Override
public boolean process(ChooseByNameContributor contributor) {
try {
if (!myProject.isDisposed()) {
ContainerUtil.addAll(names, contributor.getNames(myProject, checkBoxState));
}
}
catch (ProcessCanceledException ex) {
// index corruption detected, ignore
}
catch (IndexNotReadyException ex) {
// index corruption detected, ignore
}
catch (Exception ex) {
LOG.error(ex);
}
return true;
}
});
JobLauncher.getInstance().invokeConcurrentlyUnderProgress(filterDumb(myContributors), ProgressManager.getInstance().getProgressIndicator(), false,
new Processor<ChooseByNameContributor>() {
@Override
public boolean process(ChooseByNameContributor contributor) {
try {
if (!myProject.isDisposed()) {
ContainerUtil.addAll(names, contributor.getNames(myProject, checkBoxState));
}
}
catch (ProcessCanceledException ex) {
// index corruption detected, ignore
}
catch (IndexNotReadyException ex) {
// index corruption detected, ignore
}
catch (Exception ex) {
LOG.error(ex);
}
return true;
}
});
return ArrayUtil.toStringArray(names);
}
@@ -115,36 +115,40 @@ public abstract class ContributorsBasedGotoByModel implements ChooseByNameModel
public Object[] getElementsByName(final String name, final boolean checkBoxState, final String pattern) {
final List<NavigationItem> items = Collections.synchronizedList(new ArrayList<NavigationItem>());
JobUtil.invokeConcurrentlyUnderProgress(filterDumb(myContributors), ProgressManager.getInstance().getProgressIndicator(), false, new Processor<ChooseByNameContributor>() {
@Override
public boolean process(ChooseByNameContributor contributor) {
try {
for (NavigationItem item : contributor.getItemsByName(name, pattern, myProject, checkBoxState)) {
if (item == null) {
final PluginId pluginId = PluginManager.getPluginByClassName(contributor.getClass().getName());
if (pluginId != null) {
LOG.error(new PluginException("null item from contributor " + contributor + " for name " + name, pluginId));
}
else {
LOG.error("null item from contributor " + contributor + " for name " + name);
}
continue;
}
JobLauncher.getInstance().invokeConcurrentlyUnderProgress(filterDumb(myContributors), ProgressManager.getInstance().getProgressIndicator(), false,
new Processor<ChooseByNameContributor>() {
@Override
public boolean process(ChooseByNameContributor contributor) {
try {
for (NavigationItem item : contributor
.getItemsByName(name, pattern, myProject, checkBoxState)) {
if (item == null) {
final PluginId pluginId =
PluginManager.getPluginByClassName(contributor.getClass().getName());
if (pluginId != null) {
LOG.error(new PluginException(
"null item from contributor " + contributor + " for name " + name, pluginId));
}
else {
LOG.error("null item from contributor " + contributor + " for name " + name);
}
continue;
}
if (acceptItem(item)) {
items.add(item);
}
}
}
catch (ProcessCanceledException ex) {
// index corruption detected, ignore
}
catch (Exception ex) {
LOG.error(ex);
}
return true;
}
});
if (acceptItem(item)) {
items.add(item);
}
}
}
catch (ProcessCanceledException ex) {
// index corruption detected, ignore
}
catch (Exception ex) {
LOG.error(ex);
}
return true;
}
});
return ArrayUtil.toObjectArray(items);
}
@@ -17,7 +17,7 @@
package com.intellij.psi.impl.search;
import com.intellij.codeInsight.CommentUtil;
import com.intellij.concurrency.JobUtil;
import com.intellij.concurrency.JobLauncher;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ReadAction;
import com.intellij.openapi.application.ReadActionProcessor;
@@ -138,7 +138,7 @@ public class PsiSearchHelperImpl implements PsiSearchHelper {
PsiElement[] scopeElements = scope.getScope();
final boolean ignoreInjectedPsi = scope.isIgnoreInjectedPsi();
return JobUtil.invokeConcurrentlyUnderProgress(Arrays.asList(scopeElements), progress, false, new Processor<PsiElement>() {
return JobLauncher.getInstance().invokeConcurrentlyUnderProgress(Arrays.asList(scopeElements), progress, false, new Processor<PsiElement>() {
@Override
public boolean process(PsiElement scopeElement) {
return processElementsWithWordInScopeElement(scopeElement, processor, text, caseSensitively, ignoreInjectedPsi, progress);
@@ -207,7 +207,7 @@ public class PsiSearchHelperImpl implements PsiSearchHelper {
final AtomicBoolean pceThrown = new AtomicBoolean(false);
final int size = files.size();
boolean completed = JobUtil.invokeConcurrentlyUnderProgress(files, progress, false, new Processor<VirtualFile>() {
boolean completed = JobLauncher.getInstance().invokeConcurrentlyUnderProgress(files, progress, false, new Processor<VirtualFile>() {
@Override
public boolean process(final VirtualFile vfile) {
final PsiFile file = ApplicationManager.getApplication().runReadAction(new Computable<PsiFile>() {
@@ -228,7 +228,14 @@ public class PsiSearchHelperImpl implements PsiSearchHelper {
for (PsiElement psiRoot : psiRoots) {
if (progress != null) progress.checkCanceled();
if (!processed.add(psiRoot)) continue;
assert psiRoot != null : "One of the roots of file "+file + " is null. All roots: "+Arrays.asList(psiRoots)+"; Viewprovider: "+file.getViewProvider()+"; Virtual file: "+file.getViewProvider().getVirtualFile();
assert psiRoot != null : "One of the roots of file " +
file +
" is null. All roots: " +
Arrays.asList(psiRoots) +
"; Viewprovider: " +
file.getViewProvider() +
"; Virtual file: " +
file.getViewProvider().getVirtualFile();
if (!psiRootProcessor.process(psiRoot)) {
canceled.set(true);
return;
@@ -19,7 +19,7 @@ package com.intellij.psi.impl.source.tree.injected;
import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer;
import com.intellij.codeInsight.daemon.impl.DaemonProgressIndicator;
import com.intellij.concurrency.Job;
import com.intellij.concurrency.JobUtil;
import com.intellij.concurrency.JobLauncher;
import com.intellij.injected.editor.DocumentWindow;
import com.intellij.injected.editor.DocumentWindowImpl;
import com.intellij.injected.editor.VirtualFileWindow;
@@ -181,7 +181,7 @@ public class InjectedLanguageManagerImpl extends InjectedLanguageManager impleme
@Override
public void run() {
if (myProgress.isCanceled()) return;
JobUtil.invokeConcurrentlyUnderProgress(new ArrayList<DocumentWindow>(injected), myProgress, !synchronously, commitProcessor);
JobLauncher.getInstance().invokeConcurrentlyUnderProgress(new ArrayList<DocumentWindow>(injected), myProgress, !synchronously, commitProcessor);
}
};
@@ -196,7 +196,7 @@ public class InjectedLanguageManagerImpl extends InjectedLanguageManager impleme
}
}
else {
JobUtil.submitToJobThread(Job.DEFAULT_PRIORITY, new Runnable() {
JobLauncher.getInstance().submitToJobThread(Job.DEFAULT_PRIORITY, new Runnable() {
@Override
public void run() {
ApplicationManagerEx.getApplicationEx().tryRunReadAction(commitInjectionsRunnable);
@@ -20,7 +20,7 @@
package com.intellij.ui;
import com.intellij.concurrency.Job;
import com.intellij.concurrency.JobUtil;
import com.intellij.concurrency.JobLauncher;
import com.intellij.openapi.progress.ProcessCanceledException;
import com.intellij.openapi.project.IndexNotReadyException;
import com.intellij.openapi.util.Ref;
@@ -117,14 +117,15 @@ public class DeferredIconImpl<T> implements DeferredIcon {
paintingParentRec.set(((PaintingParent)pp).getChildRec(c));
}
JobUtil.submitToJobThread(Job.DEFAULT_PRIORITY, new Runnable() {
JobLauncher.getInstance().submitToJobThread(Job.DEFAULT_PRIORITY, new Runnable() {
@Override
public void run() {
int oldWidth = myDelegateIcon.getIconWidth();
final Icon result = evaluate();
myDelegateIcon = result;
final boolean shouldRevalidate = Registry.is("ide.tree.deferredicon.invalidates.cache") && myDelegateIcon.getIconWidth() != oldWidth;
final boolean shouldRevalidate =
Registry.is("ide.tree.deferredicon.invalidates.cache") && myDelegateIcon.getIconWidth() != oldWidth;
//noinspection SSBasedInspection
SwingUtilities.invokeLater(new Runnable() {
@@ -34,13 +34,10 @@ import java.util.concurrent.Future;
* @author cdr
*/
public class JobUtil {
private static final Logger LOG = Logger.getInstance("#com.intellij.concurrency.JobUtil");
public class JobLauncherImpl extends JobLauncher {
private static final Logger LOG = Logger.getInstance("#com.intellij.concurrency.JobLauncher");
private JobUtil() {
}
private static <T> boolean invokeConcurrentlyForAll(@NotNull final List<T> things,
private <T> boolean invokeConcurrentlyForAll(@NotNull final List<T> things,
boolean failFastOnAcquireReadAction,
@NotNull final Processor<T> thingProcessor) throws ProcessCanceledException {
final Job<String> job = new JobImpl<String>(Job.DEFAULT_PRIORITY, failFastOnAcquireReadAction);
@@ -95,7 +92,8 @@ public class JobUtil {
* or we were unable to start read action in at least one thread
* @throws ProcessCanceledException if at least one task has thrown ProcessCanceledException
*/
public static <T> boolean invokeConcurrentlyUnderProgress(@NotNull List<T> things,
@Override
public <T> boolean invokeConcurrentlyUnderProgress(@NotNull List<T> things,
ProgressIndicator progress,
boolean failFastOnAcquireReadAction,
@NotNull final Processor<T> thingProcessor) throws ProcessCanceledException {
@@ -122,11 +120,13 @@ public class JobUtil {
});
}
public static Job<Void> submitToJobThread(int priority, @NotNull final Runnable action) {
@Override
public Job<Void> submitToJobThread(int priority, @NotNull final Runnable action) {
return submitToJobThread(priority, action, null);
}
public static Job<Void> submitToJobThread(int priority, @NotNull final Runnable action, Consumer<Future> onDoneCallback) {
@Override
public Job<Void> submitToJobThread(int priority, @NotNull final Runnable action, Consumer<Future> onDoneCallback) {
final JobImpl<Void> job = new JobImpl<Void>(priority, false);
Callable<Void> callable = new Callable<Void>() {
public Void call() throws Exception {
@@ -15,6 +15,9 @@
<applicationService serviceInterface="com.intellij.codeStyle.CodeStyleFacade"
serviceImplementation="com.intellij.psi.impl.source.codeStyle.CodeStyleFacadeImpl"/>
<applicationService serviceInterface="com.intellij.concurrency.JobLauncher"
serviceImplementation="com.intellij.concurrency.JobLauncherImpl"/>
<applicationService serviceInterface="com.intellij.openapi.project.ProjectLocator"
serviceImplementation="com.intellij.openapi.project.ProjectLocatorImpl"/>
@@ -15,7 +15,7 @@
*/
package com.intellij.openapi.vfs;
import com.intellij.concurrency.JobUtil;
import com.intellij.concurrency.JobLauncher;
import com.intellij.openapi.application.Result;
import com.intellij.openapi.application.WriteAction;
import com.intellij.openapi.application.ex.PathManagerEx;
@@ -146,18 +146,19 @@ public class VfsUtilTest extends PlatformLangTestCase {
public void testAsyncRefresh() throws Throwable {
final Throwable[] ex = {null};
JobUtil.invokeConcurrentlyUnderProgress(Arrays.asList(new Object[8]), ProgressManager.getInstance().getProgressIndicator(), false, new Processor<Object>() {
@Override
public boolean process(Object o) {
try {
doAsyncRefreshTest();
}
catch (Throwable t) {
ex[0] = t;
}
return true;
}
});
JobLauncher.getInstance().invokeConcurrentlyUnderProgress(Arrays.asList(new Object[8]), ProgressManager.getInstance().getProgressIndicator(), false,
new Processor<Object>() {
@Override
public boolean process(Object o) {
try {
doAsyncRefreshTest();
}
catch (Throwable t) {
ex[0] = t;
}
return true;
}
});
if (ex[0] != null) throw ex[0];
}
@@ -15,7 +15,7 @@
*/
package com.intellij.openapi.vfs.impl;
import com.intellij.concurrency.JobUtil;
import com.intellij.concurrency.JobLauncher;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ex.PathManagerEx;
@@ -514,7 +514,7 @@ public class VirtualFilePointerTest extends PlatformLangTestCase {
}
private static void stressRead(@NotNull final VirtualFilePointer pointer) {
boolean b = JobUtil.invokeConcurrentlyUnderProgress(Collections.nCopies(10, null), null, false, new Processor<Object>() {
boolean b = JobLauncher.getInstance().invokeConcurrentlyUnderProgress(Collections.nCopies(10, null), null, false, new Processor<Object>() {
@Override
public boolean process(Object o) {
ApplicationManager.getApplication().runReadAction(new Runnable() {
@@ -18,7 +18,7 @@ package com.intellij.codeInspection.duplicatePropertyInspection;
import com.intellij.codeInspection.*;
import com.intellij.codeInspection.ex.GlobalInspectionContextImpl;
import com.intellij.codeInspection.reference.RefManager;
import com.intellij.concurrency.JobUtil;
import com.intellij.concurrency.JobLauncher;
import com.intellij.lang.properties.IProperty;
import com.intellij.lang.properties.PropertiesBundle;
import com.intellij.lang.properties.psi.PropertiesFile;
@@ -162,7 +162,7 @@ public class DuplicatePropertyInspection extends GlobalSimpleInspectionTool {
final ProgressIndicator progress = ProgressWrapper.wrap(original);
ProgressManager.getInstance().runProcess(new Runnable() {
public void run() {
if (!JobUtil.invokeConcurrentlyUnderProgress(properties, progress, false, new Processor<IProperty>() {
if (!JobLauncher.getInstance().invokeConcurrentlyUnderProgress(properties, progress, false, new Processor<IProperty>() {
public boolean process(final IProperty property) {
if (original != null) {
if (original.isCanceled()) return false;