Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
full redesign of this example
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Tue, 29 Mar 2016 17:43:39 +0000 (19:43 +0200)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Tue, 29 Mar 2016 17:43:39 +0000 (19:43 +0200)
 + (almost) match the behavior of examples/msg/process-kill now

.gitignore
examples/java/kill/CMakeLists.txt [moved from examples/java/master_slave_kill/CMakeLists.txt with 65% similarity]
examples/java/kill/Killer.java [new file with mode: 0644]
examples/java/kill/Main.java [moved from examples/java/master_slave_kill/MsKill.java with 73% similarity]
examples/java/kill/Victim.java [new file with mode: 0644]
examples/java/kill/kill.tesh [new file with mode: 0644]
examples/java/master_slave_kill/FinalizeTask.java [deleted file]
examples/java/master_slave_kill/Master.java [deleted file]
examples/java/master_slave_kill/Slave.java [deleted file]
examples/java/master_slave_kill/kill.tesh [deleted file]
tools/cmake/DefinePackages.cmake

index 5cea948..146f5df 100644 (file)
@@ -980,8 +980,7 @@ examples/java/commTime/java_commTime_compiled
 examples/java/energy/java_energy_compiled
 examples/java/io/java_io_compiled
 examples/java/kademlia/java_kademlia_compiled
 examples/java/energy/java_energy_compiled
 examples/java/io/java_io_compiled
 examples/java/kademlia/java_kademlia_compiled
-examples/java/master_slave_bypass/java_master_slave_bypass_compiled
-examples/java/master_slave_kill/java_master_slave_kill_compiled
+examples/java/kill/java_kill_compiled
 examples/java/masterworker/java_masterworker_compiled
 examples/java/migration/java_migration_compiled
 examples/java/mutualExclusion/java_mutualExclusion_compiled
 examples/java/masterworker/java_masterworker_compiled
 examples/java/migration/java_migration_compiled
 examples/java/mutualExclusion/java_mutualExclusion_compiled
similarity index 65%
rename from examples/java/master_slave_kill/CMakeLists.txt
rename to examples/java/kill/CMakeLists.txt
index 20cae75..4a7eaf1 100644 (file)
@@ -1,6 +1,5 @@
-set(example java_master_slave_kill)
-set(sources ${CMAKE_CURRENT_SOURCE_DIR}/MsKill.java ${CMAKE_CURRENT_SOURCE_DIR}/FinalizeTask.java
-            ${CMAKE_CURRENT_SOURCE_DIR}/Master.java ${CMAKE_CURRENT_SOURCE_DIR}/Slave.java)
+set(example java_kill)
+set(sources ${CMAKE_CURRENT_SOURCE_DIR}/Main.java ${CMAKE_CURRENT_SOURCE_DIR}/Killer.java ${CMAKE_CURRENT_SOURCE_DIR}/Victim.java)
 
 if(enable_java)
   add_custom_command(
 
 if(enable_java)
   add_custom_command(
@@ -12,9 +11,8 @@ if(enable_java)
     COMMAND ${CMAKE_COMMAND} -E touch ${example}_compiled
   )
   add_custom_target(${example} ALL DEPENDS ${example}_compiled)
     COMMAND ${CMAKE_COMMAND} -E touch ${example}_compiled
   )
   add_custom_target(${example} ALL DEPENDS ${example}_compiled)
-  ADD_TESH(java-kill --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/java --setenv classpath=${TESH_CLASSPATH} --cd ${CMAKE_BINARY_DIR}/examples/java ${CMAKE_HOME_DIRECTORY}/examples/java/master_slave_kill/kill.tesh)
+  ADD_TESH(java-kill --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/java --setenv classpath=${TESH_CLASSPATH} --cd ${CMAKE_BINARY_DIR}/examples/java ${CMAKE_HOME_DIRECTORY}/examples/java/kill/kill.tesh)
 endif()
 
 set(tesh_files    ${tesh_files}    ${CMAKE_CURRENT_SOURCE_DIR}/kill.tesh  PARENT_SCOPE)
 endif()
 
 set(tesh_files    ${tesh_files}    ${CMAKE_CURRENT_SOURCE_DIR}/kill.tesh  PARENT_SCOPE)
-set(xml_files     ${xml_files}                                            PARENT_SCOPE)
 set(examples_src  ${examples_src}  ${sources}                             PARENT_SCOPE)
 set(examples_src  ${examples_src}  ${sources}                             PARENT_SCOPE)
