Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
model-checker : update tesh
[simgrid.git] / examples / java / cloud / Slave.java
1 /*
2  * Copyright 2012. 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 cloud;
8
9 import org.simgrid.msg.Host;
10 import org.simgrid.msg.Msg;
11 import org.simgrid.msg.MsgException;
12 import org.simgrid.msg.Process;
13 import org.simgrid.msg.Task;
14
15 public class Slave extends Process {
16         private int number;
17         public Slave(Host host, int number) {
18                 super(host,"Slave " + number,null);
19                 this.number = number;
20         }
21         public void main(String[] args) throws MsgException {
22                 while(true) {                   
23                         Msg.info("Receiving on " + "slave_" + number);
24                         Task task;
25                         try {
26                                 task = Task.receive("slave_"+number);
27                         } catch (MsgException e) {
28                                 Msg.debug("Received failed. I'm done. See you!");
29                                 break;
30                         }
31                         if (task instanceof FinalizeTask) {
32                                 Msg.info("Received Finalize. I'm done. See you!");
33                                 break;
34                         }
35                         Msg.info("Received \"" + task.getName() +  "\". Processing it.");
36                         try {
37                                 task.execute();
38                         } catch (MsgException e) {
39
40                         }
41                         Msg.info("\"" + task.getName() + "\" done ");
42                 }
43
44                 
45         }
46 }