@Override public final void run() { if (!HeavyProcessLatch.INSTANCE.isRunning() && !myInProgress.getAndSet(true)) { try { ApplicationManager.getApplication().executeOnPooledThread(myTaskRunnable); } catch (RejectedExecutionException ignored) { // we were shut down myInProgress.set(false); } catch (Throwable e) { myInProgress.set(false); throw new RuntimeException(e); } } else { schedule(); } }
private void flushAllIndices(final long modCount) { if (HeavyProcessLatch.INSTANCE.isRunning()) { return; } IndexingStamp.flushCaches(); for (ID<?, ?> indexId : new ArrayList<ID<?, ?>>(myIndices.keySet())) { if (HeavyProcessLatch.INSTANCE.isRunning() || modCount != myLocalModCount) { return; // do not interfere with 'main' jobs } try { final UpdatableIndex<?, ?, FileContent> index = getIndex(indexId); if (index != null) { index.flush(); } } catch (StorageException e) { LOG.info(e); requestRebuild(indexId); } } ContentHashesSupport.flushContentHashes(); }
/** * this method will called from webservice thread */ private static void syncProjectStep2(@NotNull final Project project, @Nullable final Sdk sdk, @Nullable UnityOpenFilePostHandlerRequest requestor, final boolean runValidator, UnitySetDefines unitySetDefines) { Task.Backgroundable.queue(project, "Sync Project", indicator -> { AccessToken accessToken = HeavyProcessLatch.INSTANCE.processStarted("unity sync project"); try { importAfterDefines(project, sdk, runValidator, indicator, requestor, unitySetDefines); } finally { accessToken.finish(); } }); }
public void runStartupActivities() { ApplicationManager.getApplication().runReadAction(new Runnable() { public void run() { HeavyProcessLatch.INSTANCE.processStarted(); try { runActivities(myPreStartupActivities); myPreStartupActivitiesPassed = true; myStartupActivitiesRunning = true; runActivities(myStartupActivities); myStartupActivitiesRunning = false; myStartupActivitiesPassed = true; } finally { HeavyProcessLatch.INSTANCE.processFinished(); } } }); }
private void flushAllIndices(final long modCount) { if (HeavyProcessLatch.INSTANCE.isRunning()) { return; } IndexingStamp.flushCaches(); for (ID<?, ?> indexId : new ArrayList<ID<?, ?>>(myIndices.keySet())) { if (HeavyProcessLatch.INSTANCE.isRunning() || modCount != myLocalModCount) { return; // do not interfere with 'main' jobs } try { final UpdatableIndex<?, ?, FileContent> index = getIndex(indexId); if (index != null) { index.flush(); } } catch (StorageException e) { LOG.info(e); requestRebuild(indexId); } } if (!HeavyProcessLatch.INSTANCE.isRunning() && modCount == myLocalModCount) { // do not interfere with 'main' jobs SerializationManagerEx.getInstanceEx().flushNameStorage(); } }
@Override public void load(String path) throws IOException { getStateStore().setOptionsPath(path); getStateStore().setConfigPath(PathManager.getConfigPath()); AccessToken accessToken = HeavyProcessLatch.INSTANCE.processStarted("app store load"); try { getStateStore().load(); } catch (StateStorageException e) { throw new IOException(e.getMessage()); } finally { accessToken.finish(); } }
@Override public void waitForCompletion(int millis) throws InterruptedException, ExecutionException, TimeoutException { HeavyProcessLatch.INSTANCE.stopThreadPrioritizing(); while (!isDone()) { try { myForkJoinTask.get(millis, TimeUnit.MILLISECONDS); break; } catch (CancellationException e) { // was canceled in the middle of execution // can't do anything but wait. help other tasks in the meantime if (!isDone()) { ForkJoinPool.commonPool().awaitQuiescence(millis, TimeUnit.MILLISECONDS); } } } }
public ProgressManagerImpl() { HeavyProcessLatch.INSTANCE.addUIActivityListener(new HeavyProcessLatch.HeavyProcessListener() { private final CheckCanceledHook sleepHook = indicator -> sleepIfNeededToGivePriorityToAnotherThread(); private final AtomicBoolean scheduled = new AtomicBoolean(); private final Runnable addHookLater = () -> { scheduled.set(false); if (HeavyProcessLatch.INSTANCE.hasPrioritizedThread()) { addCheckCanceledHook(sleepHook); } }; @Override public void processStarted() { if (scheduled.compareAndSet(false, true)) { AppExecutorUtil.getAppScheduledExecutorService().schedule(addHookLater, 5, TimeUnit.MILLISECONDS); } } @Override public void processFinished() { removeCheckCanceledHook(sleepHook); } }, this); }
@SuppressWarnings("SynchronizeOnThis") public void runStartupActivities() { ApplicationManager.getApplication().runReadAction(() -> { AccessToken token = HeavyProcessLatch.INSTANCE.processStarted("Running Startup Activities"); try { runActivities(myPreStartupActivities); // to avoid atomicity issues if runWhenProjectIsInitialized() is run at the same time synchronized (this) { myPreStartupActivitiesPassed = true; myStartupActivitiesRunning = true; } runActivities(myStartupActivities); synchronized (this) { myStartupActivitiesRunning = false; myStartupActivitiesPassed = true; } } finally { token.finish(); } }); }
private void flushAllIndices(final long modCount) { if (HeavyProcessLatch.INSTANCE.isRunning()) { return; } IndexingStamp.flushCaches(); IndexConfiguration state = getState(); for (ID<?, ?> indexId : new ArrayList<>(state.getIndexIDs())) { if (HeavyProcessLatch.INSTANCE.isRunning() || modCount != myLocalModCount) { return; // do not interfere with 'main' jobs } try { final UpdatableIndex<?, ?, FileContent> index = state.getIndex(indexId); if (index != null) { index.flush(); } } catch (StorageException e) { LOG.info(e); requestRebuild(indexId); } } ContentHashesSupport.flushContentHashes(); SharedIndicesData.flushData(); }
@Override public void load(@Nullable final String configPath) { AccessToken token = HeavyProcessLatch.INSTANCE.processStarted("Loading application components"); try { long t = System.currentTimeMillis(); init(mySplash == null ? null : new EmptyProgressIndicator() { @Override public void setFraction(double fraction) { mySplash.showProgress("", (float)(0.65 + getPercentageOfComponentsLoaded() * 0.35)); } }, new Runnable() { @Override public void run() { // create ServiceManagerImpl at first to force extension classes registration getPicoContainer().getComponentInstance(ServiceManagerImpl.class); String effectiveConfigPath = FileUtilRt.toSystemIndependentName(configPath == null ? PathManager.getConfigPath() : configPath); for (ApplicationLoadListener listener : ApplicationLoadListener.EP_NAME.getExtensions()) { try { listener.beforeApplicationLoaded(ApplicationImpl.this, effectiveConfigPath); } catch (Throwable e) { LOG.error(e); } } // we set it after beforeApplicationLoaded call, because app store can depends on stream provider state ServiceKt.getStateStore(ApplicationImpl.this).setPath(effectiveConfigPath); } }); t = System.currentTimeMillis() - t; LOG.info(getComponentConfigCount() + " application components initialized in " + t + " ms"); } finally { token.finish(); } myLoaded = true; createLocatorFile(); }
private void queueSession(@NotNull final RefreshSessionImpl session, @NotNull final ModalityState modality) { myQueue.submit(new Runnable() { @Override public void run() { try { myRefreshIndicator.start(); AccessToken token = HeavyProcessLatch.INSTANCE.processStarted("Doing file refresh. " + session.toString()); try { doScan(session); } finally { token.finish(); myRefreshIndicator.stop(); } } finally { ApplicationManager.getApplication().invokeLater(new DumbAwareRunnable() { @Override public void run() { session.fireEvents(false); } }, modality); } } }); myEventCounter.eventHappened(); }
public void runStartupActivities() { ApplicationManager.getApplication().runReadAction(new Runnable() { @Override @SuppressWarnings("SynchronizeOnThis") public void run() { AccessToken token = HeavyProcessLatch.INSTANCE.processStarted("Running Startup Activities"); try { runActivities(myPreStartupActivities); // to avoid atomicity issues if runWhenProjectIsInitialized() is run at the same time synchronized (StartupManagerImpl.this) { myPreStartupActivitiesPassed = true; myStartupActivitiesRunning = true; } runActivities(myStartupActivities); synchronized (StartupManagerImpl.this) { myStartupActivitiesRunning = false; myStartupActivitiesPassed = true; } } finally { token.finish(); } } }); }
@NotNull private Runnable createUpdateRunnable() { return new Runnable() { @Override public void run() { ApplicationManager.getApplication().assertIsDispatchThread(); if (myDisposed || !myProject.isInitialized() || PowerSaveMode.isEnabled()) { return; } if (HeavyProcessLatch.INSTANCE.isRunning()) { if (myAlarm.isEmpty()) { // wait for heavy processing to stop, re-schedule daemon but not too soon myAlarm.addRequest(myUpdateRunnable, Math.max(mySettings.AUTOREPARSE_DELAY,100)); } return; } Editor activeEditor = FileEditorManager.getInstance(myProject).getSelectedTextEditor(); if (activeEditor == null) { submitPassesRunnable.run(); } else { ((PsiDocumentManagerBase)myPsiDocumentManager).cancelAndRunWhenAllCommitted("start daemon when all committed", submitPassesRunnable); } } }; }
@Override public void load(String path) throws IOException, InvalidDataException { getStateStore().setOptionsPath(path); getStateStore().setConfigPath(PathManager.getConfigPath()); myIsFiringLoadingEvent = true; try { fireBeforeApplicationLoaded(); } finally { myIsFiringLoadingEvent = false; } loadComponentRoamingTypes(); HeavyProcessLatch.INSTANCE.processStarted(); try { getStateStore().load(); } catch (StateStorageException e) { throw new IOException(e.getMessage()); } finally { HeavyProcessLatch.INSTANCE.processFinished(); } myLoaded = true; createLocatorFile(); }
private void queueSession(@NotNull final RefreshSessionImpl session, @NotNull final ModalityState modality) { myQueue.submit(new Runnable() { @Override public void run() { try { myRefreshIndicator.start(); HeavyProcessLatch.INSTANCE.processStarted(); try { doScan(session); } finally { HeavyProcessLatch.INSTANCE.processFinished(); myRefreshIndicator.stop(); } } finally { final Application app = ApplicationManager.getApplication(); app.invokeLater(new DumbAwareRunnable() { @Override public void run() { if (app.isDisposed()) return; session.fireEvents(false); } }, modality); } } }); }
static void executeOutOfHeavyProcessLater(@Nonnull Runnable command, int delayMs) { HeavyProcessLatch.INSTANCE.executeOutOfHeavyProcess(() -> JobScheduler.getScheduler().schedule(() -> { if (HeavyProcessLatch.INSTANCE.isRunning()) { executeOutOfHeavyProcessLater(command, delayMs); } else { command.run(); } }, delayMs, TimeUnit.MILLISECONDS)); }
@Override public void save() { if (ApplicationManagerEx.getApplicationEx().isDoNotSave()) { // no need to save return; } if (!mySavingInProgress.compareAndSet(false, true)) { return; } HeavyProcessLatch.INSTANCE.prioritizeUiActivity(); try { if(!isDefault()) { String projectBasePath = getStateStore().getProjectBasePath(); if (projectBasePath != null) { File projectDir = new File(projectBasePath); File nameFile = new File(projectDir, DIRECTORY_STORE_FOLDER + "/" + NAME_FILE); if (!projectDir.getName().equals(getName())) { try { FileUtil.writeToFile(nameFile, getName()); } catch (IOException e) { LOG.error("Unable to store project name", e); } } else { FileUtil.delete(nameFile); } } } StoreUtil.save(getStateStore(), this); } finally { mySavingInProgress.set(false); ApplicationManager.getApplication().getMessageBus().syncPublisher(ProjectSaved.TOPIC).saved(this); } }
private static void runTaskSynchronously(@Nonnull DumbModeTask task) { ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator(); if (indicator == null) indicator = new EmptyProgressIndicator(); indicator.pushState(); try (AccessToken ignored = HeavyProcessLatch.INSTANCE.processStarted("Performing indexing task")) { task.performInDumbMode(indicator); } finally { indicator.popState(); Disposer.dispose(task); } }
public void load(@Nonnull String configPath, @Nonnull String optionsPath) throws IOException { IApplicationStore store = getStateStore(); store.setOptionsPath(optionsPath); store.setConfigPath(configPath); myIsFiringLoadingEvent = true; try { fireBeforeApplicationLoaded(); } finally { myIsFiringLoadingEvent = false; } AccessToken token = HeavyProcessLatch.INSTANCE.processStarted("Loading application components"); try { store.load(); } catch (StateStorageException e) { throw new IOException(e.getMessage()); } finally { token.finish(); } myLoaded = true; createLocatorFile(); }
private void startWrite(@Nonnull Class clazz) { if (!isWriteAccessAllowed()) { assertIsDispatchThread("Write access is allowed from event dispatch thread only"); } HeavyProcessLatch.INSTANCE.stopThreadPrioritizing(); // let non-cancellable read actions complete faster, if present boolean writeActionPending = myWriteActionPending; if (gatherStatistics && myWriteActionsStack.isEmpty() && !writeActionPending) { ActionPauses.WRITE.started("write action (" + clazz + ")"); } myWriteActionPending = true; try { ActivityTracker.getInstance().inc(); fireBeforeWriteActionStart(clazz); if (!myLock.isWriteLocked() && !myLock.tryWriteLock()) { Future<?> reportSlowWrite = ourDumpThreadsOnLongWriteActionWaiting <= 0 ? null : JobScheduler.getScheduler().scheduleWithFixedDelay(() -> PerformanceWatcher.getInstance().dumpThreads("waiting", true), ourDumpThreadsOnLongWriteActionWaiting, ourDumpThreadsOnLongWriteActionWaiting, TimeUnit.MILLISECONDS); long t = LOG.isDebugEnabled() ? System.currentTimeMillis() : 0; myLock.writeLock(); if (LOG.isDebugEnabled()) { long elapsed = System.currentTimeMillis() - t; if (elapsed != 0) { LOG.debug("Write action wait time: " + elapsed); } } if (reportSlowWrite != null) { reportSlowWrite.cancel(false); } } } finally { myWriteActionPending = writeActionPending; } myWriteActionsStack.push(clazz); fireWriteActionStarted(clazz); }
public void _saveSettings() { if (mySaveSettingsIsInProgress.compareAndSet(false, true)) { HeavyProcessLatch.INSTANCE.prioritizeUiActivity(); try { StoreUtil.save(getStateStore(), null); } finally { mySaveSettingsIsInProgress.set(false); } } }
private void queueSession(@Nonnull RefreshSessionImpl session, @Nullable TransactionId transaction) { myQueue.submit(() -> { myRefreshIndicator.start(); try (AccessToken ignored = HeavyProcessLatch.INSTANCE.processStarted("Doing file refresh. " + session)) { doScan(session); } finally { myRefreshIndicator.stop(); TransactionGuard.getInstance().submitTransaction(ApplicationManager.getApplication(), transaction, session::fireEvents); } }); myEventCounter.eventHappened(session); }
@Override public void run() { ApplicationManager.getApplication().assertIsDispatchThread(); Project project = myProject; DaemonCodeAnalyzerImpl daemonCodeAnalyzer; if (project == null || !project.isInitialized() || project.isDisposed() || PowerSaveMode.isEnabled() || (daemonCodeAnalyzer = (DaemonCodeAnalyzerImpl)DaemonCodeAnalyzer.getInstance(project)).myDisposed) { return; } // wait for heavy processing to stop, re-schedule daemon but not too soon if (HeavyProcessLatch.INSTANCE.isRunning()) { HeavyProcessLatch.INSTANCE.executeOutOfHeavyProcess(() -> daemonCodeAnalyzer.stopProcess(true, "re-scheduled to execute after heavy processing finished")); return; } Editor activeEditor = FileEditorManager.getInstance(project).getSelectedTextEditor(); if (activeEditor == null) { AutoPopupController.runTransactionWithEverythingCommitted(project, daemonCodeAnalyzer.submitPassesRunnable); } else { ((PsiDocumentManagerBase)PsiDocumentManager.getInstance(project)).cancelAndRunWhenAllCommitted("start daemon when all committed", daemonCodeAnalyzer.submitPassesRunnable); } }
private <T> T withLock(Computable<T> computable) { if (ApplicationManager.getApplication().isDispatchThread()) { HeavyProcessLatch.INSTANCE.stopThreadPrioritizing(); } synchronized (myLock) { return computable.compute(); } }
@Override public void reset() { // need this to ensure VFS operations will not block because of storage flushing // and other maintenance IO tasks run in background AccessToken token = HeavyProcessLatch.INSTANCE.processStarted("Resetting Project Structure"); try { myContext.reset(); myProjectSdksModel.reset(); Configurable toSelect = null; for (Configurable each : myName2Config) { if (myUiState.lastEditedConfigurable != null && myUiState.lastEditedConfigurable.equals(each.getDisplayName())) { toSelect = each; } if (each instanceof MasterDetailsComponent) { ((MasterDetailsComponent)each).setHistory(myHistory); } each.reset(); } myHistory.clear(); if (toSelect == null && myName2Config.size() > 0) { toSelect = myName2Config.iterator().next(); } removeSelected(); navigateTo(toSelect != null ? createPlaceFor(toSelect) : null, false); } finally { token.finish(); } }
@Override public void reset() { // need this to ensure VFS operations will not block because of storage flushing // and other maintenance IO tasks run in background AccessToken token = HeavyProcessLatch.INSTANCE.processStarted("Resetting Project Structure"); try { myWasUiDisposed = false; myContext.reset(); myProjectJdksModel.reset(myProject); Configurable toSelect = null; for (Configurable each : myName2Config) { if (myUiState.lastEditedConfigurable != null && myUiState.lastEditedConfigurable.equals(each.getDisplayName())) { toSelect = each; } if (each instanceof MasterDetailsComponent) { ((MasterDetailsComponent)each).setHistory(myHistory); } each.reset(); } myHistory.clear(); if (toSelect == null && myName2Config.size() > 0) { toSelect = myName2Config.iterator().next(); } removeSelected(); navigateTo(toSelect != null ? createPlaceFor(toSelect) : null, false); if (myUiState.proportion > 0) { mySplitter.setProportion(myUiState.proportion); } } finally { token.finish(); } }
private void startBackgroundProcess(final boolean modal) { ProgressManager.getInstance().run(new Task.Backgroundable(myProject, IdeBundle.message("progress.indexing"), false) { @Override public void run(@NotNull final ProgressIndicator visibleIndicator) { final ShutDownTracker shutdownTracker = ShutDownTracker.getInstance(); final Thread self = Thread.currentThread(); AccessToken token = HeavyProcessLatch.INSTANCE.processStarted("Performing indexing tasks"); try { shutdownTracker.registerStopperThread(self); if (visibleIndicator instanceof ProgressIndicatorEx) { ((ProgressIndicatorEx)visibleIndicator).addStateDelegate(new AppIconProgress()); } DumbModeTask task = null; while (true) { Pair<DumbModeTask, ProgressIndicatorEx> pair = getNextTask(task); if (pair == null) break; task = pair.first; ProgressIndicatorEx taskIndicator = pair.second; if (visibleIndicator instanceof ProgressIndicatorEx) { taskIndicator.addStateDelegate(new AbstractProgressIndicatorExBase() { @Override protected void delegateProgressChange(@NotNull IndicatorAction action) { super.delegateProgressChange(action); action.execute((ProgressIndicatorEx)visibleIndicator); } }); } runSingleTask(task, taskIndicator); } } catch (Throwable unexpected) { LOG.error(unexpected); } finally { shutdownTracker.unregisterStopperThread(self); token.finish(); } } public boolean isConditionalModal() { return modal; } @Override public boolean shouldStartInBackground() { return !modal; } }); }
@Override public Object getComponentInstance(@NotNull PicoContainer container) throws PicoInitializationException, PicoIntrospectionException { Object instance = myInitializedComponentInstance; if (instance != null) { return instance; } // we must take read action before adapter lock - if service requested from EDT (2) and pooled (1), will be a deadlock, because EDT waits adapter lock and Pooled waits read lock boolean useReadActionToInitService = isUseReadActionToInitService(); AccessToken readToken = useReadActionToInitService ? ReadAction.start() : null; try { synchronized (this) { instance = myInitializedComponentInstance; if (instance != null) { // DCL is fine, field is volatile return instance; } ComponentAdapter delegate = getDelegate(); // useReadActionToInitService is enabled currently only in internal or test mode or explicitly (registry) - we have enough feedback to fix, so, don't disturb all users if (!useReadActionToInitService && LOG.isDebugEnabled() && ApplicationManager.getApplication().isWriteAccessAllowed() && PersistentStateComponent.class.isAssignableFrom(delegate.getComponentImplementation())) { LOG.warn(new Throwable("Getting service from write-action leads to possible deadlock. Service implementation " + myDescriptor.getImplementation())); } // prevent storages from flushing and blocking FS AccessToken token = HeavyProcessLatch.INSTANCE.processStarted("Creating component '" + myDescriptor.getImplementation() + "'"); try { instance = delegate.getComponentInstance(container); if (instance instanceof Disposable) { Disposer.register(myComponentManager, (Disposable)instance); } myComponentManager.initializeComponent(instance, true); myInitializedComponentInstance = instance; return instance; } finally { token.finish(); } } } finally { if (readToken != null) { readToken.finish(); } } }
@NotNull public static AccessToken workingTreeChangeStarted(@NotNull Project project) { ApplicationManager.getApplication().getMessageBus().syncPublisher(BatchFileChangeListener.TOPIC).batchChangeStarted(project); return HeavyProcessLatch.INSTANCE.processStarted("Changing DVCS working tree"); }
private boolean checkHeavyOperations() { if (myIgnoreBackgroundOperation) return false; return myPlVcsManager.isBackgroundVcsOperationRunning() || myTrackHeavyLatch && HeavyProcessLatch.INSTANCE.isRunning(); }
@NotNull protected DaemonCodeAnalyzerStatus getDaemonCodeAnalyzerStatus(@NotNull SeverityRegistrar severityRegistrar) { DaemonCodeAnalyzerStatus status = new DaemonCodeAnalyzerStatus(); if (myFile == null) { status.reasonWhyDisabled = "No file"; status.errorAnalyzingFinished = true; return status; } if (myProject != null && myProject.isDisposed()) { status.reasonWhyDisabled = "Project is disposed"; status.errorAnalyzingFinished = true; return status; } if (!myDaemonCodeAnalyzer.isHighlightingAvailable(myFile)) { if (!myFile.isPhysical()) { status.reasonWhyDisabled = "File is generated"; status.errorAnalyzingFinished = true; return status; } else if (myFile instanceof PsiCompiledElement) { status.reasonWhyDisabled = "File is decompiled"; status.errorAnalyzingFinished = true; return status; } final FileType fileType = myFile.getFileType(); if (fileType.isBinary()) { status.reasonWhyDisabled = "File is binary"; status.errorAnalyzingFinished = true; return status; } status.reasonWhyDisabled = "Highlighting is disabled for this file"; status.errorAnalyzingFinished = true; return status; } FileViewProvider provider = myFile.getViewProvider(); Set<Language> languages = provider.getLanguages(); HighlightingSettingsPerFile levelSettings = HighlightingSettingsPerFile.getInstance(myProject); boolean shouldHighlight = languages.isEmpty(); for (Language language : languages) { PsiFile root = provider.getPsi(language); FileHighlightingSetting level = levelSettings.getHighlightingSettingForRoot(root); shouldHighlight |= level != FileHighlightingSetting.SKIP_HIGHLIGHTING; } if (!shouldHighlight) { status.reasonWhyDisabled = "Highlighting level is None"; status.errorAnalyzingFinished = true; return status; } if (HeavyProcessLatch.INSTANCE.isRunning()) { status.reasonWhySuspended = StringUtil.defaultIfEmpty(HeavyProcessLatch.INSTANCE.getRunningOperationName(), "Heavy operation is running"); status.errorAnalyzingFinished = true; return status; } status.errorCount = errorCount.clone(); fillDaemonCodeAnalyzerErrorsStatus(status, severityRegistrar); List<TextEditorHighlightingPass> passes = myDaemonCodeAnalyzer.getPassesToShowProgressFor(myDocument); status.passStati = passes.isEmpty() ? Collections.<ProgressableTextEditorHighlightingPass>emptyList() : new ArrayList<ProgressableTextEditorHighlightingPass>(passes.size()); //noinspection ForLoopReplaceableByForEach for (int i = 0; i < passes.size(); i++) { TextEditorHighlightingPass tepass = passes.get(i); if (!(tepass instanceof ProgressableTextEditorHighlightingPass)) continue; ProgressableTextEditorHighlightingPass pass = (ProgressableTextEditorHighlightingPass)tepass; if (pass.getProgress() < 0) continue; status.passStati.add(pass); } status.errorAnalyzingFinished = myDaemonCodeAnalyzer.isAllAnalysisFinished(myFile); status.reasonWhySuspended = myDaemonCodeAnalyzer.isUpdateByTimerEnabled() ? null : "Highlighting is paused temporarily"; return status; }
@Override public void reset() { // need this to ensure VFS operations will not block because of storage flushing // and other maintenance IO tasks run in background HeavyProcessLatch.INSTANCE.processStarted(); try { myWasUiDisposed = false; myContext.reset(); myProjectJdksModel.reset(myProject); Configurable toSelect = null; for (Configurable each : myName2Config) { if (myUiState.lastEditedConfigurable != null && myUiState.lastEditedConfigurable.equals(each.getDisplayName())) { toSelect = each; } if (each instanceof MasterDetailsComponent) { ((MasterDetailsComponent)each).setHistory(myHistory); } each.reset(); } myHistory.clear(); if (toSelect == null && myName2Config.size() > 0) { toSelect = myName2Config.iterator().next(); } removeSelected(); navigateTo(toSelect != null ? createPlaceFor(toSelect) : null, false); if (myUiState.proportion > 0) { mySplitter.setProportion(myUiState.proportion); } } finally { HeavyProcessLatch.INSTANCE.processFinished(); } }
private void runBackgroundProcess(@Nonnull final ProgressIndicator visibleIndicator) { if (!myState.compareAndSet(State.SCHEDULED_TASKS, State.RUNNING_DUMB_TASKS)) return; ProgressSuspender suspender = ProgressSuspender.markSuspendable(visibleIndicator, "Indexing paused"); myCurrentSuspender = suspender; suspendIfRequested(suspender); final ShutDownTracker shutdownTracker = ShutDownTracker.getInstance(); final Thread self = Thread.currentThread(); try { shutdownTracker.registerStopperThread(self); if (visibleIndicator instanceof ProgressIndicatorEx) { ((ProgressIndicatorEx)visibleIndicator).addStateDelegate(new AppIconProgress()); } DumbModeTask task = null; while (true) { Pair<DumbModeTask, ProgressIndicatorEx> pair = getNextTask(task, visibleIndicator); if (pair == null) break; task = pair.first; ProgressIndicatorEx taskIndicator = pair.second; if (visibleIndicator instanceof ProgressIndicatorEx) { taskIndicator.addStateDelegate(new AbstractProgressIndicatorExBase() { @Override protected void delegateProgressChange(@Nonnull IndicatorAction action) { super.delegateProgressChange(action); action.execute((ProgressIndicatorEx)visibleIndicator); } }); } try (AccessToken ignored = HeavyProcessLatch.INSTANCE.processStarted("Performing indexing tasks")) { runSingleTask(task, taskIndicator); } } } catch (Throwable unexpected) { LOG.error(unexpected); } finally { shutdownTracker.unregisterStopperThread(self); myCurrentSuspender = null; } }
private static void checkHeavyProcessRunning() { if (HeavyProcessLatch.INSTANCE.isRunning()) { TimeoutUtil.sleep(1); } }
@Override public Object getComponentInstance(@Nonnull PicoContainer container) throws PicoInitializationException, PicoIntrospectionException { Object instance = myInitializedComponentInstance; if (instance != null) { return instance; } synchronized (this) { instance = myInitializedComponentInstance; if (instance != null) { // DCL is fine, field is volatile return instance; } ComponentAdapter delegate = getDelegate(); if (LOGGER.isDebugEnabled() && ApplicationManager.getApplication().isWriteAccessAllowed() && !ApplicationManager.getApplication().isUnitTestMode() && PersistentStateComponent.class.isAssignableFrom(delegate.getComponentImplementation())) { LOGGER.warn( new Throwable("Getting service from write-action leads to possible deadlock. Service implementation " + myDescriptor.getImplementation())); } // prevent storages from flushing and blocking FS AccessToken token = HeavyProcessLatch.INSTANCE.processStarted("Creating component '" + myDescriptor.getImplementation() + "'"); try { instance = delegate.getComponentInstance(container); if (instance instanceof Disposable) { Disposer.register(myComponentManager, (Disposable)instance); } myComponentManager.initializeComponent(instance, true); myInitializedComponentInstance = instance; return instance; } finally { token.finish(); } } }
@Nonnull public static AccessToken workingTreeChangeStarted(@Nonnull Project project) { ApplicationManager.getApplication().getMessageBus().syncPublisher(BatchFileChangeListener.TOPIC).batchChangeStarted(project); return HeavyProcessLatch.INSTANCE.processStarted("Changing DVCS working tree"); }