]> WPIA git - gigi.git/commitdiff
UPD: document and justify call to System.exit in /kill
authorFelix Dörre <felix@dogcraft.de>
Sat, 28 Feb 2015 22:43:56 +0000 (23:43 +0100)
committerFelix Dörre <felix@dogcraft.de>
Sat, 28 Feb 2015 22:52:15 +0000 (23:52 +0100)
src/org/cacert/gigi/DevelLauncher.java

index 9f1bf066dd810165fbee617371d2e488860a3ca7..97b4b3d52e7b6bd1332aea76ae6b4a679f81bb78 100644 (file)
@@ -43,13 +43,7 @@ public class DevelLauncher {
             }
             i++;
         }
-        try {
-            String targetPort = mainProps.getProperty("http.port");
-            String targetHost = mainProps.getProperty("name.www");
-            URL u = new URL("http://" + targetHost + ":" + targetPort + "/kill");
-            u.openStream();
-        } catch (IOException e) {
-        }
+        killPreviousInstance(mainProps);
 
         ByteArrayOutputStream chunkConfig = new ByteArrayOutputStream();
         DataOutputStream dos = new DataOutputStream(chunkConfig);
@@ -70,6 +64,16 @@ public class DevelLauncher {
         System.exit(0);
     }
 
+    private static void killPreviousInstance(Properties mainProps) {
+        try {
+            String targetPort = mainProps.getProperty("http.port");
+            String targetHost = mainProps.getProperty("name.www");
+            URL u = new URL("http://" + targetHost + ":" + targetPort + "/kill");
+            u.openStream();
+        } catch (IOException e) {
+        }
+    }
+
     public static void addDevelPage() {
         try {
             Field instF = Gigi.class.getDeclaredField("instance");
@@ -102,6 +106,14 @@ public class DevelLauncher {
 
             pages.put("/kill", new Page("Kill") {
 
+                /**
+                 * The contained call to {@link System#exit(int)} is mainly
+                 * needed to kill this instance immediately if another
+                 * {@link DevelLauncher} is booting up to free all ports This is
+                 * required for fast development cycles.
+                 * 
+                 * @see #killPreviousInstance(Properties)
+                 */
                 @Override
                 public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
                     System.exit(0);