2 * Copyright 2006-2012. The SimGrid Team. All rights reserved.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package.
11 import org.simgrid.msg.Host
12 import org.simgrid.msg.Msg
13 import org.simgrid.msg.MsgException
14 import org.simgrid.msg.Task
15 import org.simgrid.msg.Process
17 class Forwarder(host:Host, name:String, args:Array[String]) extends Process(host,name,args) {
19 def main(args: Array[String]){
20 if (args.length < 3) {
21 Msg.info("Forwarder needs 3 arguments (input mailbox, first output mailbox, last one)")
22 Msg.info("Got "+args.length+" instead")
25 val input = args(0).toInt
26 val firstOutput = args(1).toInt
27 val lastOutput = args(2).toInt
30 val slavesCount = lastOutput - firstOutput + 1
31 Msg.info("Receiving on 'slave_"+input+"'")
34 continually({Task.receive("slave_"+input)})
35 .takeWhile(!_.isInstanceOf[FinalizeTask])
37 val dest = firstOutput + (taskCount % slavesCount)
38 Msg.info("Sending \"" + task.getName() + "\" to \"slave_" + dest + "\"")
39 task.send("slave_"+dest)
43 Msg.info("Got a finalize task. Let's forward that we're done.")
44 for (cpt <- firstOutput to lastOutput) {
45 val tf = new FinalizeTask()
49 Msg.info("I'm done. See you!")