Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Change the way the objects are created in ApplicationHandler: they are
[simgrid.git] / examples / basic / 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 basic;
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 Slave(Host host, String name, String[]args) {
18                 super(host,name,args);
19         }
20         public void main(String[] args) throws TransferFailureException, HostFailureException, TimeoutException {
21                 if (args.length < 1) {
22                         Msg.info("Slave needs 1 argument (its number)");
23                         System.exit(1);
24                 }
25
26                 int num = Integer.valueOf(args[0]).intValue();
27                 //Msg.info("Receiving on 'slave_"+num+"'");
28
29                 while(true) {  
30                         Task task = Task.receive("slave_"+num); 
31
32                         if (task instanceof FinalizeTask) {
33                                 break;
34                         }
35                         Msg.info("Received \"" + task.getName() +  "\". Processing it.");
36                         try {
37                                 task.execute();
38                         } catch (TaskCancelledException e) {
39
40                         }
41                 //      Msg.info("\"" + task.getName() + "\" done ");
42                 }
43
44                 Msg.info("Received Finalize. I'm done. See you!");
45         }
46 }