Revision: 3118
http://vexi.svn.sourceforge.net/vexi/?rev=3118&view=rev
Author: mkpg2
Date: 2008-09-24 18:03:12 +0000 (Wed, 24 Sep 2008)
Log Message:
-----------
Test for process exiting.
Modified Paths:
--------------
trunk/core/org.vexi.core/src/org/vexi/core/Main.java
trunk/core/org.vexi.core/src/org/vexi/core/Surface.java
trunk/core/org.vexi.core/src/org/vexi/core/Vexi.jpp
trunk/core/org.vexi.core/src_junit/test/process/TestProcess.java
Added Paths:
-----------
trunk/core/org.vexi.core/src/org/vexi/util/VexiProcess.java
trunk/core/org.vexi.core/src_junit/test/process/main.t
Modified: trunk/core/org.vexi.core/src/org/vexi/core/Main.java
===================================================================
--- trunk/core/org.vexi.core/src/org/vexi/core/Main.java 2008-09-24
18:01:36 UTC (rev 3117)
+++ trunk/core/org.vexi.core/src/org/vexi/core/Main.java 2008-09-24
18:03:12 UTC (rev 3118)
@@ -12,6 +12,7 @@
import org.ibex.js.JSExn;
import org.ibex.js.JSU;
import org.ibex.js.Scheduler;
+import org.ibex.js.Thread;
import org.ibex.js.Fountain.Multiple;
import org.ibex.util.Callable;
import org.ibex.util.Encode;
@@ -23,7 +24,7 @@
public class Main {
- public static void main(String[] args) throws Exception {
+ static public void main(String[] args) throws Exception {
new Main().start(args);
}
@@ -210,6 +211,25 @@
try { params.put(JSU.S(key), JSU.S(value)); }
catch(JSExn e) { Log.warn(Main.class, e); /*Should not happen */ }
}
+
+ static public void exit(){
+ // After we finish the current thread that closed the last
surface/called exit.
+ Scheduler.add(new Callable(){
+ public Object run(Object o) throws Exception {
+ if(Main.SCHEDULER.alive.size()!=0){
+ // FEATURE - headless mode
+ // vexi.thread.headless or function.headless
+ Log.warn(Surface.class, "WARNING - threads are still
alive: ");
+ for(int i=0; i<Main.SCHEDULER.alive.size();i++){
+ Thread t= (Thread) Main.SCHEDULER.alive.elementAt(i);
+ Log.warn(Surface.class, t);
+ }
+ }
+ System.exit(0);
+ return null;
+ }
+ });
+ }
}
class BuiltinFountain extends Fountain {
Modified: trunk/core/org.vexi.core/src/org/vexi/core/Surface.java
===================================================================
--- trunk/core/org.vexi.core/src/org/vexi/core/Surface.java 2008-09-24
18:01:36 UTC (rev 3117)
+++ trunk/core/org.vexi.core/src/org/vexi/core/Surface.java 2008-09-24
18:03:12 UTC (rev 3118)
@@ -9,7 +9,6 @@
import org.ibex.js.JSExn;
import org.ibex.js.JSU;
import org.ibex.js.Scheduler;
-import org.ibex.js.Thread;
import org.ibex.util.Callable;
import org.ibex.util.Log;
import org.ibex.util.Vec;
@@ -346,22 +345,7 @@
Log.info(this, "disposing " + this);
allSurfaces.removeElement(this);
if(quitIfAllSurfacesGone && allSurfaces.size()==0){
- // After we finish the current thread that closed the last surface
- Scheduler.add(new Callable(){
- public Object run(Object o) throws Exception {
- if(Main.SCHEDULER.alive.size()!=0){
- // FEATURE - headless mode
- // vexi.thread.headless or function.headless
- Log.warn(Surface.class, "WARNING - threads are still
alive: ");
- for(int i=0; i<Main.SCHEDULER.alive.size();i++){
- Thread t= (Thread)
Main.SCHEDULER.alive.elementAt(i);
- Log.warn(Surface.class, t);
- }
- }
- System.exit(0);
- return null;
- }
- });
+ Main.exit();
}
_dispose();
//Main.tryExit();
Modified: trunk/core/org.vexi.core/src/org/vexi/core/Vexi.jpp
===================================================================
--- trunk/core/org.vexi.core/src/org/vexi/core/Vexi.jpp 2008-09-24 18:01:36 UTC
(rev 3117)
+++ trunk/core/org.vexi.core/src/org/vexi/core/Vexi.jpp 2008-09-24 18:03:12 UTC
(rev 3118)
@@ -91,6 +91,7 @@
case "crypto.rc4": return METHOD;
case "crypto.rsa": return METHOD;
case "date": return METHOD;
+ case "exit": return METHOD;
case "file": return getSub(name);
case "file.load": return METHOD;
case "file.remove": return METHOD;
@@ -248,6 +249,7 @@
switch (args.length) {
case 0:
//#switch(JSU.toString(method))
+ case "exit": Main.exit(); return null;
case "thread.yield": JSU.sleep(-1); return null;
//#end
break;
Copied: trunk/core/org.vexi.core/src/org/vexi/util/VexiProcess.java (from rev
3074, trunk/core/org.vexi.devl/src/org/vexi/process/VexiProcess.java)
===================================================================
--- trunk/core/org.vexi.core/src/org/vexi/util/VexiProcess.java
(rev 0)
+++ trunk/core/org.vexi.core/src/org/vexi/util/VexiProcess.java 2008-09-24
18:03:12 UTC (rev 3118)
@@ -0,0 +1,63 @@
+package org.vexi.util;
+
+import java.io.*;
+
+import org.ibex.util.Log;
+
+public class VexiProcess {
+
+ final String workingDir;
+ final String[] vexipath;
+
+ public VexiProcess(String workingDir, String[] vexipath){
+ this.workingDir = workingDir;
+ this.vexipath = vexipath;
+ }
+
+
+ public Process launch(StreamGobbler outGobbler, StreamGobbler
errGobbler) throws IOException{
+ String[] command_noargs =
+ new String[]{"java","-cp",
System.getProperty("java.class.path"),
+ "org.vexi.core.Main"};
+ String[] command = new String[command_noargs.length +
vexipath.length];
+ System.arraycopy(command_noargs, 0, command, 0,
command_noargs.length);
+ System.arraycopy(vexipath, 0, command, command_noargs.length,
vexipath.length);
+
+ Log.uInfo(VexiProcess.class, "Launching command: ");
+ String commandStr = "";
+ for(int i=0; i<command.length; i++) commandStr+=command[i]+" ";
+ Log.uInfo(VexiProcess.class, commandStr);
+ Process proc = Runtime.getRuntime().exec(command, new
String[]{}, new File(workingDir));
+
+ outGobbler.start(proc.getInputStream());
+ errGobbler.start(proc.getErrorStream());
+ return proc;
+ }
+
+
+
+ static abstract public class StreamGobbler extends Thread {
+ InputStream is;
+
+ public void start(InputStream is){
+ this.is = is;
+ start();
+ }
+
+ public void run()
+ {
+ try
+ {
+ InputStreamReader isr = new
InputStreamReader(is);
+ BufferedReader br = new BufferedReader(isr);
+ String line=null;
+ while ( (line = br.readLine()) != null)
gobble(line);
+ } catch (IOException ioe)
+ {
+ ioe.printStackTrace();
+ }
+ }
+
+ abstract protected void gobble(String line);
+ }
+}
Modified: trunk/core/org.vexi.core/src_junit/test/process/TestProcess.java
===================================================================
--- trunk/core/org.vexi.core/src_junit/test/process/TestProcess.java
2008-09-24 18:01:36 UTC (rev 3117)
+++ trunk/core/org.vexi.core/src_junit/test/process/TestProcess.java
2008-09-24 18:03:12 UTC (rev 3118)
@@ -1,10 +1,31 @@
package test.process;
-public class TestProcess {
+import org.vexi.util.VexiProcess;
+import org.vexi.util.VexiProcess.StreamGobbler;
+import junit.framework.TestCase;
+
+public class TestProcess extends TestCase{
+
+ static class StreamPrinter extends StreamGobbler{
+ final String prefix;
+ StreamPrinter(String prefix){this.prefix = prefix; }
+ protected void gobble(String line) {
+ System.out.println(prefix+">"+line);
+ }
+ };
+
public void testExitCleanly() throws Exception {
+ StreamGobbler sgOut = new StreamPrinter("OUT");
+ StreamGobbler sgErr = new StreamPrinter("ERR");
+
+ String dir = getClass().getResource(".").getFile();
+ VexiProcess vp = new VexiProcess(dir, new String[]{"."});
+ Process proc = vp.launch(sgOut, sgErr);
+ proc.waitFor();
+ System.out.println(proc.exitValue());
}
}
Added: trunk/core/org.vexi.core/src_junit/test/process/main.t
===================================================================
--- trunk/core/org.vexi.core/src_junit/test/process/main.t
(rev 0)
+++ trunk/core/org.vexi.core/src_junit/test/process/main.t 2008-09-24
18:03:12 UTC (rev 3118)
@@ -0,0 +1,17 @@
+
+<vexi xmlns:ui="vexi://ui">
+ <ui:box>
+
+ vexi.thread = function(){
+ vexi.log.info("before");
+ vexi.thread.sleep(1000);
+ vexi.log.info("after");
+ };
+
+ vexi.thread = function(){
+ vexi.thread.yield();
+ vexi.exit();
+ };
+
+ </ui:box>
+</vexi>
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Vexi-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/vexi-svn