Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
f9d16a3ce6c3dd154bdd7099d3987b18f5128165
[simgrid.git] / examples / master_slave_kill / Master.java
1 /*
2  * Master of a basic master/slave example in Java
3  *
4  * Copyright 2006,2007,2010 The SimGrid Team. 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
10 package master_slave_kill;
11 import org.simgrid.msg.HostNotFoundException;
12 import org.simgrid.msg.Msg;
13 import org.simgrid.msg.MsgException;
14 import org.simgrid.msg.Process;
15 import org.simgrid.msg.Task;
16
17 import master_slave_kill.FinalizeTask;
18
19 public class Master extends Process {
20         public Master(String hostname, String name) throws HostNotFoundException {
21                 super(hostname, name);
22         }
23         public void main(String[] args) throws MsgException {
24                 Msg.info("Master Hello!");
25                 Process process2 = null;
26                 //Create a slave on host "alice"
27                 try {
28                         Msg.info("Create process on host 'alice'");
29                     process2 = new Slave("alice","slave");
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                 
44 //              FinalizeTask task = new FinalizeTask();
45 //              Msg.info("Send Mail2!");
46 //              task.send("mail2");
47                 
48                 Process.waitFor(10);
49                 Process.kill(process2);
50                 
51         }
52 }