]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6365 use an enum to represent status of Platform
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Tue, 5 May 2015 08:10:23 +0000 (10:10 +0200)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Mon, 11 May 2015 10:28:54 +0000 (12:28 +0200)
using an enum allows testing all possible state of the Platform class based on a single value instead of combining multiple sequential method call which can return an inconsistent result of state changes in between method calls

server/sonar-server/src/main/java/org/sonar/server/platform/Platform.java

index 519f13ad49cbaa01139f055f167a37fb2dbc1be3..c61524fca3af25cdb000d89f97b88c02c01a0cbf 100644 (file)
@@ -124,11 +124,24 @@ public class Platform {
   }
 
   public boolean isStarted() {
-    return started && !isInSafeMode();
+    return status() == Status.UP;
   }
 
   public boolean isInSafeMode() {
-    return started && safeModeContainer != null && currentContainer == safeModeContainer;
+    return status() == Status.SAFEMODE;
+  }
+
+  public Status status() {
+    if (!started) {
+      return Status.BOOTING;
+    }
+    if (safeModeContainer != null && currentContainer == safeModeContainer) {
+      return Status.SAFEMODE;
+    }
+    if (currentContainer == level4Container) {
+      return Status.UP;
+    }
+    return Status.BOOTING;
   }
 
   /**
@@ -239,4 +252,8 @@ public class Platform {
   public Object getComponent(Object key) {
     return getContainer().getComponentByKey(key);
   }
+
+  public static enum Status {
+    BOOTING, SAFEMODE, UP;
+  }
 }