2 * Copyright (c) 2006-2013. The SimGrid Team.
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.
12 import org.simgrid.msg.Host
13 import org.simgrid.msg.Msg
14 import org.simgrid.msg.MsgException
15 import org.simgrid.msg.Task
16 import org.simgrid.msg.Process
18 class Forwarder(host:Host, name:String, args:Array[String]) extends Process(host,name,args) {
20 def main(args: Array[String]){
21 if (args.length < 3) {
22 Msg.info("Forwarder needs 3 arguments (input mailbox, first output mailbox, last one)")
23 Msg.info("Got "+args.length+" instead")
26 val input = args(0).toInt
27 val firstOutput = args(1).toInt
28 val lastOutput = args(2).toInt
31 val slavesCount = lastOutput - firstOutput + 1
32 Msg.info("Receiving on 'slave_"+input+"'")
35 continually({Task.receive("slave_"+input)})
36 .takeWhile(!_.isInstanceOf[FinalizeTask])
38 val dest = firstOutput + (taskCount % slavesCount)
39 Msg.info("Sending \"" + task.getName() + "\" to \"slave_" + dest + "\"")
40 task.send("slave_"+dest)
44 Msg.info("Got a finalize task. Let's forward that we're done.")
45 for (cpt <- firstOutput to lastOutput) {
46 val tf = new FinalizeTask()
50 Msg.info("I'm done. See you!")