Logo AND Algorithmique Numérique Distribuée

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