Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of git://scm.gforge.inria.fr/simgrid/simgrid-java
[simgrid.git] / examples / masterslave / 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 masterslave;
8
9 import org.simgrid.msg.Host;
10 import org.simgrid.msg.HostFailureException;
11 import org.simgrid.msg.Msg;
12 import org.simgrid.msg.Task;
13 import org.simgrid.msg.TaskCancelledException;
14 import org.simgrid.msg.TimeoutException;
15 import org.simgrid.msg.TransferFailureException;
16 import org.simgrid.msg.Process;
17
18 public class Slave extends Process {
19         public Slave(Host host, String name, String[]args) {
20                 super(host,name,args);
21         }
22         public void main(String[] args) throws TransferFailureException, HostFailureException, TimeoutException {
23                 if (args.length < 1) {
24                         Msg.info("Slave needs 1 argument (its number)");
25                         System.exit(1);
26                 }
27
28                 int num = Integer.valueOf(args[0]).intValue();
29                 //Msg.info("Receiving on 'slave_"+num+"'");
30
31                 while(true) {  
32                         Task task = Task.receive("slave_"+num); 
33
34                         if (task instanceof FinalizeTask) {
35                                 break;
36                         }
37                         Msg.info("Received \"" + task.getName() +  "\". Processing it.");
38                         try {
39                                 task.execute();
40                         } catch (TaskCancelledException e) {
41
42                         }
43                 //      Msg.info("\"" + task.getName() + "\" done ");
44                 }
45
46                 Msg.info("Received Finalize. I'm done. See you!");
47         }
48 }