Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
rewrite to use send/recv instead of put/get (+ add READMEs)
[simgrid.git] / examples / java / comm_time / Slave.java
index 086a192..7a7ace7 100644 (file)
 import simgrid.msg.*;
 
 public class Slave extends simgrid.msg.Process {
-   
    public void main(String[] args) throws JniException, NativeException {
+      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+"'");
       
-      Msg.info("Hello i'm a slave");
-      
-      Channel channel = new Channel(0);
-               
-      while(true) {
-        int a;
-        double time1,time2;
-         
-        time1 = Msg.getClock();
+      while(true) { 
+        Task t = Task.receive("slave_"+num);   
         
-        CommTimeTask task = (CommTimeTask)channel.get();
-        time2 = Msg.getClock();
-                               
-        if(task.getData() == 221297) {
-           Msg.info("Received " + task.getName() + " " + getHost().getName());
+        if (t instanceof FinalizeTask) {
            break;
         }
-            
-        if(time1 < task.getTime())
-          time1 = task.getTime();
-        
-        Msg.info("Processing \"" + task.getName() + "\" " + getHost().getName() + 
-                 " (Communication time : " +  (time2 - time1) + ")");
-            
+        MyTask task = (MyTask)t;
         task.execute();
-        
-        
-      }
+//      Msg.info("\"" + task.getName() + "\" done ");
+       }
        
-      Msg.info("I'm done. See you!" + getHost().getName());
-   }
+      Msg.info("Received Finalize. I'm done. See you!");
+    }
 }
\ No newline at end of file