The Equinox Jetty bundle should not be explicitly started anymore.
[lgpl/argeo-commons.git] / org.argeo.cms / src / org / argeo / cms / internal / kernel / CmsDeployment.java
index 3d8a389efd13bbe1b3c56765bc3e0aa192bc0db2..20418ec4d21e803890e838abdfaec1b092a24337 100644 (file)
@@ -34,6 +34,7 @@ import org.argeo.node.security.CryptoKeyring;
 import org.argeo.node.security.Keyring;
 import org.argeo.osgi.useradmin.UserAdminConf;
 import org.argeo.util.LangUtils;
+import org.eclipse.equinox.http.jetty.JettyConfigurator;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
@@ -192,12 +193,25 @@ public class CmsDeployment implements NodeDeployment {
        public void shutdown() {
                if (nodeHttp != null)
                        nodeHttp.destroy();
+
+               try {
+                       JettyConfigurator.stopServer(KernelConstants.DEFAULT_JETTY_SERVER);
+               } catch (Exception e) {
+                       log.error("Cannot stop default Jetty server.", e);
+               }
+
                if (deployConfig != null) {
                        new Thread(() -> deployConfig.save(), "Save Argeo Deploy Config").start();
                }
        }
 
-       private void checkReadiness() {
+       /**
+        * Checks whether the deployment is available according to expectations, and
+        * mark it as available.
+        */
+       private synchronized void checkReadiness() {
+               if (isAvailable())
+                       return;
                if (nodeAvailable && userAdminAvailable && (httpExpected ? httpAvailable : true)) {
                        String data = KernelUtils.getFrameworkProp(KernelUtils.OSGI_INSTANCE_AREA);
                        String state = KernelUtils.getFrameworkProp(KernelUtils.OSGI_CONFIGURATION_AREA);
@@ -364,15 +378,19 @@ public class CmsDeployment implements NodeDeployment {
                        properties.put(Constants.SERVICE_RANKING, Integer.MAX_VALUE);
                LocalRepository localRepository = new LocalRepository(repository, dataModelName);
                bc.registerService(Repository.class, localRepository, properties);
-               if (log.isDebugEnabled())
-                       log.debug("Published data model " + dataModelName);
+               if (log.isTraceEnabled())
+                       log.trace("Published data model " + dataModelName);
        }
 
        @Override
-       public Long getAvailableSince() {
+       public synchronized Long getAvailableSince() {
                return availableSince;
        }
 
+       public synchronized boolean isAvailable() {
+               return availableSince != null;
+       }
+
        private class RepositoryContextStc extends ServiceTracker<RepositoryContext, RepositoryContext> {
 
                public RepositoryContextStc() {