Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge commit '045db1657e870c721be490b411868f4181a12ced' into surf++
[simgrid.git] / examples / java / master_slave_bypass / 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_bypass;
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_bypass.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         
27         //Create a slave on host "alice"
28         try {
29                         Msg.info("Create process on host 'alice'");
30                 new Slave("alice","process2").start();
31             }
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("alice");
40                         if (task instanceof FinalizeTask) {
41                                 Msg.info("Received Finalize. I'm done. See you!");
42                                 break;  
43                         }
44         }
45         }
46 }