Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Change the way the objects are created in ApplicationHandler: they are
authorSamuel Lepetit <samuel.lepetit@inria.fr>
Thu, 10 May 2012 10:00:29 +0000 (12:00 +0200)
committerSamuel Lepetit <samuel.lepetit@inria.fr>
Thu, 10 May 2012 10:00:29 +0000 (12:00 +0200)
now created the same way than when you create the object manually,
using the (Host, String, String[]) constructor. It means that now your
classes need to have a (Host, String, String[]) constructor calling the
same constructor in Process.

Update the examples to reflect the change.
Update the changelog.

18 files changed:
ChangeLog
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
org/simgrid/msg/ApplicationHandler.java
org/simgrid/msg/Process.java
src/jmsg_process.c
src/smx_context_java.c
src/smx_context_java.h

index 414854b..2845ecd 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -5,8 +5,10 @@ SimGrid-java (3.6.1) unstable; urgency=low
    as sufficiently prevalent for us to not dupplicate its features.
  * Make Process.kill(process) an instance method, not a static one
  * Fix a bug around Process.kill()
- * Add dsend and simulatedSleep to the bindings.
-
+ * Add the asynchronous API to the bindings.
+ * Add "sleep" in Process with Thread-like syntax/use.
+ * Change the way the Process are created in ApplicationHandler: a full 
+constructor is now needed for your child classes.
  -- $date Da SimGrid team <simgrid-devel@lists.gforge.inria.fr>
 
 SimGrid-java (3.6) unstable; urgency=low
index 3ed84f3..2a0b4c6 100644 (file)
@@ -13,7 +13,9 @@ import org.simgrid.msg.Process;
 
 
 public class Forwarder extends Process {
-
+       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)");
index 043f41c..19e840c 100644 (file)
@@ -11,6 +11,7 @@ package async;
 import java.util.ArrayList;
 
 import org.simgrid.msg.Comm;
+import org.simgrid.msg.Host;
 import org.simgrid.msg.Process;
 import org.simgrid.msg.Msg;
 import org.simgrid.msg.MsgException;
