Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Removed "ApplicationHandler" and "japplication_handler" and use MSG_launch_applicatio...
authorSamuel Lepetit <samuel.lepetit@inria.fr>
Wed, 16 May 2012 14:59:56 +0000 (16:59 +0200)
committerSamuel Lepetit <samuel.lepetit@inria.fr>
Wed, 16 May 2012 14:59:56 +0000 (16:59 +0200)
Also, removed the mandatory "Host, String, String[], double, double" constructor and replaced it with the old "Host, String, String[]" mandatory constructor
for the classes (updated the examples if you need an example), since we can't know from MSG the start_time and the kill_time if we launch it from
deployment file.

23 files changed:
CMakeLists.txt
examples/async/Forwarder.java
examples/async/Master.java
examples/async/Slave.java
examples/basic/Forwarder.java
examples/basic/Master.java
examples/basic/Slave.java
examples/commTime/Master.java
examples/commTime/Slave.java
examples/mutualExclusion/centralized/Coordinator.java
examples/mutualExclusion/centralized/Node.java
examples/pingPong/Receiver.java
examples/pingPong/Sender.java
examples/startKillTime/Master.java
examples/startKillTime/Slave.java
org/simgrid/msg/ApplicationHandler.java [deleted file]
org/simgrid/msg/Process.java
src/jmsg.c
src/jmsg_application_handler.c [deleted file]
src/jmsg_application_handler.h [deleted file]
src/jmsg_process.c
src/jmsg_process.h
src/smx_context_java.c

