From 3badd476071ad30333b9a1a4080531e84953b6e4 Mon Sep 17 00:00:00 2001 From: Duarte Meneses Date: Wed, 30 Sep 2015 15:16:18 +0200 Subject: [PATCH] Change global cache strategy --- .../batch/bootstrap/GlobalContainer.java | 24 +++++++++++++------ .../org/sonar/batch/bootstrapper/Batch.java | 4 ++-- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalContainer.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalContainer.java index 30b54799632..ebcc795c9e5 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalContainer.java +++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalContainer.java @@ -52,16 +52,16 @@ import org.sonar.core.util.UuidFactoryImpl; public class GlobalContainer extends ComponentContainer { private final Map bootstrapProperties; - private boolean forceSync; + private boolean preferCache; - private GlobalContainer(Map bootstrapProperties, boolean forceSync) { + private GlobalContainer(Map bootstrapProperties, boolean preferCache) { super(); this.bootstrapProperties = bootstrapProperties; - this.forceSync = forceSync; + this.preferCache = preferCache; } - public static GlobalContainer create(Map bootstrapProperties, List extensions, boolean forceSync) { - GlobalContainer container = new GlobalContainer(bootstrapProperties, forceSync); + public static GlobalContainer create(Map bootstrapProperties, List extensions, boolean preferCache) { + GlobalContainer container = new GlobalContainer(bootstrapProperties, preferCache); container.add(extensions); return container; } @@ -69,12 +69,23 @@ public class GlobalContainer extends ComponentContainer { @Override protected void doBeforeStart() { GlobalProperties bootstrapProps = new GlobalProperties(bootstrapProperties); - StrategyWSLoaderProvider wsLoaderProvider = forceSync ? new StrategyWSLoaderProvider(LoadStrategy.SERVER_ONLY) : new StrategyWSLoaderProvider(LoadStrategy.SERVER_FIRST); + GlobalMode globalMode = new GlobalMode(bootstrapProps); + LoadStrategy strategy = getDataLoadingStrategy(globalMode, preferCache); + StrategyWSLoaderProvider wsLoaderProvider = new StrategyWSLoaderProvider(strategy); add(wsLoaderProvider); add(bootstrapProps); + add(globalMode); addBootstrapComponents(); } + private static LoadStrategy getDataLoadingStrategy(GlobalMode mode, boolean preferCache) { + if (!mode.isIssues()) { + return LoadStrategy.SERVER_ONLY; + } + + return preferCache ? LoadStrategy.CACHE_FIRST : LoadStrategy.SERVER_FIRST; + } + private void addBootstrapComponents() { add( // plugins @@ -86,7 +97,6 @@ public class GlobalContainer extends ComponentContainer { ExtensionInstaller.class, CachesManager.class, - GlobalMode.class, GlobalSettings.class, new RulesProvider(), ServerClient.class, diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/Batch.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/Batch.java index e98e6366f7a..116272c6a20 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/Batch.java +++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/Batch.java @@ -89,13 +89,13 @@ public final class Batch { return start(false); } - public synchronized Batch start(boolean forceSync) { + public synchronized Batch start(boolean preferCache) { if (started) { throw new IllegalStateException("Batch is already started"); } configureLogging(); - bootstrapContainer = GlobalContainer.create(bootstrapProperties, components, forceSync); + bootstrapContainer = GlobalContainer.create(bootstrapProperties, components, preferCache); bootstrapContainer.startComponents(); this.started = true; -- 2.39.5