Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Smelly code, smelly code, how are they writing you
[simgrid.git] / examples / java / app / masterworker / Worker.java
1 /* Copyright (c) 2006-2014. 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 app.masterworker;
8
9 import org.simgrid.msg.Host;
10 import org.simgrid.msg.HostFailureException;
11 import org.simgrid.msg.Msg;
12 import org.simgrid.msg.Task;
13 import org.simgrid.msg.TaskCancelledException;
14 import org.simgrid.msg.TimeoutException;
15 import org.simgrid.msg.TransferFailureException;
16 import org.simgrid.msg.Process;
17
18 public class Worker extends Process {
19   public Worker(Host host, String name, String[]args) {
20     super(host,name,args);
21   }
22   public void main(String[] args) throws TransferFailureException, HostFailureException, TimeoutException {
23     if (args.length < 1) {
24       Msg.info("Worker needs 1 argument (its number)");
25       System.exit(1);
26     }
27
28     int num = Integer.parseInt(args[0]);
29     Msg.debug("Receiving on 'worker_"+num+"'");
30
31     while(true) {  
32       Task task = Task.receive("worker_"+num);
33
34       if (task.getName().equals("finalize")) {
35         break;
36       }
37       Msg.info("Received \"" + task.getName() +  "\". Processing it.");
38       try {
39         task.execute();
40       } catch (TaskCancelledException e) {
41         e.printStackTrace();
42       }
43     }
44
45     Msg.info("Received Finalize. I'm done. See you!");
46   }
47 }