X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fhttpserver%2FHttpServer.java;h=8797f331bfb7a10b6f7dd379ff9d6842ba28b08e;hb=47806656477f02076cac0467c7374e231a59ab7e;hp=59eef26d9f3d2cdcd90ae9194aace48fc6544953;hpb=4d7f98a6dd54d9863ba449ec79dcd95d25ed863d;p=jalview.git
diff --git a/src/jalview/httpserver/HttpServer.java b/src/jalview/httpserver/HttpServer.java
index 59eef26..8797f33 100644
--- a/src/jalview/httpserver/HttpServer.java
+++ b/src/jalview/httpserver/HttpServer.java
@@ -1,5 +1,26 @@
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see .
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
package jalview.httpserver;
+import jalview.bin.Instance;
import jalview.rest.RestHandler;
import java.net.BindException;
@@ -31,36 +52,6 @@ import org.eclipse.jetty.util.thread.QueuedThreadPool;
*/
public class HttpServer
{
- /*
- * '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.
@@ -72,22 +63,22 @@ public class HttpServer
{
synchronized (HttpServer.class)
{
- if (instance == null)
- {
- instance = new HttpServer();
- }
- return instance;
+ Instance j = Instance.getInstance();
+ return (j.httpServer == null ? j.httpServer = new HttpServer()
+ : j.httpServer);
}
}
/**
- * 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();
/*
@@ -96,6 +87,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
*
@@ -136,8 +153,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();
@@ -247,8 +264,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));