MCPcopy Create free account
hub / github.com/e2wugui/zeze / main

Method main

ZezeJava/ZezeJava/src/main/java/Zeze/Services/Daemon.java:55–93  ·  view source on GitHub ↗
(String[] args)

Source from the content-addressed store, hash-verified

53 }
54
55 public static void main(String[] args) throws Exception {
56 // udp for subprocess register
57 udpSocket = new DatagramSocket(0, InetAddress.getLoopbackAddress());
58 udpSocket.setSoTimeout(200);
59 var minAliveTime = getLongProperty("MinAliveTime", 30 * 60 * 1000);
60
61 try {
62 var restart = false;
63 while (true) {
64 var command = new ArrayList<String>();
65 Collections.addAll(command, args);
66 if (restart)
67 command.add(1, "-D" + propertyNameClearInUse + "=true");
68 command.add(1, "-D" + propertyNamePort + "=" + udpSocket.getLocalPort());
69
70 var pb = new ProcessBuilder(command);
71 pb.inheritIO();
72
73 subprocess = pb.start();
74 var startTime = System.currentTimeMillis();
75 var exitCode = mainRun();
76 if (exitCode == 0)
77 break;
78 joinMonitors();
79 logger.warn("Subprocess Restart! ExitCode={}", exitCode);
80 if (System.currentTimeMillis() - startTime < minAliveTime) {
81 logger.fatal("subprocess alive too short: {}", minAliveTime);
82 break;
83 }
84 restart = true;
85 }
86 } catch (Throwable ex) { // print stacktrace.
87 logger.error("Daemon.main", ex);
88 } finally {
89 // 退出的时候,确保销毁服务进程。
90 if (subprocess != null)
91 subprocess.destroy();
92 }
93 }
94
95 private static int mainRun() {
96 while (true) {

Callers

nothing calls this directly

Calls 8

getLongPropertyMethod · 0.95
mainRunMethod · 0.95
joinMonitorsMethod · 0.95
getLocalPortMethod · 0.80
addMethod · 0.65
startMethod · 0.65
addAllMethod · 0.45
destroyMethod · 0.45

Tested by

no test coverage detected