Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Energy, onHostDestruction: ensured ptr existence
[simgrid.git] / examples / scala / masterslave / Slave.scala
1 /*
2  * Copyright (c) 2006-2013. The SimGrid Team.
3  * All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the license (GNU LGPL) which comes with this package. 
7  */
8 package masterslave;
9
10 import Stream._
11 import org.simgrid.msg.Host
12 import org.simgrid.msg.HostFailureException
13 import org.simgrid.msg.Msg
14 import org.simgrid.msg.Task
15 import org.simgrid.msg.TaskCancelledException
16 import org.simgrid.msg.TimeoutException
17 import org.simgrid.msg.TransferFailureException
18 import org.simgrid.msg.Process
19
20 class Slave(host:Host, name:String, args:Array[String]) extends Process(host,name,args) {
21   def main(args:Array[String]){
22     if (args.length < 1) {
23       Msg.info("Slave needs 1 argument (its number)")
24       System.exit(1)
25     }
26
27     val num = args(0).toInt
28     
29     continually({Task.receive("slave_"+num)})
30       .takeWhile(!_.isInstanceOf[FinalizeTask])
31       .foreach(task => {
32         Msg.info("Received \"" + task.getName() +  "\". Processing it.");
33         try {
34           task.execute();
35         } catch {
36           case e:TaskCancelledException => {}
37         }
38       })
39
40     Msg.info("Received Finalize. I'm done. See you!")
41   }
42 }