01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
03: * notice. All rights reserved.
04: */
05: package com.tc.process;
06:
07: import java.lang.reflect.Method;
08:
09: /**
10: * Runs another main class, with full arguments, but first establishes a socket heartbeat protocol with a parent process
11: * on a specified port — and kills itself if this ping protocol is broken. This prevents runaway Java processes.
12: */
13: public class LinkedJavaProcessStarter {
14:
15: public static void main(String args[]) throws Exception {
16: int pingPort = Integer.parseInt(args[0]);
17: String childClass = args[1];
18:
19: String[] realArgs = new String[args.length - 2];
20: if (realArgs.length > 0)
21: System.arraycopy(args, 2, realArgs, 0, realArgs.length);
22:
23: HeartBeatService.registerForHeartBeat(pingPort, childClass);
24:
25: final Class mainClass = Class.forName(childClass);
26:
27: Method mainMethod = mainClass.getMethod("main",
28: new Class[] { String[].class });
29: mainMethod.invoke(null, new Object[] { realArgs });
30:
31: }
32:
33: }
|