Merge remote-tracking branch 'origin/merge/Jalview-JS/develop_feature/JAL-3690_callba...
[jalview.git] / src / jalview / httpserver / HttpServer.java
index 134123b..7021fae 100644 (file)
@@ -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,39 +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<Handler, ContextHandler> myHandlers = new HashMap<Handler, ContextHandler>();
-
-  /*
-   * The context root for the server
-   */
-  private URI contextRoot;
-
   /**
    * Returns the singleton instance of this class.
    * 
@@ -92,14 +63,10 @@ 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
    * 
@@ -116,6 +83,34 @@ 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<Handler, ContextHandler> myHandlers = new HashMap<Handler, ContextHandler>();
+
+  /*
+   * The context root for the server
+   */
+  private URI contextRoot;
+
+
   /**
    * Start the http server
    * 
@@ -156,8 +151,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 +262,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));