Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of git+ssh://scm.gforge.inria.fr//gitroot/simgrid/simgrid
[simgrid.git] / examples / java / cloud / Slave.java
1 /* Copyright (c) 2012-2016. The SimGrid Team.
2  * 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.Msg;
10 import org.simgrid.msg.Host;
11 import org.simgrid.msg.Task;
12 import org.simgrid.msg.Process;
13 import org.simgrid.msg.MsgException;
14
15 public class Slave extends Process {
16   private int number;
17   public Slave(Host host, int number) {
18     super(host,"WRK0" + number,null);
19     this.number = number;
20   }
21
22   public void main(String[] args) throws MsgException {
23     Msg.info(this.getName() +" 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       Msg.info(this.getName() +" executed task (" + task.getName()+")");
42     }
43   }
44 }