Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add dsend and simulatedSleep to the binding, and add an example
authorMartin Quinson <martin.quinson@loria.fr>
Tue, 24 Apr 2012 08:17:11 +0000 (10:17 +0200)
committerMartin Quinson <martin.quinson@loria.fr>
Tue, 24 Apr 2012 08:17:11 +0000 (10:17 +0200)
15 files changed:
.gitignore
CMakeLists.txt
examples/async/AsyncTest.java [new file with mode: 0644]
examples/async/FinalizeTask.java [new file with mode: 0644]
examples/async/Forwarder.java [new file with mode: 0644]
examples/async/Master.java [new file with mode: 0644]
examples/async/README [new file with mode: 0644]
examples/async/Slave.java [new file with mode: 0644]
examples/async/async.tesh [new file with mode: 0644]
examples/async/asyncDeployment.xml [new file with mode: 0644]
org/simgrid/msg/MsgNative.java
org/simgrid/msg/Process.java
org/simgrid/msg/Task.java
src/jmsg.c
src/jmsg.h

index 4c96975..7cae982 100644 (file)
@@ -10,3 +10,4 @@ build/
 .project
 .cproject
 .classpath
+*~
\ No newline at end of file
index 99095e6..32bfee1 100644 (file)
@@ -135,6 +135,11 @@ set(JAVA_EXAMPLES
        examples/master_slave_kill/MsKill.java
        examples/master_slave_kill/Slave.java
        examples/master_slave_kill/FinalizeTask.java
+       examples/async/AsyncTest.java
+       examples/async/FinalizeTask.java  
+       examples/async/Forwarder.java
+       examples/async/Master.java  
+       examples/async/Slave.java
 )
 
 set(CMAKE_SRC
@@ -154,6 +159,7 @@ set(XML_FILES
     examples/basic/deploy.xml
     examples/master_slave_bypass/platform.xml
     examples/master_slave_kill/platform.xml
+    examples/async/asyncDeployment.xml
 )
 
 set(source_to_pack
@@ -225,6 +231,7 @@ add_custom_command(
        OUTPUT  ${JAVA_EXAMPLES_CLASS}
        DEPENDS ${JAVA_EXAMPLES}
        COMMAND ${JAVA_COMPILE} -d ${CMAKE_HOME_DIRECTORY}/examples -cp ${CMAKE_HOME_DIRECTORY}/simgrid.jar ${CMAKE_HOME_DIRECTORY}/examples/basic/*.java  
+       COMMAND ${JAVA_COMPILE} -d ${CMAKE_HOME_DIRECTORY}/examples -cp ${CMAKE_HOME_DIRECTORY}/simgrid.jar ${CMAKE_HOME_DIRECTORY}/examples/async/*.java
        COMMAND ${JAVA_COMPILE} -d ${CMAKE_HOME_DIRECTORY}/examples -cp ${CMAKE_HOME_DIRECTORY}/simgrid.jar ${CMAKE_HOME_DIRECTORY}/examples/pingPong/*.java
        COMMAND ${JAVA_COMPILE} -d ${CMAKE_HOME_DIRECTORY}/examples -cp ${CMAKE_HOME_DIRECTORY}/simgrid.jar ${CMAKE_HOME_DIRECTORY}/examples/commTime/*.java
        COMMAND ${JAVA_COMPILE} -d ${CMAKE_HOME_DIRECTORY}/examples -cp ${CMAKE_HOME_DIRECTORY}/simgrid.jar ${CMAKE_HOME_DIRECTORY}/examples/mutualExclusion/centralized/*.java                                 
@@ -255,6 +262,9 @@ ENABLE_TESTING()
 ADD_TEST(basic
 java -cp .:${CMAKE_HOME_DIRECTORY}/examples:${CMAKE_HOME_DIRECTORY}/simgrid.jar basic/BasicTest ${CMAKE_HOME_DIRECTORY}/examples/platform.xml ${CMAKE_HOME_DIRECTORY}/examples/basic/basicDeployment.xml
 )
+ADD_TEST(async
+java -cp .:${CMAKE_HOME_DIRECTORY}/examples:${CMAKE_HOME_DIRECTORY}/simgrid.jar async/AsyncTest ${CMAKE_HOME_DIRECTORY}/examples/platform.xml ${CMAKE_HOME_DIRECTORY}/examples/async/asyncDeployment.xml
+)
 ADD_TEST(pingPong
 java -cp .:${CMAKE_HOME_DIRECTORY}/examples:${CMAKE_HOME_DIRECTORY}/simgrid.jar pingPong/PingPongTest ${CMAKE_HOME_DIRECTORY}/examples/platform.xml ${CMAKE_HOME_DIRECTORY}/examples/pingPong/pingPongDeployment.xml
 )
@@ -271,7 +281,7 @@ ADD_TEST(kill
 java -cp .:${CMAKE_HOME_DIRECTORY}/examples:${CMAKE_HOME_DIRECTORY}/simgrid.jar master_slave_kill/MsKill ${CMAKE_HOME_DIRECTORY}/examples/master_slave_kill/platform.xml
 )
 #Don't forget to put new test in this list!!!
-set(test_list basic pingPong CommTime mutualExclusion bypass kill)
+set(test_list basic async pingPong CommTime mutualExclusion bypass kill)
 
 ##########################################
 # Set the  DYLD_LIBRARY_PATH for mac     #
diff --git a/examples/async/AsyncTest.java b/examples/async/AsyncTest.java
new file mode 100644 (file)
index 0000000..1e14632
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2006,2007,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. 
+ */
+
+package async;
+
+import org.simgrid.msg.Msg;
+import org.simgrid.msg.NativeException;
+
+public class AsyncTest {
+
+       /* This only contains the launcher. If you do nothing more than than you can run 
+        *   java simgrid.msg.Msg
+        * which also contains such a launcher
+        */
+
+       public static void main(String[] args) throws NativeException {
+
+               /* initialize the MSG simulation. Must be done before anything else (even logging). */
+               Msg.init(args);
+
+               if(args.length == 0) {
+                       Msg.createEnvironment("async_platform.xml");
+                       Msg.deployApplication("async_deployment.xml");
+
+               } else if (args.length < 2) {
+
+
+                       Msg.info("Usage   : Async platform_file deployment_file");
+                       Msg.info("example : Async async_platform.xml async_deployment.xml");
+                       System.exit(1);
+               } else {
+
+                       /* construct the platform and deploy the application */
+                       Msg.createEnvironment(args[0]);
+                       Msg.deployApplication(args[1]);
+               }
+
+               /*  execute the simulation. */
+               Msg.run();
+       }
+}
diff --git a/examples/async/FinalizeTask.java b/examples/async/FinalizeTask.java
new file mode 100644 (file)
index 0000000..c93dc7f
--- /dev/null
@@ -0,0 +1,16 @@
+/*
+ * Copyright 2006,2007,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. 
+ */
+
+package async;
+import org.simgrid.msg.Task;
+
+public class FinalizeTask extends Task {       
+   public FinalizeTask() {
+      super("finalize",0,0);
+   }
+}
+    
\ No newline at end of file
diff --git a/examples/async/Forwarder.java b/examples/async/Forwarder.java
new file mode 100644 (file)
index 0000000..d17bb93
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2006,2007,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. 
+ */
+
+package async;
+import org.simgrid.msg.Msg;
+import org.simgrid.msg.MsgException;
+import org.simgrid.msg.Task;
+import org.simgrid.msg.Process;
+
+
+public class Forwarder extends Process {
+
+       public void main(String[] args) throws MsgException {
+               if (args.length < 3) {   
+                       Msg.info("Forwarder needs 3 arguments (input mailbox, first output mailbox, last one)");
+                       Msg.info("Got "+args.length+" instead");
+                       System.exit(1);
+               }
+               int input = Integer.valueOf(args[0]).intValue();                
+               int firstOutput = Integer.valueOf(args[1]).intValue();          
+               int lastOutput = Integer.valueOf(args[2]).intValue();           
+
+               int taskCount = 0;
+               int slavesCount = lastOutput - firstOutput + 1;
+               Msg.info("Receiving on 'slave_"+input+"'");
+               while(true) {
+                       Task task = Task.receive("slave_"+input);       
+
+                       if (task instanceof FinalizeTask) {
+                               Msg.info("Got a finalize task. Let's forward (asynchronously) that we're done, and then sleep 20 seconds so that nobody gets a message from a terminated process.");
+
+                               for (int cpt = firstOutput; cpt<=lastOutput; cpt++) {
+                                       Task tf = new FinalizeTask();
+                                       tf.dsend("slave_"+cpt);
+                               }
+                               simulatedSleep(20);
+                               break;
+                       }
+                       int dest = firstOutput + (taskCount % slavesCount);
+
+                       Msg.info("Sending \"" + task.getName() + "\" to \"slave_" + dest + "\"");
+                       task.send("slave_"+dest);
+
+                       taskCount++;
+               }
+
+
+               Msg.info("I'm done. See you!");
+       }
+}
+
diff --git a/examples/async/Master.java b/examples/async/Master.java
new file mode 100644 (file)
index 0000000..88d6d12
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * Master of a basic master/slave example in Java
+ *
+ * Copyright 2006,2007,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. 
+ */
+
+package async;
+import org.simgrid.msg.Msg;
+import org.simgrid.msg.MsgException;
+import org.simgrid.msg.Task;
+import org.simgrid.msg.Process;;
+
+public class Master extends Process {
+       public void main(String[] args) throws MsgException {
+               if (args.length < 4) {
+                       Msg.info("Master needs 4 arguments");
+                       System.exit(1);
+               }
+
+               int tasksCount = Integer.valueOf(args[0]).intValue();           
+               double taskComputeSize = Double.valueOf(args[1]).doubleValue();         
+               double taskCommunicateSize = Double.valueOf(args[2]).doubleValue();
+
+               int slavesCount = Integer.valueOf(args[3]).intValue();
+
+               Msg.info("Hello! Got "+  slavesCount + " slaves and "+tasksCount+" tasks to process");
+
+               for (int i = 0; i < tasksCount; i++) {
+                       Task task = new Task("Task_" + i, taskComputeSize, taskCommunicateSize); 
+                       //Msg.info("Sending \"" + task.getName()+ "\" to \"slave_" + i % slavesCount + "\"");
+                       task.send("slave_"+(i%slavesCount));
+               }
+
+               Msg.info("All tasks have been dispatched. Let's tell (asynchronously) everybody the computation is over, and sleep 20s so that nobody gets a message from a terminated process.");
+
+               for (int i = 0; i < slavesCount; i++) {
+                       FinalizeTask task = new FinalizeTask();
+                       task.dsend("slave_"+(i%slavesCount));
+               }
+               simulatedSleep(20);
+
+               Msg.info("Goodbye now!");
+       }
+}
diff --git a/examples/async/README b/examples/async/README
new file mode 100644 (file)
index 0000000..0d6dcc2
--- /dev/null
@@ -0,0 +1,24 @@
+This is another version of the master/slaves example, using asynchronous communications.
+
+There is 3 kind of processes:
+ * Master: creates some tasks, and dispatches them to its slaves
+ * Forwarder: get tasks from master, and dispatch them further
+ * Slave: get tasks from either master or forwarder, and run them
+
+At the end of the execution:
+ - the master sends FinalizeTask to every known slave to stop them,
+   using dsend instead of send. That's non-blocking with no way to
+   know if/when the communication succeeds. It is intended for
+   communications where you don't care to know whether your message got 
+   received or not. The process then sleeps 20 seconds because we have
+   a strange bug for now when the receiver gets a message from a
+   terminated process. This should not be the case, actually, that's a
+   JAVA specific bug, but I don't really have the time to dig in right
+   now.
+
+ - On reception of FT, forwarders dsend FT to every slave, and stop
+   after a little while.
+ - On reception of FinalizeTask, slaves stop.
+Other non-blocking primitives will get used here as soon as they are 
+added to the bindings.
\ No newline at end of file
diff --git a/examples/async/Slave.java b/examples/async/Slave.java
new file mode 100644 (file)
index 0000000..3d2270b
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2006,2007,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. 
+ */
+package async;
+import org.simgrid.msg.HostFailureException;
+import org.simgrid.msg.Msg;
+import org.simgrid.msg.Task;
+import org.simgrid.msg.TaskCancelledException;
+import org.simgrid.msg.TimeoutException;
+import org.simgrid.msg.TransferFailureException;
+import org.simgrid.msg.Process;
+
+public class Slave extends Process {
+       public void main(String[] args) throws TransferFailureException, HostFailureException, TimeoutException {
+               if (args.length < 1) {
+                       Msg.info("Slave needs 1 argument (its number)");
+                       System.exit(1);
+               }
+
+               int num = Integer.valueOf(args[0]).intValue();
+               //Msg.info("Receiving on 'slave_"+num+"'");
+
+               while(true) {  
+                       Task task = Task.receive("slave_"+num); 
+
+                       if (task instanceof FinalizeTask) {
+                               break;
+                       }
+                       Msg.info("Received \"" + task.getName() +  "\". Processing it.");
+                       try {
+                               task.execute();
+                       } catch (TaskCancelledException e) {
+
+                       }
+               //      Msg.info("\"" + task.getName() + "\" done ");
+               }
+
+               Msg.info("Received Finalize. I'm done. See you!");
+       }
+}
\ No newline at end of file
diff --git a/examples/async/async.tesh b/examples/async/async.tesh
new file mode 100644 (file)
index 0000000..8bbea2b
--- /dev/null
@@ -0,0 +1,75 @@
+# compile the example\r
+$ javac -classpath $MSG4JAVA_CLASSPATH$ENV_SEPARATOR. *.java\r
+\r
+# run the basic sample\r
+$ java -classpath $MSG4JAVA_CLASSPATH$ENV_SEPARATOR BasicTest basic_platform.xml basic_deployment.xml\r
+> [Jacquelin:Master:(1) 0.000000] [jmsg/INFO] hello!\r
+> [Jacquelin:Master:(1) 0.000000] [jmsg/INFO] argc=8\r
+> [Jacquelin:Master:(1) 0.000000] [jmsg/INFO] argv:5\r
+> [Jacquelin:Master:(1) 0.000000] [jmsg/INFO] argv:50000\r
+> [Jacquelin:Master:(1) 0.000000] [jmsg/INFO] argv:10\r
+> [Jacquelin:Master:(1) 0.000000] [jmsg/INFO] argv:iRMX\r
+> [Jacquelin:Master:(1) 0.000000] [jmsg/INFO] argv:Casavant\r
+> [Jacquelin:Master:(1) 0.000000] [jmsg/INFO] argv:Bousquet\r
+> [Jacquelin:Master:(1) 0.000000] [jmsg/INFO] argv:Soucy\r
+> [Jacquelin:Master:(1) 0.000000] [jmsg/INFO] argv:Jackson\r
+> [Jacquelin:Master:(1) 0.000000] [jmsg/INFO] Got 5 slave(s) :\r
+> [Jacquelin:Master:(1) 0.000000] [jmsg/INFO]  iRMX\r
+> [Jacquelin:Master:(1) 0.000000] [jmsg/INFO]  Casavant\r
+> [Jacquelin:Master:(1) 0.000000] [jmsg/INFO]  Bousquet\r
+> [Jacquelin:Master:(1) 0.000000] [jmsg/INFO]  Soucy\r
+> [Jacquelin:Master:(1) 0.000000] [jmsg/INFO]  Jackson\r
+> [Jacquelin:Master:(1) 0.000000] [jmsg/INFO] Got 5 task to process.\r
+> [Jacquelin:Master:(1) 0.000000] [jmsg/INFO] Sending "Task_0" to "iRMX"\r
+> [Jackson:Forwarder:(2) 0.000000] [jmsg/INFO] hello!\r
+> [Casavant:Forwarder:(3) 0.000000] [jmsg/INFO] hello!\r
+> [iRMX:Slave:(4) 0.000000] [jmsg/INFO] Hello !\r
+> [Bousquet:Slave:(5) 0.000000] [jmsg/INFO] Hello !\r
+> [Soucy:Slave:(6) 0.000000] [jmsg/INFO] Hello !\r
+> [Kuenning:Slave:(7) 0.000000] [jmsg/INFO] Hello !\r
+> [Browne:Slave:(8) 0.000000] [jmsg/INFO] Hello !\r
+> [Stephen:Slave:(9) 0.000000] [jmsg/INFO] Hello !\r
+> [Robert:Slave:(10) 0.000000] [jmsg/INFO] Hello !\r
+> [Sirois:Slave:(11) 0.000000] [jmsg/INFO] Hello !\r
+> [Monique:Slave:(12) 0.000000] [jmsg/INFO] Hello !\r
+> [Jacquelin:Master:(1) 0.234181] [jmsg/INFO] Sending "Task_1" to "Casavant"\r
+> [iRMX:Slave:(4) 0.234181] [jmsg/INFO] Received "Task_0" \r
+> [iRMX:Slave:(4) 0.234181] [jmsg/INFO] Processing "Task_0" \r
+> [iRMX:Slave:(4) 0.234910] [jmsg/INFO] "Task_0" done \r
+> [Jacquelin:Master:(1) 0.338591] [jmsg/INFO] Sending "Task_2" to "Bousquet"\r
+> [Casavant:Forwarder:(3) 0.338591] [jmsg/INFO] Received "Task_1" \r
+> [Casavant:Forwarder:(3) 0.338591] [jmsg/INFO] Sending "Task_1" to "Robert"\r
+> [Jacquelin:Master:(1) 0.416661] [jmsg/INFO] Sending "Task_3" to "Soucy"\r
+> [Bousquet:Slave:(5) 0.416661] [jmsg/INFO] Received "Task_2" \r
+> [Bousquet:Slave:(5) 0.416661] [jmsg/INFO] Processing "Task_2" \r
+> [Bousquet:Slave:(5) 0.417826] [jmsg/INFO] "Task_2" done \r
+> [Robert:Slave:(10) 0.454402] [jmsg/INFO] Received "Task_1" \r
+> [Robert:Slave:(10) 0.454402] [jmsg/INFO] Processing "Task_1" \r
+> [Robert:Slave:(10) 0.454766] [jmsg/INFO] "Task_1" done \r
+> [Jacquelin:Master:(1) 0.527739] [jmsg/INFO] Sending "Task_4" to "Jackson"\r
+> [Soucy:Slave:(6) 0.527739] [jmsg/INFO] Received "Task_3" \r
+> [Soucy:Slave:(6) 0.527739] [jmsg/INFO] Processing "Task_3" \r
+> [Soucy:Slave:(6) 0.528103] [jmsg/INFO] "Task_3" done \r
+> [Jacquelin:Master:(1) 0.593252] [jmsg/INFO] Send completed\r
+> [Jacquelin:Master:(1) 0.593252] [jmsg/INFO] All tasks have been dispatched. Let's tell everybody the computation is over.\r
+> [Jackson:Forwarder:(2) 0.593252] [jmsg/INFO] Received "Task_4" \r
+> [Jackson:Forwarder:(2) 0.593252] [jmsg/INFO] Sending "Task_4" to "Kuenning"\r
+> [Kuenning:Slave:(7) 0.593708] [jmsg/INFO] Received "Task_4" \r
+> [Kuenning:Slave:(7) 0.593708] [jmsg/INFO] Processing "Task_4" \r
+> [Kuenning:Slave:(7) 0.594291] [jmsg/INFO] "Task_4" done \r
+> [iRMX:Slave:(4) 0.827199] [jmsg/INFO] Received Finalize. I'm done. See you!\r
+> [Casavant:Forwarder:(3) 0.931504] [jmsg/INFO] All tasks have been dispatched. Let's tell everybody the computation is over.\r
+> [Bousquet:Slave:(5) 1.009496] [jmsg/INFO] Received Finalize. I'm done. See you!\r
+> [Robert:Slave:(10) 1.047200] [jmsg/INFO] Received Finalize. I'm done. See you!\r
+> [Sirois:Slave:(11) 1.086548] [jmsg/INFO] Received Finalize. I'm done. See you!\r
+> [Soucy:Slave:(6) 1.120464] [jmsg/INFO] Received Finalize. I'm done. See you!\r
+> [Casavant:Forwarder:(3) 1.154764] [jmsg/INFO] I'm done. See you!\r
+> [Monique:Slave:(12) 1.154764] [jmsg/INFO] Received Finalize. I'm done. See you!\r
+> [Jacquelin:Master:(1) 1.185911] [jmsg/INFO] Goodbye now!\r
+> [Jackson:Forwarder:(2) 1.185911] [jmsg/INFO] All tasks have been dispatched. Let's tell everybody the computation is over.\r
+> [Kuenning:Slave:(7) 1.186360] [jmsg/INFO] Received Finalize. I'm done. See you!\r
+> [Browne:Slave:(8) 1.325058] [jmsg/INFO] Received Finalize. I'm done. See you!\r
+> [Jackson:Forwarder:(2) 1.532781] [jmsg/INFO] I'm done. See you!\r
+> [Stephen:Slave:(9) 1.532781] [jmsg/INFO] Received Finalize. I'm done. See you!\r
+\r
+\r
diff --git a/examples/async/asyncDeployment.xml b/examples/async/asyncDeployment.xml
new file mode 100644 (file)
index 0000000..5b545d3
--- /dev/null
@@ -0,0 +1,49 @@
+<?xml version='1.0'?>
+<!DOCTYPE platform SYSTEM "http://simgrid.gforge.inria.fr/simgrid.dtd">
+<platform version="3">
+  <process host="Jacquelin" function="async.Master">
+     <argument value="5"/>     <!-- Amount of tasks to dispatch -->
+     <argument value="50000"/> <!-- Computation size of each task -->
+     <argument value="10"/>    <!-- Communication size of each one -->
+     <argument value="7"/>     <!-- Amount of slaves waiting for orders -->
+  </process>
+  
+  <process host="Jackson" function="async.Forwarder">
+     <argument value="0"/>  <!-- Input mailbox -->
+     <argument value="7"/>  <!-- First output mailbox -->
+     <argument value="8"/>  <!-- Last output mailbox -->
+  </process>
+  <process host="Casavant" function="async.Forwarder">
+     <argument value="1"/>  <!-- Input mailbox -->
+     <argument value="9"/>  <!-- First output mailbox -->
+     <argument value="10"/> <!-- Last output mailbox -->
+  </process>
+  
+  <process host="iRMX" function="async.Slave">
+     <argument value="2"/>  <!-- Input mailbox -->
+  </process>
+  <process host="Bousquet" function="async.Slave">
+     <argument value="3"/>  <!-- Input mailbox -->
+  </process>  
+  <process host="Soucy" function="async.Slave">
+     <argument value="4"/>  <!-- Input mailbox -->
+  </process>  
+  <process host="Kuenning" function="async.Slave">
+     <argument value="5"/>  <!-- Input mailbox -->
+  </process>  
+  <process host="Browne" function="async.Slave">
+     <argument value="6"/>  <!-- Input mailbox -->
+  </process>  
+  <process host="Stephen" function="async.Slave">
+     <argument value="7"/>  <!-- Input mailbox -->
+  </process>  
+  <process host="Robert" function="async.Slave">
+     <argument value="8"/>  <!-- Input mailbox -->
+  </process>  
+  <process host="Sirois" function="async.Slave">
+     <argument value="9"/>  <!-- Input mailbox -->
+  </process>  
+  <process host="Monique" function="async.Slave">
+     <argument value="10"/>  <!-- Input mailbox -->
+  </process>  
+</platform>
index b5f8765..3f3df21 100644 (file)
@@ -427,4 +427,6 @@ final class MsgNative {
         */ 
        final static native void taskSendBounded(String alias, Task task, double maxrate) throws TransferFailureException,HostFailureException,TimeoutException;
 
+       final static native void taskDSend(String mailbox, Task task);
+
 }
index 94d6bf6..d2d657e 100644 (file)
@@ -365,6 +365,15 @@ public abstract class Process extends Thread {
                        Msg.info("[" + this.msgName() + "/" + this.getHost().getName() +
                                        "] args[" + i + "]=" + (String) (this.args.get(i)));
        }
+    /**
+     * Let the simulated process sleep for the given amount of millisecond in the simulated world.
+     * 
+     *  You don't want to use sleep instead, because it would freeze your simulation 
+     *  run without any impact on the simulated world.
+     * @param millis
+     */
+    public native void simulatedSleep(double seconds);
+
        /**
         * This method runs the process. Il calls the method function that you must overwrite.
         */
index c151961..907c26f 100644 (file)
@@ -146,6 +146,14 @@ public class Task {
                        MsgNative.taskDestroy(this);
        }
 
+       /** Send the task asynchronously on the mailbox identified by the specified name, 
+        *  with no way to retrieve whether the communication succeeded or not
+        * 
+        */
+       public void dsend(String mailbox) {
+               MsgNative.taskDSend(mailbox, this);
+       } 
+       
        /**
         * Sends the task on the mailbox identified by the specified name 
         *
index 61d916b..f10f465 100644 (file)
@@ -140,6 +140,22 @@ Java_org_simgrid_msg_MsgNative_processSuspend(JNIEnv * env, jclass cls,
 
 }
 
+JNIEXPORT void JNICALL
+Java_org_simgrid_msg_Process_simulatedSleep(JNIEnv * env, jobject jprocess,
+                                           jdouble jseconds) {
+         m_process_t process = jprocess_to_native_process(jprocess, env);
+
+         if (!process) {
+           jxbt_throw_notbound(env, "process", 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"));
+}
+
+
 JNIEXPORT void JNICALL
 Java_org_simgrid_msg_MsgNative_processResume(JNIEnv * env, jclass cls,
                                          jobject jprocess)
@@ -967,6 +983,41 @@ Java_org_simgrid_msg_MsgNative_taskSend(JNIEnv * env, jclass cls,
                          MSG_task_get_name(task), alias));
 }
 
+static void msg_task_cancel_on_failed_dsend(void*t) {
+       m_task_t task = t;
+       JNIEnv *env =get_current_thread_env();
+       jobject jtask_global = MSG_task_get_data(task);
+
+       /* Destroy the global ref so that the JVM can free the stuff */
+       (*env)->DeleteGlobalRef(env, jtask_global);
+       MSG_task_set_data(task, NULL);
+       MSG_task_destroy(task);
+}
+
+JNIEXPORT void JNICALL
+Java_org_simgrid_msg_MsgNative_taskDSend(JNIEnv * env, jclass cls,
+                                    jstring jalias, jobject jtask)
+{
+
+  const char *alias = (*env)->GetStringUTFChars(env, jalias, 0);
+
+  m_task_t task = jtask_to_native_task(jtask, env);
+
+
+  if (!task) {
+    (*env)->ReleaseStringUTFChars(env, jalias, alias);
+    jxbt_throw_notbound(env, "task", jtask);
+    return;
+  }
+
+  /* Pass a global ref to the Jtask into the Ctask so that the receiver can use it */
+  MSG_task_set_data(task, (void *) (*env)->NewGlobalRef(env, jtask));
+  MSG_task_dsend(task, alias, msg_task_cancel_on_failed_dsend);
+
+  (*env)->ReleaseStringUTFChars(env, jalias, alias);
+}
+
+
 JNIEXPORT void JNICALL
 Java_org_simgrid_msg_MsgNative_taskSendBounded(JNIEnv * env, jclass cls,
                                            jstring jalias, jobject jtask,
index bfa02c1..9fdbaeb 100644 (file)
@@ -32,7 +32,7 @@ Java_org_simgrid_msg_MsgNative_processCreate(JNIEnv * env, jclass cls,
  * Signature   (Lsimgrid/msg/Process;)V
  */
 JNIEXPORT void JNICALL
-Java_org_simgrid_msg_MsgNative_processSuspend(JNIEnv * env, jclass cls,
+Java_org_simgrid_msg_MsgNative_processSuspend(JNIEnv * env, jobject obj,
                                           jobject jprocess);
 
 /*
@@ -43,6 +43,12 @@ Java_org_simgrid_msg_MsgNative_processSuspend(JNIEnv * env, jclass cls,
 JNIEXPORT void JNICALL Java_org_simgrid_msg_MsgNative_processResume
     (JNIEnv *, jclass, jobject);
 
+
+JNIEXPORT void JNICALL
+Java_org_simgrid_msg_Process_simulatedSleep(JNIEnv * env, jclass cls,
+                                           jdouble jmillis);
+
+
 /*
  * Class               simgrid_msg_Msg
  * Method              processIsSuspended
@@ -273,17 +279,14 @@ JNIEXPORT jobject JNICALL
     Java_org_simgrid_msg_MsgNative_taskReceive
     (JNIEnv *, jclass, jstring, jdouble, jobject);
 
+JNIEXPORT void JNICALL
+Java_org_simgrid_msg_MsgNative_taskDSend(JNIEnv * env, jclass cls,
+                                    jstring jalias, jobject jtask);
+
 JNIEXPORT void JNICALL
     Java_org_simgrid_msg_MsgNative_taskSend
     (JNIEnv *, jclass, jstring, jobject, jdouble);
 
-/*
- * Class               simgrid_msg_Msg
- * Method              getErrCode
- * Signature   ()I
- */
-JNIEXPORT jint JNICALL Java_org_simgrid_msg_Msg_getErrCode(JNIEnv *, jclass);
-
 /*
  * Class               simgrid_msg_Msg
  * Method              getClock