import static org.argeo.api.cms.CmsConstants.CONTEXT_PATH;
import java.util.Map;
+import java.util.Objects;
import java.util.TreeMap;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.CompletionStage;
import org.argeo.api.cms.CmsConstants;
import org.argeo.api.cms.CmsDeployment;
import org.argeo.api.cms.CmsLog;
+import org.argeo.api.cms.CmsSshd;
import org.argeo.api.cms.CmsState;
import org.argeo.cms.CmsDeployProperty;
-import org.argeo.cms.CmsSshd;
import org.argeo.cms.internal.http.CmsAuthenticator;
import org.argeo.cms.internal.http.PublicCmsAuthenticator;
private boolean sshdExpected = false;
// HTTP
- private HttpServer httpServer;
+ private CompletableFuture<HttpServer> httpServer = new CompletableFuture<>();
private Map<String, HttpHandler> httpHandlers = new TreeMap<>();
private Map<String, CmsAuthenticator> httpAuthenticators = new TreeMap<>();
// SSHD
- private CmsSshd cmsSshd;
+ private CompletableFuture<CmsSshd> cmsSshd = new CompletableFuture<>();
public void start() {
log.debug(() -> "CMS deployment available");
String httpPort = this.cmsState.getDeployProperty(CmsDeployProperty.HTTP_PORT.getProperty());
String httpsPort = this.cmsState.getDeployProperty(CmsDeployProperty.HTTPS_PORT.getProperty());
httpExpected = httpPort != null || httpsPort != null;
+ if (!httpExpected)
+ httpServer.complete(null);
String sshdPort = this.cmsState.getDeployProperty(CmsDeployProperty.SSHD_PORT.getProperty());
sshdExpected = sshdPort != null;
+ if (!sshdExpected)
+ cmsSshd.complete(null);
}
public void setHttpServer(HttpServer httpServer) {
- this.httpServer = httpServer;
+ Objects.requireNonNull(httpServer);
+ this.httpServer.complete(httpServer);
// create contexts whose handles had already been published
for (String contextPath : httpHandlers.keySet()) {
HttpHandler httpHandler = httpHandlers.get(contextPath);
}
public void createHttpContext(String contextPath, HttpHandler httpHandler, CmsAuthenticator authenticator) {
- HttpContext httpContext = httpServer.createContext(contextPath);
+ HttpContext httpContext = httpServer.join().createContext(contextPath);
// we want to set the authenticator BEFORE the handler actually becomes active
httpContext.setAuthenticator(authenticator);
httpContext.setHandler(httpHandler);
httpHandlers.remove(contextPath);
if (httpServer == null)
return;
- httpServer.removeContext(contextPath);
+ httpServer.join().removeContext(contextPath);
log.debug(() -> "Removed handler " + contextPath + " : " + httpHandler.getClass().getName());
}
}
public void setCmsSshd(CmsSshd cmsSshd) {
- this.cmsSshd = cmsSshd;
+ Objects.requireNonNull(cmsSshd);
+ this.cmsSshd.complete(cmsSshd);
+ }
+
+ @Override
+ public CompletionStage<HttpServer> getHttpServer() {
+ return httpServer.minimalCompletionStage();
+ }
+
+ @Override
+ public CompletionStage<CmsSshd> getCmsSshd() {
+ return cmsSshd.minimalCompletionStage();
}
}