Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'mc' into mc++
[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 'alice'");
28                     process2 = new Slave("alice","slave");
29                     process2.start();
30                 } catch (MsgException e){
31                     System.out.println("Process2!");
32                 }
33                 
34                 //Wait for slave "alice"
35                 while(true)
36                 {  
37                                 Task task = Task.receive("mail1");
38                                 if (task instanceof FinalizeTask) {
39                                         Msg.info("Received mail1!");
40                                         break;  
41                                 }
42                 }
43                 process2.kill();
44
45                 Msg.info("Process2 is now killed, should exit now");
46         }
47 }