diff --git a/examples/java/kill/Killer.java b/examples/java/kill/Killer.java
new file mode 100644 (file)
index 0000000..08bd9b6
--- /dev/null
@@ -0,0 +1,39 @@
+/* Master of a basic master/slave example in Java */
+
+/* Copyright (c) 2006-2014. 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 kill;
+import org.simgrid.msg.Msg;
+import org.simgrid.msg.Process;
+import org.simgrid.msg.MsgException;
+import org.simgrid.msg.HostNotFoundException;
+
+import kill.Victim;
+
+public class Killer extends Process {
+  public Killer(String hostname, String name) throws HostNotFoundException {
+    super(hostname, name);
+  }
+  public void main(String[] args) throws MsgException {
+    Victim poorVictim = null;
+    Msg.info("Hello!");
+    try {
+      poorVictim = new Victim("Boivin","victim");
+      poorVictim.start();
+    } catch (MsgException e){
+      System.out.println("Cannot create the victim process!");
+    }
+    sleep(10000);
+    Msg.info("Resume Process");
+    poorVictim.resume();
+    sleep(1000);
+    Msg.info("Kill Process");
+    poorVictim.kill();
+
+    Msg.info("Ok, goodbye now.");
+  }
+}
similarity index 73%
rename from examples/java/master_slave_kill/MsKill.java
rename to examples/java/kill/Main.java
index 7a4a680..baacd19 100644 (file)
@@ -4,17 +4,13 @@
 /* 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. */
 
 /* 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 master_slave_kill;
+package kill;
 
 import org.simgrid.msg.Msg;
 import org.simgrid.msg.MsgException;
 import org.simgrid.msg.NativeException;
 
 
 import org.simgrid.msg.Msg;
 import org.simgrid.msg.MsgException;
 import org.simgrid.msg.NativeException;
 
-public class MsKill {
-  /* 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 class Main {
   public static void main(String[] args) throws NativeException {
     /* initialize the MSG simulation. Must be done before anything else (even logging). */
     Msg.init(args);
   public static void main(String[] args) throws NativeException {
     /* initialize the MSG simulation. Must be done before anything else (even logging). */
     Msg.init(args);
@@ -22,8 +18,8 @@ public class MsKill {
 
     /* bypass deploymemt */
     try {
 
     /* bypass deploymemt */
     try {
-      Master process1 = new Master("Jacquelin","master");
-      process1.start();
+      Killer killer = new Killer("Jacquelin","killer");
+      killer.start();
     } catch (MsgException e){
       System.out.println("Create processes failed!");
     }
     } catch (MsgException e){
       System.out.println("Create processes failed!");
     }
diff --git a/examples/java/kill/Victim.java b/examples/java/kill/Victim.java
new file mode 100644 (file)
index 0000000..dfa61c0
--- /dev/null
@@ -0,0 +1,27 @@
+/* Copyright (c) 2006-2014. 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 kill;
+import org.simgrid.msg.Msg;
+import org.simgrid.msg.Task;
+import org.simgrid.msg.Process;
+import org.simgrid.msg.MsgException;
+import org.simgrid.msg.HostNotFoundException;
+
+public class Victim extends Process {
+  public Victim(String hostname, String name) throws HostNotFoundException {
+    super(hostname, name);
+  }
+  public void main(String[] args) throws MsgException{
+    Msg.info("Hello!");
+    Msg.info("Suspending myself");
+    suspend();
+    Msg.info("OK, OK. Let's work");
+    Task task = new Task("work", 1e9, 0);
+    task.execute();
+    Msg.info("Bye");
+  }
+}
\ No newline at end of file
diff --git a/examples/java/kill/kill.tesh b/examples/java/kill/kill.tesh
new file mode 100644 (file)
index 0000000..defce7f
--- /dev/null
@@ -0,0 +1,14 @@
+#! tesh
+
+! output sort 19
+
+$ java -classpath ${classpath:=.} kill/Main ${srcdir:=.}/../platforms/platform.xml --lof=no_loc
+> [0.000000] [jmsg/INFO] Using regular java threads.
+> [11.000000] [jmsg/INFO] MSG_main finished; Cleaning up the simulation...
+> [Boivin:victim:(2) 0.000000] [jmsg/INFO] Hello!
+> [Boivin:victim:(2) 0.000000] [jmsg/INFO] Suspending myself
+> [Boivin:victim:(2) 10.000000] [jmsg/INFO] OK, OK. Let's work
+> [Jacquelin:killer:(1) 0.000000] [jmsg/INFO] Hello!
+> [Jacquelin:killer:(1) 10.000000] [jmsg/INFO] Resume Process
+> [Jacquelin:killer:(1) 11.000000] [jmsg/INFO] Kill Process
+> [Jacquelin:killer:(1) 11.000000] [jmsg/INFO] Ok, goodbye now.
diff --git a/examples/java/master_slave_kill/FinalizeTask.java b/examples/java/master_slave_kill/FinalizeTask.java
deleted file mode 100644 (file)
index 0af5a86..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-/* Copyright (c) 2006-2014. 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 master_slave_kill;
-import org.simgrid.msg.Task;
-
-public class FinalizeTask extends Task {
-   public FinalizeTask() {
-      super("finalize",0,0);
-   }
-}
diff --git a/examples/java/master_slave_kill/Master.java b/examples/java/master_slave_kill/Master.java
deleted file mode 100644 (file)
index 8cb481e..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-/* Master of a basic master/slave example in Java */
-
-/* Copyright (c) 2006-2014. 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 master_slave_kill;
-import org.simgrid.msg.HostNotFoundException;
-import org.simgrid.msg.Msg;
-import org.simgrid.msg.MsgException;
-import org.simgrid.msg.Process;
-import org.simgrid.msg.Task;
-
-import master_slave_kill.FinalizeTask;
-
-public class Master extends Process {
-  public Master(String hostname, String name) throws HostNotFoundException {
-    super(hostname, name);
-  }
-  public void main(String[] args) throws MsgException {
-    Msg.info("Master Hello!");
-    Process process2 = null;
-    //Create a slave on host "alice"
-    try {
-      Msg.info("Create process on host 'Boivin'");
-      process2 = new Slave("Boivin","slave");
-      process2.start();
-    } catch (MsgException e){
-      System.out.println("Process2!");
-    }
-
-    //Wait for slave "alice"
-    while(true) {
-      Task task = Task.receive("mail1");
-      if (task instanceof FinalizeTask) {
-        Msg.info("Received mail1!");
-        break;
-      }
-    }
-    process2.kill();
-
-    Msg.info("Process2 is now killed, should exit now");
-  }
-}
diff --git a/examples/java/master_slave_kill/Slave.java b/examples/java/master_slave_kill/Slave.java
deleted file mode 100644 (file)
index 847b8fc..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-/* Copyright (c) 2006-2014. 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 master_slave_kill;
-import org.simgrid.msg.HostFailureException;
-import org.simgrid.msg.HostNotFoundException;
-import org.simgrid.msg.Msg;
-import org.simgrid.msg.MsgException;
-import org.simgrid.msg.Task;
-import org.simgrid.msg.TimeoutException;
-import org.simgrid.msg.TransferFailureException;
-import org.simgrid.msg.NativeException;
-import org.simgrid.msg.Process;
-
-import master_slave_kill.FinalizeTask;
-
-public class Slave extends Process {
-  public Slave(String hostname, String name) throws HostNotFoundException {
-    super(hostname, name);
-  }
-  public void main(String[] args) throws TransferFailureException, HostFailureException, TimeoutException, NativeException {
-    Msg.info("Slave Hello!");
-
-    FinalizeTask task = new FinalizeTask();
-    Msg.info("Send Mail1!");
-    task.send("mail1");
-
-    try {
-      Task.receive("mail2");
-    } catch (MsgException e) {
-      Msg.debug("Received failed");
-      return;
-    }
-    Msg.info("Receive Mail2!");
-  }
-}
diff --git a/examples/java/master_slave_kill/kill.tesh b/examples/java/master_slave_kill/kill.tesh
deleted file mode 100644 (file)
index 9281484..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-#! tesh
-
-! output sort 19
-
-$ java -classpath ${classpath:=.} master_slave_kill/MsKill ${srcdir:=.}/../platforms/platform.xml
-> [0.000000] [jmsg/INFO] Using regular java threads.
-> [Jacquelin:master:(1) 0.000000] [jmsg/INFO] Master Hello!
-> [Jacquelin:master:(1) 0.000000] [jmsg/INFO] Create process on host 'Boivin'
-> [Boivin:slave:(2) 0.000000] [jmsg/INFO] Slave Hello!
-> [Boivin:slave:(2) 0.000000] [jmsg/INFO] Send Mail1!
-> [Jacquelin:master:(1) 1.048881] [jmsg/INFO] Received mail1!
-> [Jacquelin:master:(1) 1.048881] [jmsg/INFO] Process2 is now killed, should exit now
-> [1.048881] [jmsg/INFO] MSG_main finished; Cleaning up the simulation...
index c725a9b..f136617 100644 (file)
@@ -933,7 +933,7 @@ set(CMAKEFILES_TXT
   examples/java/energy/CMakeLists.txt
   examples/java/io/CMakeLists.txt
   examples/java/kademlia/CMakeLists.txt
   examples/java/energy/CMakeLists.txt
   examples/java/io/CMakeLists.txt
   examples/java/kademlia/CMakeLists.txt
-  examples/java/master_slave_kill/CMakeLists.txt
+  examples/java/kill/CMakeLists.txt
   examples/java/masterworker/CMakeLists.txt
   examples/java/migration/CMakeLists.txt
   examples/java/mutualExclusion/CMakeLists.txt
   examples/java/masterworker/CMakeLists.txt
   examples/java/migration/CMakeLists.txt
   examples/java/mutualExclusion/CMakeLists.txt