Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Change the way the threads are launched: they are now launched as
[simgrid.git] / examples / master_slave_bypass / 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_bypass;
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_bypass.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         
26         //Create a slave on host "alice"
27         try {
28                         Msg.info("Create process on host 'alice'");
29                 new Slave("alice","process2").start();
30             }
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("alice");
39                         if (task instanceof FinalizeTask) {
40                                 Msg.info("Received Finalize. I'm done. See you!");
41                                 break;  
42                         }
43         }
44         }
45 }