diff --git a/plugins/jps-cache/src/com/intellij/jps/cache/loader/JpsCacheLoader.java b/plugins/jps-cache/src/com/intellij/jps/cache/loader/JpsCacheLoader.java index ee97ca36f853..1f5e472a98a6 100644 --- a/plugins/jps-cache/src/com/intellij/jps/cache/loader/JpsCacheLoader.java +++ b/plugins/jps-cache/src/com/intellij/jps/cache/loader/JpsCacheLoader.java @@ -14,7 +14,6 @@ import org.jetbrains.annotations.Nullable; import java.io.File; import java.io.IOException; -import java.util.concurrent.ExecutorService; class JpsCacheLoader implements JpsOutputLoader { private static final Logger LOG = Logger.getInstance("com.intellij.jps.loader.JpsCacheLoader"); @@ -45,8 +44,7 @@ class JpsCacheLoader implements JpsOutputLoader { } @Override - public LoaderStatus extract(@Nullable Object loadResults, @NotNull ExecutorService executorService, - @NotNull SegmentedProgressIndicatorManager extractIndicatorManager) { + public LoaderStatus extract(@Nullable Object loadResults, @NotNull SegmentedProgressIndicatorManager extractIndicatorManager) { if (!(loadResults instanceof File)) return LoaderStatus.FAILED; File zipFile = (File) loadResults; @@ -86,7 +84,7 @@ class JpsCacheLoader implements JpsOutputLoader { } @Override - public void apply(@NotNull ExecutorService executorService, @NotNull SegmentedProgressIndicatorManager indicatorManager) { + public void apply(@NotNull SegmentedProgressIndicatorManager indicatorManager) { if (myTmpCacheFolder == null) { LOG.warn("Nothing to apply, download results are empty"); return; diff --git a/plugins/jps-cache/src/com/intellij/jps/cache/loader/JpsCompilationOutputLoader.java b/plugins/jps-cache/src/com/intellij/jps/cache/loader/JpsCompilationOutputLoader.java index 0f39f1124aa7..02fa1bdc9022 100644 --- a/plugins/jps-cache/src/com/intellij/jps/cache/loader/JpsCompilationOutputLoader.java +++ b/plugins/jps-cache/src/com/intellij/jps/cache/loader/JpsCompilationOutputLoader.java @@ -38,15 +38,15 @@ class JpsCompilationOutputLoader implements JpsOutputLoader myOldModulesPaths; + private final ExecutorService myExecutorService; private Map myTmpFolderToModuleName; - JpsCompilationOutputLoader(JpsServerClient client, Project project) { + JpsCompilationOutputLoader(@NotNull JpsServerClient client, Project project, @NotNull ExecutorService executorService) { myClient = client; - myProject = project; - myProjectPath = myProject.getBasePath(); + myExecutorService = executorService; + myProjectPath = project.getBasePath(); } @Override @@ -77,8 +77,7 @@ class JpsCompilationOutputLoader implements JpsOutputLoader> futureList = ContainerUtil.map(outputLoadResults, loadResult -> - executorService.submit(new UnzipOutputTask(result, loadResult, extractIndicatorManager))); + myExecutorService.submit(new UnzipOutputTask(result, loadResult, extractIndicatorManager))); for (Future future : futureList) { future.get(); } @@ -116,7 +115,7 @@ class JpsCompilationOutputLoader implements JpsOutputLoader executorService.submit(() -> { + entry -> myExecutorService.submit(() -> { String moduleName = entry.getValue(); File tmpModuleFolder = entry.getKey(); SegmentedProgressIndicatorManager.SubTaskProgressIndicator subTaskIndicator = diff --git a/plugins/jps-cache/src/com/intellij/jps/cache/loader/JpsOutputLoader.java b/plugins/jps-cache/src/com/intellij/jps/cache/loader/JpsOutputLoader.java index 6a1db9f89fe7..4ada2a5bb8ca 100644 --- a/plugins/jps-cache/src/com/intellij/jps/cache/loader/JpsOutputLoader.java +++ b/plugins/jps-cache/src/com/intellij/jps/cache/loader/JpsOutputLoader.java @@ -7,13 +7,12 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.Map; -import java.util.concurrent.ExecutorService; interface JpsOutputLoader { T load(@NotNull JpsLoaderContext context); - LoaderStatus extract(@Nullable Object loadResults, @NotNull ExecutorService executorService, @NotNull SegmentedProgressIndicatorManager extractIndicatorManager); + LoaderStatus extract(@Nullable Object loadResults, @NotNull SegmentedProgressIndicatorManager extractIndicatorManager); void rollback(); - void apply(@NotNull ExecutorService executorService, @NotNull SegmentedProgressIndicatorManager indicatorManager); + void apply(@NotNull SegmentedProgressIndicatorManager indicatorManager); default int calculateDownloads(@NotNull Map> commitSourcesState, @Nullable Map> currentSourcesState) { return 1; diff --git a/plugins/jps-cache/src/com/intellij/jps/cache/loader/JpsOutputLoaderManager.java b/plugins/jps-cache/src/com/intellij/jps/cache/loader/JpsOutputLoaderManager.java index c07962ab07bf..0fbf9fe5fb06 100644 --- a/plugins/jps-cache/src/com/intellij/jps/cache/loader/JpsOutputLoaderManager.java +++ b/plugins/jps-cache/src/com/intellij/jps/cache/loader/JpsOutputLoaderManager.java @@ -2,7 +2,6 @@ package com.intellij.jps.cache.loader; import com.intellij.compiler.CompilerWorkspaceConfiguration; import com.intellij.compiler.server.BuildManager; -import com.intellij.execution.process.ProcessIOExecutorService; import com.intellij.ide.util.PropertiesComponent; import com.intellij.jps.cache.client.JpsServerClient; import com.intellij.jps.cache.git.GitRepositoryUtil; @@ -29,13 +28,13 @@ import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.io.File; import java.util.*; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.atomic.AtomicBoolean; +import static com.intellij.execution.process.ProcessIOExecutorService.INSTANCE; import static com.intellij.jps.cache.ui.JpsLoaderNotifications.NONE_NOTIFICATION_GROUP; import static com.intellij.jps.cache.ui.JpsLoaderNotifications.STICKY_NOTIFICATION_GROUP; @@ -45,7 +44,7 @@ public class JpsOutputLoaderManager { private static final String PROGRESS_TITLE = "Updating Compiler Caches"; private static final double SEGMENT_SIZE = 0.33; private final AtomicBoolean hasRunningTask; - private final ExecutorService ourThreadPool; + private final ExecutorService myExecutorService; private final CompilerWorkspaceConfiguration myWorkspaceConfiguration; private List> myJpsOutputLoadersLoaders; private final JpsMetadataLoader myMetadataLoader; @@ -66,9 +65,9 @@ public class JpsOutputLoaderManager { // Configure build manager BuildManager buildManager = BuildManager.getInstance(); if (!buildManager.isGeneratePortableCachesEnabled()) buildManager.setGeneratePortableCachesEnabled(true); - ourThreadPool = AppExecutorUtil.createBoundedApplicationPoolExecutor("JpsCacheLoader Pool", - ProcessIOExecutorService.INSTANCE, - getThreadPoolSize()); + myExecutorService = AppExecutorUtil.createBoundedApplicationPoolExecutor("JpsCacheLoader Pool", + INSTANCE, + getThreadPoolSize()); } public void load(boolean isForceUpdate) { @@ -92,7 +91,7 @@ public class JpsOutputLoaderManager { } public void notifyAboutNearestCache() { - ourThreadPool.execute(() -> { + INSTANCE.execute(() -> { Pair commitInfo = getNearestCommit(false); if (commitInfo == null) return; @@ -208,10 +207,7 @@ public class JpsOutputLoaderManager { // Start loaders with own context List> completableFutures = ContainerUtil.map(loaders, loader -> - CompletableFuture.supplyAsync(() -> { - Object loadResults = loader.load(loaderContext); - return loader.extract(loadResults, ourThreadPool, extractIndicatorManager); - }, ourThreadPool)); + CompletableFuture.supplyAsync(() -> loader.extract(loader.load(loaderContext), extractIndicatorManager), INSTANCE)); // Reduce loaders statuses into the one CompletableFuture initialFuture = completableFutures.get(0); @@ -223,13 +219,13 @@ public class JpsOutputLoaderManager { return initialFuture; } - private CompletableFuture applyChanges(LoaderStatus loaderStatus, JpsOutputLoader loader, ProgressIndicator indicator, - SegmentedProgressIndicatorManager indicatorManager) { + private static CompletableFuture applyChanges(LoaderStatus loaderStatus, JpsOutputLoader loader, ProgressIndicator indicator, + SegmentedProgressIndicatorManager indicatorManager) { if (loaderStatus == LoaderStatus.FAILED) { indicator.setText("Rolling back"); - return CompletableFuture.runAsync(() -> loader.rollback(), ourThreadPool); + return CompletableFuture.runAsync(() -> loader.rollback(), INSTANCE); } - return CompletableFuture.runAsync(() -> loader.apply(ourThreadPool, indicatorManager), ourThreadPool); + return CompletableFuture.runAsync(() -> loader.apply(indicatorManager), INSTANCE); } private void saveStateAndNotify(LoaderStatus loaderStatus, String commitId, long startTime) { @@ -268,7 +264,7 @@ public class JpsOutputLoaderManager { private List> getLoaders(@NotNull Project project) { if (myJpsOutputLoadersLoaders != null) return myJpsOutputLoadersLoaders; - myJpsOutputLoadersLoaders = Arrays.asList(new JpsCompilationOutputLoader(myServerClient, project), + myJpsOutputLoadersLoaders = Arrays.asList(new JpsCompilationOutputLoader(myServerClient, project, myExecutorService), new JpsCacheLoader(myServerClient, project)); return myJpsOutputLoadersLoaders; } diff --git a/plugins/jps-cache/tests/com/intellij/jps/cache/loader/JpsCompilationOutputLoaderTest.java b/plugins/jps-cache/tests/com/intellij/jps/cache/loader/JpsCompilationOutputLoaderTest.java index ef52b4199d1e..07a63ade0494 100644 --- a/plugins/jps-cache/tests/com/intellij/jps/cache/loader/JpsCompilationOutputLoaderTest.java +++ b/plugins/jps-cache/tests/com/intellij/jps/cache/loader/JpsCompilationOutputLoaderTest.java @@ -8,6 +8,7 @@ import com.intellij.jps.cache.model.AffectedModule; import com.intellij.jps.cache.model.BuildTargetState; import com.intellij.openapi.application.PluginPathManager; import com.intellij.testFramework.fixtures.BasePlatformTestCase; +import com.intellij.util.ConcurrencyUtil; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; @@ -29,7 +30,8 @@ public class JpsCompilationOutputLoaderTest extends BasePlatformTestCase { @Override public void setUp() throws Exception { super.setUp(); - compilationOutputLoader = new JpsCompilationOutputLoader(JpsServerClient.getServerClient(), getProject()); + compilationOutputLoader = new JpsCompilationOutputLoader(JpsServerClient.getServerClient(), getProject(), + ConcurrencyUtil.newSingleThreadExecutor("JpsCompilationOutputLoaderTest")); myGson = new Gson(); myTokenType = new TypeToken>>() {}.getType(); }