Logo AND Algorithmique Numérique Distribuée

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