Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
e3dc16e2e12c83ef3640c57f7acd6fe1b0517391
[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                 Process.kill(process2);
45
46                 Msg.info("Process2 is now killed, should exit now");
47         }
48 }