Improve CMS start up and status reporting.
[lgpl/argeo-commons.git] / org.argeo.cms / src / org / argeo / cms / internal / runtime / CmsContextImpl.java
index 7a0f3388c07a4f79cabdd6928de9fa210e3bc511..940e329a358fd8deab1a717d5471772d1d042eb2 100644 (file)
@@ -91,7 +91,16 @@ public class CmsContextImpl implements CmsContext {
 //
 //             }.open();
 
-               checkReadiness();
+               new Thread(() -> {
+                       while (!checkReadiness()) {
+                               try {
+                                       Thread.sleep(500);
+                               } catch (InterruptedException e) {
+                               }
+                       }
+               }, "Check readiness").start();
+               
+               // checkReadiness();
 
                setInstance(this);
        }
@@ -104,10 +113,13 @@ public class CmsContextImpl implements CmsContext {
         * Checks whether the deployment is available according to expectations, and
         * mark it as available.
         */
-       private void checkReadiness() {
+       private boolean checkReadiness() {
                if (isAvailable())
-                       return;
-               if (cmsDeployment != null && userAdmin != null) {
+                       return true;
+               if (cmsDeployment == null)
+                       return false;
+
+               if (((CmsDeploymentImpl) cmsDeployment).allExpectedServicesAvailable() && userAdmin != null) {
                        String data = KernelUtils.getFrameworkProp(KernelUtils.OSGI_INSTANCE_AREA);
                        String state = KernelUtils.getFrameworkProp(KernelUtils.OSGI_CONFIGURATION_AREA);
                        availableSince = System.currentTimeMillis();
@@ -124,8 +136,11 @@ public class CmsContextImpl implements CmsContext {
                        if (log.isTraceEnabled())
                                log.trace("Kernel initialization took " + initDuration + "ms");
                        tributeToFreeSoftware(initDuration);
+
+                       return true;
                } else {
-                       throw new IllegalStateException("Deployment is not available");
+                       return false;
+                       // throw new IllegalStateException("Deployment is not available");
                }
        }