45 int optsLen = (options == null) ? 0 : options.length; 46 int argsLen = (args == null) ? 0 : args.length; 47 int len = 1 + optsLen + 1 + argsLen; 48 String cmdarray[] = new String[len]; 49 int pos = 0; 50 cmdarray[pos++] = Util.javaCommand(); 51 if (options != null) { 52 for (String opt: options) { 53 cmdarray[pos++] = opt; 54 } 55 } 56 cmdarray[pos++] = className; 57 if (args != null) { 58 for (String arg: args) { 59 cmdarray[pos++] = arg; 60 } 61 } 62 launch0(cmdarray, fd); 63 } 64 65 /* 66 * Launch 'java' with specified class with the specified arguments (may be null). 67 * The launched process will inherit a connected TCP socket. The remote endpoint 68 * will be the SocketChannel returned by this method. 69 */ 70 public static SocketChannel launchWithSocketChannel(String className, String options[], String args[]) throws IOException { 71 ServerSocketChannel ssc = ServerSocketChannel.open(); 72 ssc.socket().bind(new InetSocketAddress(0)); 73 InetSocketAddress isa = new InetSocketAddress(InetAddress.getLocalHost(), 74 ssc.socket().getLocalPort()); 75 SocketChannel sc1 = SocketChannel.open(isa); 76 SocketChannel sc2 = ssc.accept(); 77 launch(className, options, args, Util.getFD(sc2)); 78 sc2.close(); 79 ssc.close(); 80 return sc1; 81 } 82 83 public static SocketChannel launchWithSocketChannel(String className, String args[]) throws IOException { 84 return launchWithSocketChannel(className, null, args); | 45 int optsLen = (options == null) ? 0 : options.length; 46 int argsLen = (args == null) ? 0 : args.length; 47 int len = 1 + optsLen + 1 + argsLen; 48 String cmdarray[] = new String[len]; 49 int pos = 0; 50 cmdarray[pos++] = Util.javaCommand(); 51 if (options != null) { 52 for (String opt: options) { 53 cmdarray[pos++] = opt; 54 } 55 } 56 cmdarray[pos++] = className; 57 if (args != null) { 58 for (String arg: args) { 59 cmdarray[pos++] = arg; 60 } 61 } 62 launch0(cmdarray, fd); 63 } 64 65 66 /** 67 * Launch 'java' with specified class using a UnixDomainSocket pair linking calling 68 * process to the child VM. UnixDomainSocket is a simplified interface to PF_UNIX sockets 69 * which supports byte a time reads and writes. 70 */ 71 public static UnixDomainSocket launchWithUnixDomainSocket(String className) throws IOException { 72 UnixDomainSocket[] socks = UnixDomainSocket.socketpair(); 73 launch(className, null, null, socks[0].fd()); 74 socks[0].close(); 75 return socks[1]; 76 } 77 78 /* 79 * Launch 'java' with specified class with the specified arguments (may be null). 80 * The launched process will inherit a connected TCP socket. The remote endpoint 81 * will be the SocketChannel returned by this method. 82 */ 83 public static SocketChannel launchWithSocketChannel(String className, String options[], String args[]) throws IOException { 84 ServerSocketChannel ssc = ServerSocketChannel.open(); 85 ssc.socket().bind(new InetSocketAddress(0)); 86 InetSocketAddress isa = new InetSocketAddress(InetAddress.getLocalHost(), 87 ssc.socket().getLocalPort()); 88 SocketChannel sc1 = SocketChannel.open(isa); 89 SocketChannel sc2 = ssc.accept(); 90 launch(className, options, args, Util.getFD(sc2)); 91 sc2.close(); 92 ssc.close(); 93 return sc1; 94 } 95 96 public static SocketChannel launchWithSocketChannel(String className, String args[]) throws IOException { 97 return launchWithSocketChannel(className, null, args); |