index 753e8a7..f097deb 100644 (file)
@@ -88,12 +88,9 @@ set(JMSG_C_SRC
        src/jmsg_task.h
        src/jmsg_synchro.c
        src/jmsg_synchro.h
        src/jmsg_task.h
        src/jmsg_synchro.c
        src/jmsg_synchro.h
-       src/jmsg_application_handler.c
-       src/jmsg_application_handler.h
 )
 
 set(JMSG_JAVA_SRC
 )
 
 set(JMSG_JAVA_SRC
-       org/simgrid/msg/ApplicationHandler.java
        org/simgrid/msg/Host.java
        org/simgrid/msg/HostFailureException.java       
        org/simgrid/msg/HostNotFoundException.java      
        org/simgrid/msg/Host.java
        org/simgrid/msg/HostFailureException.java       
        org/simgrid/msg/HostNotFoundException.java      
index 35fb2e4..29e9d18 100644 (file)
@@ -14,8 +14,8 @@ import org.simgrid.msg.Process;
 
 
 public class Forwarder extends Process {
 
 
 public class Forwarder extends Process {
-       public Forwarder(Host host, String name, String[]args, double startTime, double killTime) {
-               super(host,name,args,startTime,killTime);
+       public Forwarder(Host host, String name, String[]args) {
+               super(host,name,args);
        }
        public void main(String[] args) throws MsgException {
                if (args.length < 3) {   
        }
        public void main(String[] args) throws MsgException {
                if (args.length < 3) {   
index 971cd5f..19e840c 100644 (file)
@@ -19,8 +19,8 @@ import org.simgrid.msg.Task;
 import org.simgrid.msg.Process;;
 
 public class Master extends Process {
 import org.simgrid.msg.Process;;
 
 public class Master extends Process {
-       public Master(Host host, String name, String[]args, double startTime, double killTime) {
-               super(host,name,args,startTime,killTime);
+       public Master(Host host, String name, String[]args) {
+               super(host,name,args);
        }
        public void main(String[] args) throws MsgException {
                if (args.length < 4) {
        }
        public void main(String[] args) throws MsgException {
                if (args.length < 4) {
index f271dc6..d58910f 100644 (file)
@@ -17,8 +17,8 @@ import org.simgrid.msg.TransferFailureException;
 import org.simgrid.msg.Process;
 
 public class Slave extends Process {
 import org.simgrid.msg.Process;
 
 public class Slave extends Process {
-       public Slave(Host host, String name, String[]args, double startTime, double killTime) {
-               super(host,name,args,startTime,killTime);
+       public Slave(Host host, String name, String[]args) {
+               super(host,name,args);
        }
        public void main(String[] args) throws TransferFailureException, HostFailureException, TimeoutException {
                if (args.length < 1) {
        }
        public void main(String[] args) throws TransferFailureException, HostFailureException, TimeoutException {
                if (args.length < 1) {
index 6152da1..e8faf39 100644 (file)
@@ -15,9 +15,9 @@ import org.simgrid.msg.Process;
 
 
 public class Forwarder extends Process {
 
 
 public class Forwarder extends Process {
-       public Forwarder(Host host, String name, String[]args, double startTime, double killTime) {
-               super(host,name,args,startTime,killTime);
-       } 
+       public Forwarder(Host host, String name, String[]args) {
+               super(host,name,args);
+       }
    public void main(String[] args) throws MsgException {
       if (args.length < 3) {    
         Msg.info("Forwarder needs 3 arguments (input mailbox, first output mailbox, last one)");
    public void main(String[] args) throws MsgException {
       if (args.length < 3) {    
         Msg.info("Forwarder needs 3 arguments (input mailbox, first output mailbox, last one)");
index 5df6154..dfb4a9b 100644 (file)
@@ -15,8 +15,8 @@ import org.simgrid.msg.Task;
 import org.simgrid.msg.Process;;
 
 public class Master extends Process {
 import org.simgrid.msg.Process;;
 
 public class Master extends Process {
-       public Master(Host host, String name, String[]args, double startTime, double killTime) {
-               super(host,name,args,startTime,killTime);
+       public Master(Host host, String name, String[]args) {
+               super(host,name,args);
        } 
        public void main(String[] args) throws MsgException {
                if (args.length < 4) {
        } 
        public void main(String[] args) throws MsgException {
                if (args.length < 4) {
index 6f43f34..dc216a4 100644 (file)
@@ -16,8 +16,8 @@ import org.simgrid.msg.TransferFailureException;
 import org.simgrid.msg.Process;
 
 public class Slave extends Process {
 import org.simgrid.msg.Process;
 
 public class Slave extends Process {
-       public Slave(Host host, String name, String[]args, double startTime, double killTime) {
-               super(host,name,args,startTime,killTime);
+       public Slave(Host host, String name, String[]args) {
+               super(host,name,args);
        }
        public void main(String[] args) throws TransferFailureException, HostFailureException, TimeoutException {
                if (args.length < 1) {
        }
        public void main(String[] args) throws TransferFailureException, HostFailureException, TimeoutException {
                if (args.length < 1) {
index cd68e14..ea46963 100644 (file)
@@ -17,9 +17,9 @@ import org.simgrid.msg.Task;
 import org.simgrid.msg.Process;
 
 public class Master extends Process {
 import org.simgrid.msg.Process;
 
 public class Master extends Process {
-       public Master(Host host, String name, String[]args, double startTime, double killTime) {
-               super(host,name,args, startTime, killTime);
-       }
+       public Master(Host host, String name, String[]args) {
+               super(host,name,args);
+       } 
        public void main(String[] args) throws MsgException {
       if (args.length < 4) {
         Msg.info("Master needs 4 arguments");
        public void main(String[] args) throws MsgException {
       if (args.length < 4) {
         Msg.info("Master needs 4 arguments");
index 52c10a0..0ada19e 100644 (file)
@@ -10,9 +10,9 @@ package commTime;
 import org.simgrid.msg.*;
 
 public class Slave extends org.simgrid.msg.Process {
 import org.simgrid.msg.*;
 
 public class Slave extends org.simgrid.msg.Process {
-       public Slave(Host host, String name, String[]args, double startTime, double killTime) {
-               super(host,name,args, startTime, killTime);
-       }
+       public Slave(Host host, String name, String[]args) {
+               super(host,name,args);
+       } 
        public void main(String[] args) throws MsgException {
       if (args.length < 1) {
         Msg.info("Slave needs 1 argument (its number)");
        public void main(String[] args) throws MsgException {
       if (args.length < 1) {
         Msg.info("Slave needs 1 argument (its number)");
index dc4935a..abd94ba 100644 (file)
@@ -18,9 +18,9 @@ import org.simgrid.msg.Process;
 
 
 public class Coordinator extends Process  {
 
 
 public class Coordinator extends Process  {
-       public Coordinator(Host host, String name, String[]args, double startTime, double killTime) {
-               super(host,name,args, startTime, killTime);
-       }
+    public Coordinator(Host host, String name, String[]args) {
+               super(host,name,args);
+    } 
        LinkedList<RequestTask> waitingQueue=new LinkedList<RequestTask>();
        int CsToServe;
                
        LinkedList<RequestTask> waitingQueue=new LinkedList<RequestTask>();
        int CsToServe;
                
index d261b79..90ff40f 100644 (file)
@@ -15,9 +15,9 @@ import org.simgrid.msg.Task;
 import org.simgrid.msg.Process;
 
 public class Node extends Process {
 import org.simgrid.msg.Process;
 
 public class Node extends Process {
-       public Node(Host host, String name, String[]args, double startTime, double killTime) {
-               super(host,name,args,startTime,killTime);
-       }
+    public Node(Host host, String name, String[]args) {
+               super(host,name,args);
+    } 
        public void request(double CStime) throws MsgException {
                RequestTask req = new RequestTask(this.name);
           Msg.info("Send a request to the coordinator");
        public void request(double CStime) throws MsgException {
                RequestTask req = new RequestTask(this.name);
           Msg.info("Send a request to the coordinator");
index a0cb0ff..05f50dc 100644 (file)
@@ -15,9 +15,9 @@ import org.simgrid.msg.Task;
 import org.simgrid.msg.Process;
 
 public class Receiver extends Process {
 import org.simgrid.msg.Process;
 
 public class Receiver extends Process {
-       public Receiver(Host host, String name, String[]args, double startTime, double killTime) {
-               super(host,name,args,startTime,killTime);
-       }
+   public Receiver(Host host, String name, String[]args) {
+               super(host,name,args);
+   } 
    final double commSizeLat = 1;
    final double commSizeBw = 100000000;
     
    final double commSizeLat = 1;
    final double commSizeBw = 100000000;
     
index 7e00cc0..0af72d0 100644 (file)
@@ -14,8 +14,8 @@ import org.simgrid.msg.MsgException;
 import org.simgrid.msg.Process;
 
 public class Sender extends Process {
 import org.simgrid.msg.Process;
 
 public class Sender extends Process {
-       public Sender(Host host, String name, String[]args, double startTime, double killTime) {
-               super(host,name,args,startTime,killTime);
+       public Sender(Host host, String name, String[] args) {
+               super(host,name,args);
        }
     private final double commSizeLat = 1;
     final double commSizeBw = 100000000;
        }
     private final double commSizeLat = 1;
     final double commSizeBw = 100000000;
index 1262850..b71dd8f 100644 (file)
@@ -15,9 +15,9 @@ import org.simgrid.msg.Process;
 
 
 public class Master extends Process {
 
 
 public class Master extends Process {
-       public Master(Host host, String name, String[]args, double startTime, double killTime) {
-               super(host,name,args,startTime,killTime);
-       }
+       public Master(Host host, String name, String[]args) {
+               super(host,name,args);
+       } 
        public void main(String[] args) throws TransferFailureException, HostFailureException, TimeoutException {
                Msg.info("Hello!");
                waitFor(10.0);
        public void main(String[] args) throws TransferFailureException, HostFailureException, TimeoutException {
                Msg.info("Hello!");
                waitFor(10.0);
index 2120e90..2f5c82c 100644 (file)
@@ -17,9 +17,9 @@ import org.simgrid.msg.Process;
  * Lazy Guy Slave, suspends itself ASAP
  */
 public class Slave extends Process {
  * Lazy Guy Slave, suspends itself ASAP
  */
 public class Slave extends Process {
-       public Slave(Host host, String name, String[]args, double startTime, double killTime) {
-               super(host,name,args,startTime,killTime);
-       }
+       public Slave(Host host, String name, String[]args) {
+               super(host,name,args);
+       } 
        public void main(String[] args) throws TransferFailureException, HostFailureException, TimeoutException {
                Msg.info("Hello!");
                waitFor(10.0);
        public void main(String[] args) throws TransferFailureException, HostFailureException, TimeoutException {
                Msg.info("Hello!");
                waitFor(10.0);
diff --git a/org/simgrid/msg/ApplicationHandler.java b/org/simgrid/msg/ApplicationHandler.java
deleted file mode 100644 (file)
index b485d77..0000000
+++ /dev/null
@@ -1,193 +0,0 @@
-/*
- * These are the upcalls used by the FleXML parser for application files
- *
- * Copyright 2006,2007,2010,2011 The SimGrid team.           
- * All right reserved. 
- *
- * This program is free software; you can redistribute 
- * it and/or modify it under the terms of the license 
- * (GNU LGPL) which comes with this package.
- */
-
-package org.simgrid.msg;
-import java.util.Hashtable;
-import java.util.Vector;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
-
-public final class ApplicationHandler {
-
-
-               /**
-                * The vector which contains the arguments of the main function 
-                * of the process object.
-                */
-               public  static Vector<String> args;
-
-        /**
-         *
-         */
-        public  static Hashtable<String,String> properties;
-
-               /**
-                * The name of the host of the process.
-                */
-               private  static String hostName;
-
-               /**
-                * The function of the process.
-                */
-               private  static String function;
-               /**
-                * Start time of the process
-                */
-               private static double startTime;
-               /**
-                * Kill time of the process
-                */
-               private static double killTime;
-               /**
-                * This method is called by the start element handler.
-                * It sets the host and the function of the process to create,
-                * and clear the vector containing the arguments of the 
-                * previouse process function if needed.
-                *
-         * @param hostName_
-         * @param function_
-         * @host                               The host of the process to create.
-                * @function                    The function of the process to create.
-                *
-                */
-               public  static void setProcessIdentity(String hostName, String function, String startTime, String killTime) {
-                       ApplicationHandler.hostName = hostName;    
-                       ApplicationHandler.function = function;
-                       ApplicationHandler.startTime = Double.valueOf(startTime);
-                       ApplicationHandler.killTime = Double.valueOf(killTime);
-
-                       if (!args.isEmpty())
-                               args.clear();
-
-                       if(!properties.isEmpty())
-                               properties.clear();
-               }
-               /**
-                * This method is called by the startElement() handler.
-                * It stores the argument of the function of the next
-                * process to create in the vector of arguments.
-                *
-         * @param arg
-         * @arg                                        The argument to add.
-                *
-                */ public  static void registerProcessArg(String arg) {
-                        args.add(arg);
-                }
-
-         /**
-          *
-          * @param id
-          * @param value
-          */
-         public  static void setProperty(String id, String value)
-                {
-                        properties.put(id,value);      
-                }
-
-         /**
-          *
-          * @return
-          */
-         public  static String getHostName()
-                {
-                        return hostName;
-                }
-
-         /**
-          * Method called to create the process
-          */
-         @SuppressWarnings("unchecked")
-                public  static void createProcess() {
-                        try {
-                                Class<Process> cls = (Class<Process>) Class.forName(function);
-                                Constructor<Process> constructor = cls.getConstructor(new Class [] {Host.class, java.lang.String.class, java.lang.String[].class, double.class, double.class});
-                                String[] args_ = args.toArray(new String[args.size()]);
-                                Process process = constructor.newInstance(Host.getByName(hostName), function, args_, startTime, killTime);
-                                process.start();
-                        } 
-                        catch (NoSuchMethodException e) {
-                                throw new RuntimeException("Can't find the correct constructor for the class " + function + ". \n" +
-                                "Is there a constructor with the signature: \"Host host, String name, String[]args, double startTime, double killTime\" in the class ?");
-                        }
-                        catch (InvocationTargetException e) {
-                                e.printStackTrace();
-                        }
-                        catch(HostNotFoundException e) {
-                                System.out.println(e.toString());
-                                e.printStackTrace();
-
-                        } catch(ClassNotFoundException e) {
-                                System.out.println(function +
-                                " class not found\n The attribut function of the element process  of your deployment file\n must correspond to the name of a Msg Proces class)");
-                                e.printStackTrace();
-
-                        } catch(InstantiationException e) {
-                                System.out.println("Unable to create the process. I got an instantiation exception");
-                                e.printStackTrace();
-                        } catch(IllegalAccessException e) {
-                                System.out.println("Unable to create the process. I got an illegal access exception");
-                                e.printStackTrace();
-                        } 
-
-                }
-       
-
-         /**
-          *
-          */
-         public  static void onStartDocument() {
-                       args = new Vector<String>();
-                       properties = new Hashtable<String,String>();
-                       hostName = null;
-                       function = null;
-                       startTime = 0;
-                       killTime = -1;
-       }
-
-         /**
-          *
-          * @param hostName
-          * @param function
-          */
-         public  static void onBeginProcess(String hostName, String function, String startTime, String killTime) {
-               setProcessIdentity(hostName, function, startTime, killTime);
-               
-       }
-    /**
-     *
-     * @param id
-     * @param value
-     */
-    public  static void onProperty(String id, String value) {
-       setProperty(id, value);
-       }
-
-    /**
-     *
-     * @param arg
-     */
-    public  static void onProcessArg(String arg) {
-       registerProcessArg(arg);
-       }
-
-    /**
-     *
-     */
-    public  static void onEndProcess() {
-               createProcess();
-       }        
-
-    /**
-     *
-     */
-    public static void onEndDocument() {
-       }  
-}
index ea1f275..5e1b4e6 100644 (file)
@@ -75,11 +75,11 @@ public abstract class Process implements Runnable {
        /**
         * Start time of the process
         */
        /**
         * Start time of the process
         */
-       public double startTime;
+       public double startTime = 0;
        /**
         * Kill time of the process
         */
        /**
         * Kill time of the process
         */
-       public double killTime;
+       public double killTime = -1;
 
     public Hashtable<String,String> properties;
 
 
     public Hashtable<String,String> properties;
 
@@ -128,7 +128,7 @@ public abstract class Process implements Runnable {
         *
         */
        public Process(String hostname, String name) throws HostNotFoundException {
         *
         */
        public Process(String hostname, String name) throws HostNotFoundException {
-               this(Host.getByName(hostname), name, null, 0, -1);
+               this(Host.getByName(hostname), name, null);
        }
        /**
         * Constructs a new process from the name of a host and his name. The arguments
        }
        /**
         * Constructs a new process from the name of a host and his name. The arguments
@@ -144,7 +144,7 @@ public abstract class Process implements Runnable {
         *
         */ 
        public Process(String hostname, String name, String args[]) throws HostNotFoundException, NativeException {
         *
         */ 
        public Process(String hostname, String name, String args[]) throws HostNotFoundException, NativeException {
-               this(Host.getByName(hostname), name, args, 0, -1);
+               this(Host.getByName(hostname), name, args);
        }
        /**
         * Constructs a new process from a host and his name. The method function of the 
        }
        /**
         * Constructs a new process from a host and his name. The method function of the 
@@ -155,8 +155,29 @@ public abstract class Process implements Runnable {
         *
         */
        public Process(Host host, String name) {
         *
         */
        public Process(Host host, String name) {
-               this(host, name, null, 0, -1);
+               this(host, name, null);
        }
        }
+       /**
+        * Constructs a new process from a host and his name, the arguments of here method function are
+        * specified by the parameter args.
+        *
+        * @param host                  The host of the process to create.
+        * @param name                  The name of the process.
+        * @param args                  The arguments of main method of the process.
+        */     
+       public Process(Host host, String name, String[]args) {
+               this();
+               this.host = host;
+               if (name == null)
+                       throw new NullPointerException("Process name cannot be NULL");
+               this.name = name;
+
+               this.args = new Vector<String>();
+               if (null != args)
+                       this.args.addAll(Arrays.asList(args));
+               
+               this.properties = new Hashtable<String,String>();
+       }       
        /**
         * Constructs a new process from a host and his name, the arguments of here method function are
         * specified by the parameter args.
        /**
         * Constructs a new process from a host and his name, the arguments of here method function are
         * specified by the parameter args.
@@ -169,7 +190,6 @@ public abstract class Process implements Runnable {
         *
         */
        public Process(Host host, String name, String[]args, double startTime, double killTime) {
         *
         */
        public Process(Host host, String name, String[]args, double startTime, double killTime) {
-               /* This is the constructor called by all others */
                this();
                this.host = host;
                if (name == null)
                this();
                this.host = host;
                if (name == null)
@@ -189,7 +209,7 @@ public abstract class Process implements Runnable {
         * The natively implemented method to create an MSG process.
         * @param host    A valid (binded) host where create the process.
         */
         * The natively implemented method to create an MSG process.
         * @param host    A valid (binded) host where create the process.
         */
-       protected native void create(String hostName, double startTime, double killTime) throws HostNotFoundException;
+       protected native void create(String hostName) throws HostNotFoundException;
        /**
         * This method kills all running process of the simulation.
         *
        /**
         * This method kills all running process of the simulation.
         *
@@ -325,7 +345,7 @@ public abstract class Process implements Runnable {
     public final void start() throws HostNotFoundException {
        if (!started) {
                started = true;
     public final void start() throws HostNotFoundException {
        if (!started) {
                started = true;
-               create(host.getName(), startTime, killTime);
+               create(host.getName());
        }
     }
     
        }
     }
     
index 9f74905..1e02578 100644 (file)
@@ -17,7 +17,6 @@
 
 #include "jmsg_host.h"
 #include "jmsg_task.h"
 
 #include "jmsg_host.h"
 #include "jmsg_task.h"
-#include "jmsg_application_handler.h"
 #include "jxbt_utilities.h"
 
 #include "jmsg.h"
 #include "jxbt_utilities.h"
 
 #include "jmsg.h"
@@ -31,6 +30,8 @@
 #endif
 /* end of eclipse-mandated pimple */
 
 #endif
 /* end of eclipse-mandated pimple */
 
+static int create_jprocess(int argc, char *argv[]);
+
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(jmsg);
 
 static JavaVM *__java_vm = NULL;
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(jmsg);
 
 static JavaVM *__java_vm = NULL;
@@ -165,30 +166,51 @@ Java_org_simgrid_msg_Msg_deployApplication(JNIEnv * env, jclass cls,
   const char *deploymentFile =
       (*env)->GetStringUTFChars(env, jdeploymentFile, 0);
 
   const char *deploymentFile =
       (*env)->GetStringUTFChars(env, jdeploymentFile, 0);
 
-  surf_parse_reset_callbacks();
-
-  surfxml_add_callback(STag_surfxml_process_cb_list,
-                       japplication_handler_on_begin_process);
-
-  surfxml_add_callback(ETag_surfxml_argument_cb_list,
-                       japplication_handler_on_process_arg);
-
-  surfxml_add_callback(STag_surfxml_prop_cb_list,
-                       japplication_handler_on_property);
-
-  surfxml_add_callback(ETag_surfxml_process_cb_list,
-                       japplication_handler_on_end_process);
-
-  surf_parse_open(deploymentFile);
-
-  japplication_handler_on_start_document();
-
-  if (surf_parse())
-    jxbt_throw_jni(env, "surf_parse() failed");
-
-  surf_parse_close();
-
-  japplication_handler_on_end_document();
-
-  (*env)->ReleaseStringUTFChars(env, jdeploymentFile, deploymentFile);
+  SIMIX_function_register_default(create_jprocess);
+  MSG_launch_application(deploymentFile);
+}
+/**
+ * Function called when there is the need to create the java Process object
+ * (when we are using deployement files).
+ * it HAS to be executed on the process context, else really bad things will happen.
+ */
+static int create_jprocess(int argc, char *argv[]) {
+       JNIEnv *env = get_current_thread_env();
+       //Change the "." in class name for "/".
+       xbt_str_subst(argv[0],'.','/',0);
+       jclass class_Process = (*env)->FindClass(env, argv[0]);
+       xbt_str_subst(argv[0],'/','.',0);
+       //Retrieve the methodID for the constructor
+       xbt_assert((class_Process != NULL), "Class not found.");
+       jmethodID constructor_Process = (*env)->GetMethodID(env, class_Process, "<init>", "(Lorg/simgrid/msg/Host;Ljava/lang/String;[Ljava/lang/String;)V");
+       xbt_assert((constructor_Process != NULL), "Constructor not found for class %s. Is there a (Host, String ,String[]) constructor in your class ?", argv[0]);
+
+       //Retrieve the name of the process.
+       jstring jname = (*env)->NewStringUTF(env, argv[0]);
+       //Build the arguments
+       jobjectArray args = (jobjectArray)((*env)->NewObjectArray(env,argc - 1,
+       (*env)->FindClass(env,"java/lang/String"),
+       (*env)->NewStringUTF(env,"")));
+       int i;
+       for (i = 1; i < argc; i++)
+               (*env)->SetObjectArrayElement(env,args,i - 1,(*env)->NewStringUTF(env, argv[i]));
+       //Retrieve the host for the process.
+       jstring jhostName = (*env)->NewStringUTF(env, MSG_host_get_name(MSG_host_self()));
+       jobject jhost = Java_org_simgrid_msg_Host_getByName(env, NULL, jhostName);
+       //creates the process
+       jobject jprocess = (*env)->NewObject(env, class_Process, constructor_Process, jhost, jname, args);
+       xbt_assert((jprocess != NULL), "Process allocation failed.");
+       jprocess = (*env)->NewGlobalRef(env, jprocess);
+       //bind the process to the context
+       m_process_t process = MSG_process_self();
+       smx_ctx_java_t context = (smx_ctx_java_t)MSG_process_get_smx_ctx(process);
+       context->jprocess = jprocess;
+  /* sets the PID and the PPID of the process */
+  (*env)->SetIntField(env, jprocess, jprocess_field_Process_pid,(jint) MSG_process_get_PID(process));
+  (*env)->SetIntField(env, jprocess, jprocess_field_Process_ppid, (jint) MSG_process_get_PPID(process));
+
+       jprocess_bind(jprocess, process, env);
+
+       return 0;
 }
 }
+
diff --git a/src/jmsg_application_handler.c b/src/jmsg_application_handler.c
deleted file mode 100644 (file)
index ac40766..0000000
+++ /dev/null
@@ -1,116 +0,0 @@
-/* Upcalls to the Java functions used as callback to the FleXML parser.     */
-
-/* Copyright (c) 2008, 2009, 2010. The SimGrid Team.
- * All rights reserved.                                                     */
-
-/* This program is free software; you can redistribute it and/or modify it
-  * under the terms of the license (GNU LGPL) which comes with this package. */
-
-#include "jmsg_application_handler.h"
-
-#include "jmsg.h"
-
-#include "surf/surfxml_parse.h"
-#include "jxbt_utilities.h"
-void japplication_handler_on_start_document(void)
-{
-  jclass cls;
-  JNIEnv *env = get_current_thread_env();
-  jmethodID id =
-      jxbt_get_static_smethod(env, "org/simgrid/msg/ApplicationHandler",
-                              "onStartDocument", "()V");
-
-  if (!id
-      || !(cls = jxbt_get_class(env, "org/simgrid/msg/ApplicationHandler")))
-    return;
-
-  (*env)->CallStaticVoidMethod(env, cls, id);
-}
-
-void japplication_handler_on_end_document(void)
-{
-  jclass cls;
-  JNIEnv *env = get_current_thread_env();
-  jmethodID id =
-      jxbt_get_static_smethod(env, "org/simgrid/msg/ApplicationHandler",
-                              "onEndDocument", "()V");
-
-  if (!id
-      || !(cls = jxbt_get_class(env, "org/simgrid/msg/ApplicationHandler")))
-    return;
-
-  (*env)->CallStaticVoidMethod(env, cls, id);
-}
-
-void japplication_handler_on_begin_process(void)
-{
-  jstring jhostName;
-  jstring jfunction;
-  jstring jstartTime, jkillTime;
-  jclass cls;
-  JNIEnv *env = get_current_thread_env();
-  jmethodID id =
-      jxbt_get_static_smethod(env, "org/simgrid/msg/ApplicationHandler",
-                              "onBeginProcess",
-                              "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
-  if (!id
-      || !(cls = jxbt_get_class(env, "org/simgrid/msg/ApplicationHandler")))
-    return;
-  jhostName = (jstring) (*env)->NewStringUTF(env, A_surfxml_process_host);
-  jfunction =
-      (jstring) (*env)->NewStringUTF(env, A_surfxml_process_function);
-
-  jstartTime = (jstring) (*env)->NewStringUTF(env, A_surfxml_process_start_time);
-  jkillTime = (jstring) (*env)->NewStringUTF(env, A_surfxml_process_kill_time);
-
-
-  (*env)->CallStaticVoidMethod(env, cls, id, jhostName, jfunction, jstartTime, jkillTime);
-}
-
-void japplication_handler_on_process_arg(void)
-{
-  jstring jarg;
-  jclass cls;
-  JNIEnv *env = get_current_thread_env();
-  jmethodID id =
-      jxbt_get_static_smethod(env, "org/simgrid/msg/ApplicationHandler",
-                              "onProcessArg", "(Ljava/lang/String;)V");
-  if (!id
-      || !(cls = jxbt_get_class(env, "org/simgrid/msg/ApplicationHandler")))
-    return;
-  jarg = (jstring) (*env)->NewStringUTF(env, A_surfxml_argument_value);
-
-  (*env)->CallStaticVoidMethod(env, cls, id, jarg);
-}
-
-void japplication_handler_on_property(void)
-{
-  jstring jid;
-  jstring jvalue;
-  jclass cls;
-  JNIEnv *env = get_current_thread_env();
-  jmethodID id =
-      jxbt_get_static_smethod(env, "org/simgrid/msg/ApplicationHandler",
-                              "onProperty",
-                              "(Ljava/lang/String;Ljava/lang/String;)V");
-  if (!id
-      || !(cls = jxbt_get_class(env, "org/simgrid/msg/ApplicationHandler")))
-    return;
-
-  jid = (jstring) (*env)->NewStringUTF(env, A_surfxml_prop_id);
-  jvalue = (jstring) (*env)->NewStringUTF(env, A_surfxml_prop_value);
-  (*env)->CallStaticVoidMethod(env, cls, id, jid, jvalue);
-}
-
-void japplication_handler_on_end_process(void)
-{
-  JNIEnv *env = get_current_thread_env();
-  jclass cls;
-  jmethodID id =
-      jxbt_get_static_smethod(env, "org/simgrid/msg/ApplicationHandler",
-                              "onEndProcess", "()V");
-  if (!id
-      || !(cls = jxbt_get_class(env, "org/simgrid/msg/ApplicationHandler")))
-    return;
-  (*env)->CallStaticVoidMethod(env, cls, id);
-}
diff --git a/src/jmsg_application_handler.h b/src/jmsg_application_handler.h
deleted file mode 100644 (file)
index 7d3a215..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-/* Upcalls to the Java functions used as callback to the FleXML parser.     */
-
-/* Copyright (c) 2008, 2009, 2010. The SimGrid Team.
- * All rights reserved.                                                     */
-
-/* This program is free software; you can redistribute it and/or modify it
- * under the terms of the license (GNU LGPL) which comes with this package. */
-
-#ifndef MSG_JAPPLICATION_HANDLER_H
-#define MSG_JAPPLICATION_HANDLER_H
-
-#include <jni.h>
-#include "msg/msg.h"
-void japplication_handler_on_start_document(void);
-void japplication_handler_on_end_document(void);
-void japplication_handler_on_begin_process(void);
-void japplication_handler_on_process_arg(void);
-void japplication_handler_on_property(void);
-void japplication_handler_on_end_process(void);
-
-#endif                          /* !MSG_JAPPLICATION_HANDLER_H */
index 9b3bb96..213b345 100644 (file)
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(jmsg);
 
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(jmsg);
 
-static jfieldID jprocess_field_Process_bind;
-static jfieldID jprocess_field_Process_name;
-static jfieldID jprocess_field_Process_host;
-static jfieldID jprocess_field_Process_id;
-static jfieldID jprocess_field_Process_pid;
-static jfieldID jprocess_field_Process_ppid;
-
 jobject native_to_java_process(m_process_t process)
 {
   return ((smx_ctx_java_t)MSG_process_get_smx_ctx(process))->jprocess;
 jobject native_to_java_process(m_process_t process)
 {
   return ((smx_ctx_java_t)MSG_process_get_smx_ctx(process))->jprocess;
@@ -84,7 +77,7 @@ Java_org_simgrid_msg_Process_nativeInit(JNIEnv *env, jclass cls) {
        jprocess_field_Process_pid = jxbt_get_jfield(env, jprocess_class_Process, "pid", "I");
        jprocess_field_Process_ppid = jxbt_get_jfield(env, jprocess_class_Process, "ppid", "I");
        jprocess_field_Process_host = jxbt_get_jfield(env, jprocess_class_Process, "host", "Lorg/simgrid/msg/Host;");
        jprocess_field_Process_pid = jxbt_get_jfield(env, jprocess_class_Process, "pid", "I");
        jprocess_field_Process_ppid = jxbt_get_jfield(env, jprocess_class_Process, "ppid", "I");
        jprocess_field_Process_host = jxbt_get_jfield(env, jprocess_class_Process, "host", "Lorg/simgrid/msg/Host;");
-
+       jprocess_field_Process_killTime = jxbt_get_jfield(env, jprocess_class_Process, "killTime", "D");
        if (!jprocess_class_Process || !jprocess_field_Process_id || !jprocess_field_Process_name || !jprocess_field_Process_pid ||
                        !jprocess_field_Process_ppid || !jprocess_field_Process_host) {
        jxbt_throw_native(env,bprintf("Can't find some fields in Java class. You should report this bug."));
        if (!jprocess_class_Process || !jprocess_field_Process_id || !jprocess_field_Process_name || !jprocess_field_Process_pid ||
                        !jprocess_field_Process_ppid || !jprocess_field_Process_host) {
        jxbt_throw_native(env,bprintf("Can't find some fields in Java class. You should report this bug."));
@@ -93,7 +86,7 @@ Java_org_simgrid_msg_Process_nativeInit(JNIEnv *env, jclass cls) {
 JNIEXPORT void JNICALL
 Java_org_simgrid_msg_Process_create(JNIEnv * env,
                                     jobject jprocess_arg,
 JNIEXPORT void JNICALL
 Java_org_simgrid_msg_Process_create(JNIEnv * env,
                                     jobject jprocess_arg,
-                                    jobject jhostname, jdouble jstartTime, jdouble jkillTime)
+                                    jobject jhostname)
 {
 
 
 {
 
 
@@ -137,12 +130,14 @@ Java_org_simgrid_msg_Process_create(JNIEnv * env,
   name = (*env)->GetStringUTFChars(env, jname, 0);
   name = xbt_strdup(name);
 
   name = (*env)->GetStringUTFChars(env, jname, 0);
   name = xbt_strdup(name);
 
+  /* Retrieve the kill time from the process */
+  jdouble jkill = (*env)->GetDoubleField(env, jprocess, jprocess_field_Process_killTime);
   /* Actually build the MSG process */
   process = MSG_process_create_with_environment(name,
                                                (xbt_main_func_t) jprocess,
   /* Actually build the MSG process */
   process = MSG_process_create_with_environment(name,
                                                (xbt_main_func_t) jprocess,
-                                               /*data*/ NULL,
+                                               /*data*/ jprocess,
                                                host,
                                                host,
-                                               (double)jkillTime, /* kill time */
+                                               (double)jkill, /* kill time */
                                                /*argc, argv, properties*/
                                                0,NULL,NULL);
 
                                                /*argc, argv, properties*/
                                                0,NULL,NULL);
 
index f917960..a97c0dd 100644 (file)
 #include <msg/msg.h>
 #include <simgrid/simix.h>
 
 #include <msg/msg.h>
 #include <simgrid/simix.h>
 
+//Cached java fields
+jfieldID jprocess_field_Process_bind;
+jfieldID jprocess_field_Process_host;
+jfieldID jprocess_field_Process_killTime;
+jfieldID jprocess_field_Process_id;
+jfieldID jprocess_field_Process_name;
+jfieldID jprocess_field_Process_pid;
+jfieldID jprocess_field_Process_ppid;
+
+
 jobject native_to_java_process(m_process_t process);
 
 /**
 jobject native_to_java_process(m_process_t process);
 
 /**
@@ -142,7 +152,7 @@ Java_org_simgrid_msg_Process_nativeInit(JNIEnv *env, jclass cls);
 JNIEXPORT void JNICALL
 Java_org_simgrid_msg_Process_create(JNIEnv * env,
                                     jobject jprocess_arg,
 JNIEXPORT void JNICALL
 Java_org_simgrid_msg_Process_create(JNIEnv * env,
                                     jobject jprocess_arg,
-                                    jobject jhostname, jdouble jstartTime, jdouble jkillTime);
+                                    jobject jhostname);
 
 /*
  * Class               org_simgrid_msg_Process
 
 /*
  * Class               org_simgrid_msg_Process
index 8065420..10fa3ea 100644 (file)
@@ -66,16 +66,25 @@ smx_ctx_java_factory_create_context(xbt_main_func_t code, int argc,
                                     void_pfn_smxprocess_t cleanup_func,
                                     void* data)
 {
                                     void_pfn_smxprocess_t cleanup_func,
                                     void* data)
 {
-  smx_ctx_java_t context = xbt_new0(s_smx_ctx_java_t, 1);
-
+       smx_ctx_java_t context = xbt_new0(s_smx_ctx_java_t, 1);
   /* If the user provided a function for the process then use it
      otherwise is the context for maestro */
   if (code) {
   /* If the user provided a function for the process then use it
      otherwise is the context for maestro */
   if (code) {
-    context->super.cleanup_func = cleanup_func;
-    context->jprocess = (jobject) code;
-    context->begin = xbt_os_sem_init(0);
-    context->end = xbt_os_sem_init(0);
-    context->thread = xbt_os_thread_create(NULL,smx_ctx_java_thread_run,context,NULL);
+               if (argc == 0) {
+                       context->jprocess = (jobject) code;
+               }
+               else {
+                       context->jprocess = NULL;
+               }
+               context->super.cleanup_func = cleanup_func;
+               context->begin = xbt_os_sem_init(0);
+               context->end = xbt_os_sem_init(0);
+
+               context->super.argc = argc;
+               context->super.argv = argv;
+               context->super.code = code;
+
+               context->thread = xbt_os_thread_create(NULL,smx_ctx_java_thread_run,context,NULL);
   }
   else {
        context->thread = NULL;
   }
   else {
        context->thread = NULL;
@@ -96,6 +105,11 @@ static void* smx_ctx_java_thread_run(void *data) {
   context->jenv = get_current_thread_env();
   //Wait for the first scheduling round to happen.
   xbt_os_sem_acquire(context->begin);
   context->jenv = get_current_thread_env();
   //Wait for the first scheduling round to happen.
   xbt_os_sem_acquire(context->begin);
+  //Create the "Process" object if needed.
+       if (context->super.argc > 0) {
+               (*(context->super.code))(context->super.argc, context->super.argv);
+       }
+       xbt_assert((context->jprocess != NULL), "Process not created...");
   //wait for the process to be able to begin
   //TODO: Cache it
        jfieldID jprocess_field_Process_startTime = jxbt_get_sfield(env, "org/simgrid/msg/Process", "startTime", "D");
   //wait for the process to be able to begin
   //TODO: Cache it
        jfieldID jprocess_field_Process_startTime = jxbt_get_sfield(env, "org/simgrid/msg/Process", "startTime", "D");