X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fhttpserver%2FHttpServer.java;h=8cb184625c37e95e71775812d56ac04c74360b79;hb=418006c3714eb8da78234660698231597eb90fb1;hp=3d903f8f585a87a3c840467f812a5b36fb2f6045;hpb=c19d2a91ca05e052e3408bf5852d88eb5d0608f1;p=jalview.git diff --git a/src/jalview/httpserver/HttpServer.java b/src/jalview/httpserver/HttpServer.java index 3d903f8..8cb1846 100644 --- a/src/jalview/httpserver/HttpServer.java +++ b/src/jalview/httpserver/HttpServer.java @@ -1,6 +1,6 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer (Version 2.9.0b2) - * Copyright (C) 2015 The Jalview Authors + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors * * This file is part of Jalview. * @@ -20,6 +20,8 @@ */ package jalview.httpserver; +import jalview.bin.ApplicationSingletonProvider; +import jalview.bin.ApplicationSingletonProvider.ApplicationSingletonI; import jalview.rest.RestHandler; import java.net.BindException; @@ -49,38 +51,8 @@ import org.eclipse.jetty.util.thread.QueuedThreadPool; * @author gmcarstairs * @see http://eclipse.org/jetty/documentation/current/embedding-jetty.html */ -public class HttpServer +public class HttpServer implements ApplicationSingletonI { - /* - * 'context root' - actually just prefixed to the path for each handler for - * now - see registerHandler - */ - private static final String JALVIEW_PATH = "jalview"; - - /* - * Singleton instance of this server - */ - private static HttpServer instance; - - /* - * The Http server - */ - private Server server; - - /* - * Registered handlers for context paths - */ - private HandlerCollection contextHandlers; - - /* - * Lookup of ContextHandler by its wrapped handler - */ - Map myHandlers = new HashMap(); - - /* - * The context root for the server - */ - private URI contextRoot; /** * Returns the singleton instance of this class. @@ -92,22 +64,20 @@ public class HttpServer { synchronized (HttpServer.class) { - if (instance == null) - { - instance = new HttpServer(); - } - return instance; + return (HttpServer) ApplicationSingletonProvider.getInstance(HttpServer.class); } } /** - * Private constructor to enforce use of singleton + * Private constructor to enforce use of singleton; use getInstance(). * * @throws BindException * if no free port can be assigned */ private HttpServer() throws BindException { + // use getInstance() + startServer(); /* @@ -116,6 +86,32 @@ public class HttpServer registerHandler(RestHandler.getInstance()); } + /* + * 'context root' - actually just prefixed to the path for each handler for + * now - see registerHandler + */ + private static final String JALVIEW_PATH = "jalview"; + + /* + * The Http server + */ + private Server server; + + /* + * Registered handlers for context paths + */ + private HandlerCollection contextHandlers; + + /* + * Lookup of ContextHandler by its wrapped handler + */ + Map myHandlers = new HashMap<>(); + + /* + * The context root for the server + */ + private URI contextRoot; + /** * Start the http server * @@ -156,8 +152,8 @@ public class HttpServer contextRoot = server.getURI(); } catch (Exception e) { - System.err.println("Error trying to start HttpServer: " - + e.getMessage()); + System.err.println( + "Error trying to start HttpServer: " + e.getMessage()); try { server.stop(); @@ -267,8 +263,8 @@ public class HttpServer ch.start(); } catch (Exception e) { - System.err.println("Error starting handler for " + path + ": " - + e.getMessage()); + System.err.println( + "Error starting handler for " + path + ": " + e.getMessage()); } handler.setUri(this.contextRoot + ch.getContextPath().substring(1));