Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix java examples: catch exceptions on failures.
authorArnaud Giersch <arnaud.giersch@iut-bm.univ-fcomte.fr>
Sun, 3 Feb 2013 00:14:39 +0000 (01:14 +0100)
committerArnaud Giersch <arnaud.giersch@iut-bm.univ-fcomte.fr>
Sun, 3 Feb 2013 00:38:38 +0000 (01:38 +0100)
examples/java/cloud/Slave.java
examples/java/master_slave_kill/Slave.java
examples/java/startKillTime/Slave.java

index 8f7cde3..01e646f 100644 (file)
@@ -21,9 +21,15 @@ public class Slave extends Process {
        public void main(String[] args) throws MsgException {
                while(true) {                   
                        Msg.info("Receiving on " + "slave_" + number);
-                       Task task = Task.receive("slave_"+number);      
-
+                       Task task;
+                        try {
+                                task = Task.receive("slave_"+number);
+                        } catch (MsgException e) {
+                                Msg.debug("Received failed. I'm done. See you!");
+                                break;
+                        }
                        if (task instanceof FinalizeTask) {
+                                Msg.info("Received Finalize. I'm done. See you!");
                                break;
                        }
                        Msg.info("Received \"" + task.getName() +  "\". Processing it.");
@@ -35,7 +41,6 @@ public class Slave extends Process {
                        Msg.info("\"" + task.getName() + "\" done ");
                }
 
-               Msg.info("Received Finalize. I'm done. See you!");
                
        }
 }
\ No newline at end of file
index 8e85ef1..e52dd93 100644 (file)
@@ -8,6 +8,7 @@ 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;
@@ -26,7 +27,13 @@ public class Slave extends Process {
        Msg.info("Send Mail1!");
        task.send("mail1");
        
-       Task task2 = Task.receive("mail2");
-        Msg.info("Receive Mail2!");
+       Task task2;
+        try {
+                task2 = Task.receive("mail2");
+        } catch (MsgException e) {
+                Msg.debug("Received failed");
+                return;
+        }
+       Msg.info("Receive Mail2!");
   }
 }
index d3f7036..e9942f0 100644 (file)
@@ -6,6 +6,7 @@
  */
 package startKillTime;
 import org.simgrid.msg.Host;
+import org.simgrid.msg.MsgException;
 import org.simgrid.msg.HostFailureException;
 import org.simgrid.msg.HostNotFoundException;
 import org.simgrid.msg.TransferFailureException;
@@ -22,8 +23,12 @@ public class Slave extends Process {
        } 
        public void main(String[] args) throws TransferFailureException, HostFailureException, TimeoutException {
                Msg.info("Hello!");
-               waitFor(10.0);
-               Msg.info("OK, goodbye now.");
+                try {
+                        waitFor(10.0);
+                        Msg.info("OK, goodbye now.");
+                } catch (MsgException e) {
+                        Msg.debug("Wait cancelled.");
+                }
        
   }
 }