@@ -18,6 +19,9 @@ import org.simgrid.msg.Task;
 import org.simgrid.msg.Process;;
 
 public class Master extends Process {
+       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");
index e7e92d6..922db49 100644 (file)
@@ -15,6 +15,9 @@ import org.simgrid.msg.TransferFailureException;
 import org.simgrid.msg.Process;
 
 public class Slave extends Process {
+       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) {
                        Msg.info("Slave needs 1 argument (its number)");
index 57250d0..4a9b2b1 100644 (file)
@@ -13,7 +13,9 @@ import org.simgrid.msg.Process;
 
 
 public class Forwarder extends Process {
-    
+       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)");
index 93e2534..54e0f5e 100644 (file)
@@ -14,6 +14,9 @@ import org.simgrid.msg.Task;
 import org.simgrid.msg.Process;;
 
 public class Master extends Process {
+       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");
index 8c138dd..ccd2344 100644 (file)
@@ -14,6 +14,9 @@ import org.simgrid.msg.TransferFailureException;
 import org.simgrid.msg.Process;
 
 public class Slave extends Process {
+       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) {
                        Msg.info("Slave needs 1 argument (its number)");
index 7501016..b53bc0f 100644 (file)
@@ -15,6 +15,9 @@ import org.simgrid.msg.Task;
 import org.simgrid.msg.Process;
 
 public class Master extends Process {
+       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");
index dc057a2..f68848c 100644 (file)
@@ -10,7 +10,10 @@ package commTime;
 import org.simgrid.msg.*;
 
 public class Slave extends org.simgrid.msg.Process {
-   public void main(String[] args) throws MsgException {
+       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)");
         System.exit(1);
index 74abea2..eae6047 100644 (file)
@@ -17,7 +17,9 @@ import org.simgrid.msg.Process;
 
 
 public class Coordinator extends Process  {
-
+       public Coordinator(String hostname, String name) throws HostNotFoundException {
+               super(hostname, name);
+       }
        LinkedList<RequestTask> waitingQueue=new LinkedList<RequestTask>();
        int CsToServe;
                
index 75cc666..8f79d8e 100644 (file)
@@ -14,7 +14,9 @@ import org.simgrid.msg.Task;
 import org.simgrid.msg.Process;
 
 public class Node extends Process {
-
+       public Node(String hostname, String name) throws HostNotFoundException {
+               super(hostname, name);
+       }
        public void request(double CStime) throws MsgException {
                RequestTask req = new RequestTask(this.name);
           Msg.info("Send a request to the coordinator");
index 8f8268e..e4ad3ab 100644 (file)
@@ -14,7 +14,9 @@ import org.simgrid.msg.Task;
 import org.simgrid.msg.Process;
 
 public class Receiver extends Process {
-       
+       public Receiver(String hostname, String name) throws HostNotFoundException {
+               super(hostname, name);
+       }       
    final double commSizeLat = 1;
    final double commSizeBw = 100000000;
     
index 80a4102..454cbb4 100644 (file)
@@ -14,7 +14,9 @@ import org.simgrid.msg.MsgException;
 import org.simgrid.msg.Process;
 
 public class Sender extends Process {
-  
+       public Sender(String hostname, String name) throws HostNotFoundException {
+               super(hostname, name);
+       }
     private final double commSizeLat = 1;
     final double commSizeBw = 100000000;
    
index 3003ec3..9a5f58a 100644 (file)
  */
 
 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 {
 
@@ -92,28 +93,24 @@ public final class ApplicationHandler {
                 }
 
          /**
-          *
+          * Method called to create the process
           */
          @SuppressWarnings("unchecked")
                 public  static void createProcess() {
                         try {
                                 Class<Process> cls = (Class<Process>) Class.forName(function);
-
-                                Process process = cls.newInstance();
-                                process.name = function;
-                                process.id = org.simgrid.msg.Process.nextProcessId++;
-
-                               process.create(hostName);
-                                Vector<String> args_ = args;
-                                int size = args_.size();
-
-                                for (int index = 0; index < size; index++)
-                                        process.args.add(args_.get(index));
-
-                                process.properties = properties;
-                                properties = new Hashtable<String,String>();
-
-                        } catch(HostNotFoundException e) {
+                                Constructor<Process> constructor = cls.getConstructor(new Class [] {Host.class, java.lang.String.class, java.lang.String[].class});
+                                String[] args_ = args.toArray(new String[args.size()]);
+                                Process process = constructor.newInstance(Host.getByName(hostName), function, args_);
+                        } 
+                        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\" in the class ?");
+                        }
+                        catch (InvocationTargetException e) {
+                                e.printStackTrace();
+                        }
+                        catch(HostNotFoundException e) {
                                 System.out.println(e.toString());
                                 e.printStackTrace();
 
index d9cedd9..447966b 100644 (file)
@@ -179,6 +179,8 @@ public abstract class Process extends Thread {
                        throw new RuntimeException("The impossible happened (yet again): the host that I have were not found",e);
                }
                
+               this.properties = new Hashtable<String,String>();
+               
        }
        /**
         * The natively implemented method to create an MSG process.
@@ -315,7 +317,7 @@ public abstract class Process extends Thread {
         * FIXME: Not optimal, maybe we should have two native functions.
         * @param millis the length of time to sleep in milliseconds.
         */
-       public static void sleep(long millis) {
+       public static void sleep(long millis)  {
                sleep(millis,0);
        }
        /**
index cba0649..2e4c9d1 100644 (file)
@@ -430,10 +430,9 @@ Java_org_simgrid_msg_Process_waitFor(JNIEnv * env, jobject jprocess,
     return;
   }
   MSG_error_t rv = MSG_process_sleep((double)jseconds);
-
-  jxbt_check_res("MSG_process_sleep()", rv, MSG_OK,
-                 bprintf("unexpected error , please report this bug"));
-
+  if (rv != MSG_OK) {
+//     smx_ctx_java_stop(smx_ctx_java_self());
+  }
 }
 
 JNIEXPORT void JNICALL
index 622e103..b2abae8 100644 (file)
@@ -16,7 +16,6 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(jmsg, bindings, "MSG for Java(TM)");
 
 static smx_context_t my_current_context = NULL;
 
-static smx_context_t smx_ctx_java_self(void);
 static smx_context_t
 smx_ctx_java_factory_create_context(xbt_main_func_t code, int argc,
                                     char **argv,
@@ -46,7 +45,7 @@ void SIMIX_ctx_java_factory_init(smx_context_factory_t * factory)
   (*factory)->get_data = smx_ctx_base_get_data;
 }
 
-static smx_context_t smx_ctx_java_self(void)
+smx_context_t smx_ctx_java_self(void)
 {
        return my_current_context;
 }
@@ -68,7 +67,8 @@ smx_ctx_java_factory_create_context(xbt_main_func_t code, int argc,
     context->jenv = get_current_thread_env();
     jprocess_start(((smx_ctx_java_t) context)->jprocess,
                    get_current_thread_env());
-  }else{
+  }
+  else {
     my_current_context = (smx_context_t)context;
   }
   context->super.data = data;
index c95f15b..8515614 100644 (file)
@@ -22,7 +22,7 @@ typedef struct s_smx_ctx_java {
 
 void SIMIX_ctx_java_factory_init(smx_context_factory_t *factory);
 void smx_ctx_java_stop(smx_context_t context);
-
+smx_context_t smx_ctx_java_self(void);
 SG_END_DECL()
 
 #endif                          /* !_XBT_CONTEXT_JAVA_H */