From a27f7699f3318e686ef37e834d81f03972e239cb Mon Sep 17 00:00:00 2001 From: =?utf8?q?Felix=20D=C3=B6rre?= Date: Sat, 28 Feb 2015 23:43:56 +0100 Subject: [PATCH] UPD: document and justify call to System.exit in /kill --- src/org/cacert/gigi/DevelLauncher.java | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/org/cacert/gigi/DevelLauncher.java b/src/org/cacert/gigi/DevelLauncher.java index 9f1bf066..97b4b3d5 100644 --- a/src/org/cacert/gigi/DevelLauncher.java +++ b/src/org/cacert/gigi/DevelLauncher.java @@ -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); -- 2.39.2