SLING-6357 - Allow to extend LoginAdminWhitelist with multiple configurations

- always initialize repo asynchronously in order to allow additional services to be registered

git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/jcr/base@1773070 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/main/java/org/apache/sling/jcr/base/AbstractSlingRepositoryManager.java b/src/main/java/org/apache/sling/jcr/base/AbstractSlingRepositoryManager.java
index 7153178..bdbdcbc 100644
--- a/src/main/java/org/apache/sling/jcr/base/AbstractSlingRepositoryManager.java
+++ b/src/main/java/org/apache/sling/jcr/base/AbstractSlingRepositoryManager.java
@@ -22,6 +22,7 @@
 import java.util.Arrays;
 import java.util.Dictionary;
 import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
 
 import javax.jcr.Repository;
 
@@ -326,6 +327,15 @@
     protected final boolean start(final BundleContext bundleContext, final String defaultWorkspace,
                                   final boolean disableLoginAdministrative) {
         start(bundleContext, new Config(defaultWorkspace, disableLoginAdministrative));
+        long end = System.currentTimeMillis() + 5000; // wait up to 5 seconds for repository registration
+        while (!isRepositoryServiceRegistered() && end > System.currentTimeMillis()) {
+            try {
+                TimeUnit.MILLISECONDS.sleep(100);
+            } catch (InterruptedException e) {
+                Thread.currentThread().interrupt();
+                break;
+            }
+        }
         return isRepositoryServiceRegistered();
     }
 
@@ -434,24 +444,20 @@
             whitelistTracker.open();
         }
 
-        if (waitForWhitelist.getCount() > 0) {
-            // start repository asynchronously to allow LoginAdminWhitelist to become available
-            // NOTE: making this conditional allows tests to register a mock whitelist before
-            // activating the RepositoryManager, so they don't need to deal with async startup
-            new Thread("Apache Sling Repository Startup Thread") {
-                @Override
-                public void run() {
-                    try {
-                        waitForWhitelist.await();
-                        initializeAndRegisterRepositoryService();
-                    } catch (InterruptedException e) {
-                        throw new RuntimeException("Interrupted while waiting for LoginAdminWhitelist", e);
-                    }
+        // start repository asynchronously to allow LoginAdminWhitelist to become available
+        // NOTE: making this conditional allows tests to register a mock whitelist before
+        // activating the RepositoryManager, so they don't need to deal with async startup
+        new Thread("Apache Sling Repository Startup Thread") {
+            @Override
+            public void run() {
+                try {
+                    waitForWhitelist.await();
+                    initializeAndRegisterRepositoryService();
+                } catch (InterruptedException e) {
+                    throw new RuntimeException("Interrupted while waiting for LoginAdminWhitelist", e);
                 }
-            }.start();
-        } else {
-            initializeAndRegisterRepositoryService();
-        }
+            }
+        }.start();
     }
 
     private boolean isRepositoryServiceRegistered() {