JAL-3253 preliminary static fixes for JavaScript part 3 of 3
[jalview.git] / src / jalview / httpserver / HttpServer.java
index a18d38d..58e792d 100644 (file)
@@ -20,6 +20,7 @@
  */
 package jalview.httpserver;
 
+import jalview.bin.Jalview;
 import jalview.rest.RestHandler;
 
 import java.net.BindException;
@@ -57,10 +58,21 @@ public class HttpServer
    */
   private static final String JALVIEW_PATH = "jalview";
 
-  /*
-   * Singleton instance of this server
+  /**
+   * Returns the singleton instance of this class.
+   * 
+   * @return
+   * @throws BindException
    */
-  private static HttpServer instance;
+  public static HttpServer getInstance() throws BindException
+  {
+    synchronized (HttpServer.class)
+    {
+      Jalview j = Jalview.getInstance();
+      return (j.httpServer == null ? j.httpServer = new HttpServer()
+              : j.httpServer);
+    }
+  }
 
   /*
    * The Http server
@@ -75,7 +87,7 @@ public class HttpServer
   /*
    * Lookup of ContextHandler by its wrapped handler
    */
-  Map<Handler, ContextHandler> myHandlers = new HashMap<Handler, ContextHandler>();
+  Map<Handler, ContextHandler> myHandlers = new HashMap<>();
 
   /*
    * The context root for the server
@@ -83,24 +95,6 @@ public class HttpServer
   private URI contextRoot;
 
   /**
-   * Returns the singleton instance of this class.
-   * 
-   * @return
-   * @throws BindException
-   */
-  public static HttpServer getInstance() throws BindException
-  {
-    synchronized (HttpServer.class)
-    {
-      if (instance == null)
-      {
-        instance = new HttpServer();
-      }
-      return instance;
-    }
-  }
-
-  /**
    * Private constructor to enforce use of singleton
    * 
    * @throws BindException