]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9946 Background download and "pre-installation" of an edition
authorDuarte Meneses <duarte.meneses@sonarsource.com>
Thu, 19 Oct 2017 14:47:57 +0000 (16:47 +0200)
committerGrégoire Aubert <gregoire.aubert@sonarsource.com>
Mon, 23 Oct 2017 15:01:13 +0000 (08:01 -0700)
server/sonar-server/src/main/java/org/sonar/server/plugins/edition/EditionInstaller.java

index bba40e79e3ca66483ea1d329a3ab0ca6024b339d..f13731a648012c08dbc307ec6de48a4e7477f2f9 100644 (file)
@@ -24,7 +24,7 @@ import java.util.Collection;
 import java.util.Collections;
 import java.util.Map;
 import java.util.Set;
-import java.util.concurrent.locks.ReentrantLock;
+import java.util.concurrent.Semaphore;
 import java.util.stream.Collectors;
 import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
@@ -38,7 +38,7 @@ import org.sonar.updatecenter.common.UpdateCenter;
 public class EditionInstaller {
   private static final Logger LOG = Loggers.get(EditionInstaller.class);
 
-  private final ReentrantLock lock = new ReentrantLock();
+  private final Semaphore semaphore = new Semaphore(1);
   private final EditionInstallerExecutor executor;
   private final EditionPluginDownloader editionPluginDownloader;
   private final EditionPluginUninstaller editionPluginUninstaller;
@@ -64,7 +64,7 @@ public class EditionInstaller {
    * @throws IllegalStateException if an installation is already in progress
    */
   public void install(License newLicense) {
-    if (lock.tryLock()) {
+    if (semaphore.tryAcquire()) {
       try {
         Optional<UpdateCenter> updateCenter = updateCenterMatrixFactory.getUpdateCenter(true);
         if (!updateCenter.isPresent()) {
@@ -74,7 +74,7 @@ public class EditionInstaller {
         editionManagementState.startAutomaticInstall(newLicense);
         executor.execute(() -> asyncInstall(newLicense, updateCenter.get()));
       } catch (RuntimeException e) {
-        lock.unlock();
+        semaphore.release();
         throw e;
       }
     } else {
@@ -117,7 +117,7 @@ public class EditionInstaller {
       LOG.error("Failed to install edition {} with plugins {}", newLicense.getEditionKey(), newLicense.getPluginKeys(), t);
       editionManagementState.installFailed(t.getMessage());
     } finally {
-      lock.unlock();
+      semaphore.release();
     }
   }