diff options
author | Tobias Roeser <le.petit.fou@web.de> | 2019-02-25 11:07:28 +0100 |
---|---|---|
committer | Tobias Roeser <le.petit.fou@web.de> | 2019-02-25 11:07:28 +0100 |
commit | b19b5a4d36ed5015eb59d621dab13e9742408805 (patch) | |
tree | dbd4a5715155066ea46dae368314dfc9e3ea4a36 /main/client | |
parent | d1d9d5ff7f4ca5bc44c383d5e1000674c2b4c2e2 (diff) | |
download | mill-b19b5a4d36ed5015eb59d621dab13e9742408805.tar.gz mill-b19b5a4d36ed5015eb59d621dab13e9742408805.tar.bz2 mill-b19b5a4d36ed5015eb59d621dab13e9742408805.zip |
Reviewed exitCode handling
Propagate server stop because of version change as exit code.
Diffstat (limited to 'main/client')
-rw-r--r-- | main/client/src/MillClientMain.java | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/main/client/src/MillClientMain.java b/main/client/src/MillClientMain.java index 3857caff..dc144f99 100644 --- a/main/client/src/MillClientMain.java +++ b/main/client/src/MillClientMain.java @@ -10,6 +10,12 @@ import java.nio.channels.FileChannel; import java.util.*; public class MillClientMain { + + // use methods instead of constants to avoid inlining by compiler + public static final int ExitClientCodeCannotReadFromExitCodeFile() { return 1; } + public static final int ExitServerCodeWhenIdle() { return 0; } + public static final int ExitServerCodeWhenVersionMismatch() { return 101; } + static void initServer(String lockBase, boolean setJnaNoSys) throws IOException,URISyntaxException{ String[] selfJars = System.getProperty("MILL_CLASSPATH").split(","); @@ -56,7 +62,8 @@ public class MillClientMain { System.setProperty("jna.nosys", "true"); } int index = 0; - while (index < 5) { + final int processLimit = 5; + while (index < processLimit) { index += 1; String lockBase = "out/mill-worker-" + index; new java.io.File(lockBase).mkdirs(); @@ -91,7 +98,7 @@ public class MillClientMain { } } - throw new Exception("Reached max process limit: " + 5); + throw new Exception("Reached max process limit: " + processLimit); } public static int run(String lockBase, @@ -151,10 +158,10 @@ public class MillClientMain { locks.serverLock.await(); - try(FileInputStream fos = new FileInputStream(lockBase + "/exitCode")){ - return Integer.parseInt(new BufferedReader(new InputStreamReader(fos)).readLine()); + try(FileInputStream fis = new FileInputStream(lockBase + "/exitCode")){ + return Integer.parseInt(new BufferedReader(new InputStreamReader(fis)).readLine()); } catch(Throwable e){ - return 1; + return ExitClientCodeCannotReadFromExitCodeFile(); } finally{ ioSocket.close(); } |