Revision: 4664 http://sourceforge.net/p/vexi/code/4664 Author: mkpg2 Date: 2014-02-22 01:51:53 +0000 (Sat, 22 Feb 2014) Log Message: ----------- Implement fork option.
Modified Paths: -------------- trunk/org.vexi-launcher/src/main/java/org/vexi/launcher/Launcher.java Modified: trunk/org.vexi-launcher/src/main/java/org/vexi/launcher/Launcher.java =================================================================== --- trunk/org.vexi-launcher/src/main/java/org/vexi/launcher/Launcher.java 2014-02-15 22:19:30 UTC (rev 4663) +++ trunk/org.vexi-launcher/src/main/java/org/vexi/launcher/Launcher.java 2014-02-22 01:51:53 UTC (rev 4664) @@ -8,12 +8,14 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.lang.reflect.Method; import java.net.URL; +import java.net.URLClassLoader; import java.net.URLConnection; import java.util.ArrayList; +import java.util.List; import java.util.Map; import java.util.StringTokenizer; -import java.util.Vector; import org.vexi.DotVexi; import org.vexi.launcher.util.Problem; @@ -312,35 +314,55 @@ throw new RuntimeException("Could not create log file: " + f.getCanonicalPath()); } +// REMARK tried this as solution to proxy issues on a corporate network. It did not work. +// It seems system properties are essentially deprecated as they are jvm-wide, and instead +// another mechanism (ProxySelector or some such) is used. In any case it seems that it will +// not be possible to get the proxy password, so it won't be possible for proxy use to be +// transparent in a forked vexi process. +// +// static final String[] INHERITABLES = { +// "ssl.TrustManagerFactory.algorithm", +// "javax.net.ssl.trustStoreType", +// "javax.net.ssl.trustStore", +// "javax.net.ssl.trustStoreProvider", +// "javax.net.ssl.trustStorePassword", +// "java.home", +// "ssl.KeyManagerFactory.algorithm", +// "javax.net.ssl.keyStoreType", +// "javax.net.ssl.keyStore", +// "javax.net.ssl.keyStoreProvider", +// "javax.net.ssl.keyStorePassword", +// "http.proxyHost", +// "http.proxyPort", +// "http.nonProxyHosts", +// "http.keepAlive", +// "http.maxConnections" +// }; +// +// - static final String[] INHERITABLES = { - "ssl.TrustManagerFactory.algorithm", - "javax.net.ssl.trustStoreType", - "javax.net.ssl.trustStore", - "javax.net.ssl.trustStoreProvider", - "javax.net.ssl.trustStorePassword", - "java.home", - "ssl.KeyManagerFactory.algorithm", - "javax.net.ssl.keyStoreType", - "javax.net.ssl.keyStore", - "javax.net.ssl.keyStoreProvider", - "javax.net.ssl.keyStorePassword", - "http.proxyHost", - "http.proxyPort", - "http.nonProxyHosts", - "http.keepAlive", - "http.maxConnections" - }; - - - public void go() throws Exception { try { - log("Launcher Build : "+getVersion()); + log("Launcher Build : "+getVersion()); context.check(); + String forkParam = context.getParameter("fork"); + if(forkParam==null) forkParam = "yes"; + forkParam=forkParam.toLowerCase(); + + boolean fork; + if("auto".equals(forkParam)){ + // TODO should detect if proxy exists and then only fork if it does not + fork = false; + }else{ + fork = "yes".equals(forkParam) || "no".equals(forkParam); + } + + + + String core = context.getParameter("core"); if (core==null) { @@ -364,54 +386,37 @@ } File corefile = fetch(coreurl); - Vector command = new Vector(); - command.add(findJvmBinary()); - if (context.getParameter("mem") != null) { - command.add("-Xmx" + context.getParameter("mem")); - - for(String propKey: INHERITABLES){ - String propValue = System.getProperty(propKey); - if(propValue!=null){ - String propArg = "-D"+propKey+"="+propValue; - log("Inherit prop: "+propArg); - command.add(propArg); - } - } - } + List args = new ArrayList(); - - - - command.add("-jar"); - command.add(corefile.getPath()); - String logfile = context.getParameter("logfile"); if (logfile!=null) { createLog(logfile); - command.add("-l"); - command.add("logs/"+logfile); + args.add("-l"); + args.add("logs/"+logfile); } + args.add("-biscuitid"); + args.add(DotVexi.urlUniqueName(context.getOrigin())); - command.add("-biscuitid"); - command.add(DotVexi.urlUniqueName(context.getOrigin())); - - for (int i = 0; i<10000;i++) { if (context.getParameter("option" + i) == null) { break; } - command.add(context.getParameter("option" + i)); + args.add(context.getParameter("option" + i)); } for (int i = 0; i<fetchVexis.size();i++) { File f = fetch((String)fetchVexis.get(i)); - command.add(f.getPath()); + args.add(f.getPath()); } + + + + // REMARK - discovering os/architecture not relevant until // native builds are working again /* @@ -424,7 +429,44 @@ log("arch is " + arch); }*/ - spawn(command); + + + + if(fork){ + List command = new ArrayList(); + command.add(findJvmBinary()); + + String mem = context.getParameter("mem"); + if (mem != null) { + command.add("-Xmx" + mem); + // for(String propKey: INHERITABLES){ + // String propValue = System.getProperty(propKey); + // if(propValue!=null){ + // String propArg = "-D"+propKey+"="+propValue; + // log("Inherit prop: "+propArg); + // command.add(propArg); + // } + // } + } + + command.add("-jar"); + command.add(corefile.getPath()); + + command.addAll(args); + + + + spawn(args, fork); + }else{ + String[] argsArr = (String[])args.toArray(new String[args.size()]); + URL[] urls = new URL[]{corefile.toURI().toURL()}; + URLClassLoader cl = new URLClassLoader(urls); + // HACK should probably look at the manifest to get the jar main + // class file rather than hardcoding it here ... + Class vexiMain = cl.loadClass("org.vexi.core.Main"); + Method method = vexiMain.getMethod("main", String[].class); + method.invoke(null, new Object[]{argsArr}); + } } finally { Splash.close(); } @@ -433,46 +475,44 @@ /** spawns the Vexi core * @param command contains the full command - including java */ - private void spawn(Vector command) throws IOException { + private void spawn(List commandList, boolean fork) throws IOException { File dir = dotvexi.getBaseDir(); - String[] command_vec = new String[command.size()]; - - - - command.copyInto(command_vec); + String[] commandArr = (String[])commandList.toArray(new String[commandList.size()]); log("in directory : " + dir.getCanonicalPath()); log("executing : "); - for (int i=0; i<command_vec.length; i++) { - log(" \"" + command_vec[i] + "\""); + for (int i=0; i<commandArr.length; i++) { + log(" \"" + commandArr[i] + "\""); } - final Process p = Runtime.getRuntime().exec(command_vec,null,dir); - - new Thread(new Runnable() { - public void run() { - // catch output - StreamReader errorstream = new StreamReader(log, p.getErrorStream(), "ERROR", true); - StreamReader outputstream = new StreamReader(log, p.getInputStream(), "OUTPUT", false); - // kick off output streams - errorstream.start(); - outputstream.start(); - try { - log.status("Vexi loaded"); - int exitValue = p.waitFor(); - if (exitValue != 0) { - log.error("Vexi exited abnormally with error code '"+exitValue+"', see log output"); - } else { - log.status("Vexi has finished running"); - log.log("Exiting..."); - context.exited(); - } - } catch (Throwable t) { - log.error("Error exiting... " + p.exitValue()); - log.error(t); - log.flush(); - } - } - }).start(); + if(fork){ + final Process p = Runtime.getRuntime().exec(commandArr,null,dir); + + new Thread(new Runnable() { + public void run() { + // catch output + StreamReader errorstream = new StreamReader(log, p.getErrorStream(), "ERROR", true); + StreamReader outputstream = new StreamReader(log, p.getInputStream(), "OUTPUT", false); + // kick off output streams + errorstream.start(); + outputstream.start(); + try { + log.status("Vexi loaded"); + int exitValue = p.waitFor(); + if (exitValue != 0) { + log.error("Vexi exited abnormally with error code '"+exitValue+"', see log output"); + } else { + log.status("Vexi has finished running"); + log.log("Exiting..."); + context.exited(); + } + } catch (Throwable t) { + log.error("Error exiting... " + p.exitValue()); + log.error(t); + log.flush(); + } + } + }).start(); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Managing the Performance of Cloud-Based Applications Take advantage of what the Cloud has to offer - Avoid Common Pitfalls. Read the Whitepaper. http://pubads.g.doubleclick.net/gampad/clk?id=121054471&iu=/4140/ostg.clktrk _______________________________________________ Vexi-svn mailing list Vexi-svn@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/vexi-svn