Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
8cb481e0b505004c50f8e3b16be7c58be5fd16df
[simgrid.git] / examples / java / master_slave_kill / Master.java
1 /* Master of a basic master/slave example in Java */
2
3 /* Copyright (c) 2006-2014. The SimGrid Team.
4  * All rights reserved.                                                     */
5
6 /* This program is free software; you can redistribute it and/or modify it
7  * under the terms of the license (GNU LGPL) which comes with this package. */
8
9 package master_slave_kill;
10 import org.simgrid.msg.HostNotFoundException;
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 import master_slave_kill.FinalizeTask;
17
18 public class Master extends Process {
19   public Master(String hostname, String name) throws HostNotFoundException {
20     super(hostname, name);
21   }
22   public void main(String[] args) throws MsgException {
23     Msg.info("Master Hello!");
24     Process process2 = null;
25     //Create a slave on host "alice"
26     try {
27       Msg.info("Create process on host 'Boivin'");
28       process2 = new Slave("Boivin","slave");
29       process2.start();
30     } catch (MsgException e){
31       System.out.println("Process2!");
32     }
33
34     //Wait for slave "alice"
35     while(true) {
36       Task task = Task.receive("mail1");
37       if (task instanceof FinalizeTask) {
38         Msg.info("Received mail1!");
39         break;
40       }
41     }
42     process2.kill();
43
44     Msg.info("Process2 is now killed, should exit now");
45   }
46 }