Logo AND Algorithmique Numérique Distribuée

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