Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines for 2022.
[simgrid.git] / examples / deprecated / java / cloud / masterworker / Worker.java
1 /* Copyright (c) 2012-2022. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 package cloud.masterworker;
7
8 import org.simgrid.msg.Host;
9 import org.simgrid.msg.Msg;
10 import org.simgrid.msg.MsgException;
11 import org.simgrid.msg.Process;
12 import org.simgrid.msg.Task;
13
14 public class Worker extends Process {
15   public Worker(Host host, String name) {
16     super(host, name);
17   }
18
19   public void main(String[] args) throws MsgException {
20     Msg.verb(this.getName() +" is listening on "+ getName());
21     while(true) {
22       Task task = null;
23       try {
24         task = Task.receive(getName());
25       } catch (MsgException e) {
26         Msg.info("Received failed. I'm done. See you!");
27         exit();
28       }
29       Msg.verb("Received '" + task.getName() +  "'. Processing it.");
30       task.execute();
31       Msg.verb("Done executing task '" + task.getName() +"'");
32     }
33   }
34 }