Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of git+ssh://scm.gforge.inria.fr//gitroot/simgrid/simgrid
[simgrid.git] / examples / scala / master_slave_kill / Master.scala
1 /*
2  * Master of a basic master/slave example in Java
3  *
4  * Copyright 2006-2012 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
12 import Stream._
13 import org.simgrid.msg.HostNotFoundException
14 import org.simgrid.msg.Msg
15 import org.simgrid.msg.MsgException
16 import org.simgrid.msg.Process
17 import org.simgrid.msg.Task
18
19 class Master(hostname:String, name:String) extends Process(hostname, name) {
20   def main(args:Array[String]) {
21     Msg.info("Master Hello!")
22     var process2:Slave = null
23     
24     //Create a slave on host "alice"
25     try {
26       Msg.info("Create process on host 'alice'")
27       process2 = new Slave("alice","slave")
28       process2.start()
29     } catch {
30       case e:MsgException => println("Process2!")
31     }
32     
33     //Wait for slave "alice"
34     continually({Task.receive("mail1")})
35       .takeWhile(!_.isInstanceOf[FinalizeTask])
36       .force // to force the list to be compute
37     
38     Msg.info("Received mail1!")
39     process2.kill()
40     Msg.info("Process2 is now killed, should exit now")
41   }
42 }