Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
3d2270b0d471c27c2775efd6ba209eb2fb51b446
[simgrid.git] / examples / async / Slave.java
1 /*
2  * Copyright 2006,2007,2010. The SimGrid Team. All rights reserved. 
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. 
6  */
7 package async;
8 import org.simgrid.msg.HostFailureException;
9 import org.simgrid.msg.Msg;
10 import org.simgrid.msg.Task;
11 import org.simgrid.msg.TaskCancelledException;
12 import org.simgrid.msg.TimeoutException;
13 import org.simgrid.msg.TransferFailureException;
14 import org.simgrid.msg.Process;
15
16 public class Slave extends Process {
17         public void main(String[] args) throws TransferFailureException, HostFailureException, TimeoutException {
18                 if (args.length < 1) {
19                         Msg.info("Slave needs 1 argument (its number)");
20                         System.exit(1);
21                 }
22
23                 int num = Integer.valueOf(args[0]).intValue();
24                 //Msg.info("Receiving on 'slave_"+num+"'");
25
26                 while(true) {  
27                         Task task = Task.receive("slave_"+num); 
28
29                         if (task instanceof FinalizeTask) {
30                                 break;
31                         }
32                         Msg.info("Received \"" + task.getName() +  "\". Processing it.");
33                         try {
34                                 task.execute();
35                         } catch (TaskCancelledException e) {
36
37                         }
38                 //      Msg.info("\"" + task.getName() + "\" done ");
39                 }
40
41                 Msg.info("Received Finalize. I'm done. See you!");
42         }
43 }