Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Remove the Acmacro directory.
[simgrid.git] / examples / java / comm_time / Slave.java
index 086a192..539fd34 100644 (file)
@@ -1,8 +1,5 @@
 /*
- * $Id$
- *
- * Copyright 2006,2007 Martin Quinson, Malek Cherier         
- * All rights reserved. 
+ * 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. 
 import simgrid.msg.*;
 
 public class Slave extends simgrid.msg.Process {
-   
-   public void main(String[] args) throws JniException, NativeException {
-      
-      Msg.info("Hello i'm a slave");
+   public void main(String[] args) throws MsgException {
+      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+"'");
       
-      Channel channel = new Channel(0);
-               
-      while(true) {
-        int a;
-        double time1,time2;
-         
-        time1 = Msg.getClock();
+      while(true) { 
+        Task task = Task.receive("slave_"+num);        
         
-        CommTimeTask task = (CommTimeTask)channel.get();
-        time2 = Msg.getClock();
-                               
-        if(task.getData() == 221297) {
-           Msg.info("Received " + task.getName() + " " + getHost().getName());
+        if (task instanceof FinalizeTask) {
            break;
         }
-            
-        if(time1 < task.getTime())
-          time1 = task.getTime();
-        
-        Msg.info("Processing \"" + task.getName() + "\" " + getHost().getName() + 
-                 " (Communication time : " +  (time2 - time1) + ")");
-            
         task.execute();
-        
-        
-      }
+       }
        
-      Msg.info("I'm done. See you!" + getHost().getName());
-   }
+      Msg.info("Received Finalize. I'm done. See you!");
+    }
 }
\ No newline at end of file