Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'surf++'
[simgrid.git] / examples / java / cloud / Slave.java
1 /*
2  * Copyright (c) 2012-2013. The SimGrid Team.
3  * All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the license (GNU LGPL) which comes with this package. 
7  */
8 package cloud;
9
10 import org.simgrid.msg.Host;
11 import org.simgrid.msg.Msg;
12 import org.simgrid.msg.MsgException;
13 import org.simgrid.msg.Process;
14 import org.simgrid.msg.Task;
15
16 public class Slave extends Process {
17         private int number;
18         public Slave(Host host, int number) {
19                 super(host,"WRK0" + number,null);
20                 this.number = number;
21         }
22         public void main(String[] args) throws MsgException {
23                 Msg.info(this.msgName() +" is listenning on MBOX:WRK0"+ number);
24                 while(true) {                   
25                         Task task;
26                         try {
27                                 task = Task.receive("MBOX:WRK0"+number);
28                         } catch (MsgException e) {
29                                 Msg.debug("Received failed. I'm done. See you!");
30                                 break;
31                         }
32                         if (task instanceof FinalizeTask) {
33                                 Msg.info("Received Finalize. I'm done. See you!");
34                                 break;
35                         }
36                         Msg.info("Received \"" + task.getName() +  "\". Processing it.");
37                         try {
38                                 task.execute();
39                         } catch (MsgException e) {
40
41                         }
42                         Msg.info(this.msgName() +" executed task (" + task.getName()+")");
43                 }
44
45                 
46         }
47 }