2 * Copyright 2006,2007,2010. 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.
10 public class Forwarder extends simgrid.msg.Process {
12 public void main(String[] args) throws NativeException {
13 if (args.length < 3) {
14 Msg.info("Forwarder needs 3 arguments (input mailbox, first output mailbox, last one)");
15 Msg.info("Got "+args.length+" instead");
18 int input = Integer.valueOf(args[0]).intValue();
19 int firstOutput = Integer.valueOf(args[1]).intValue();
20 int lastOutput = Integer.valueOf(args[2]).intValue();
23 int slavesCount = lastOutput - firstOutput + 1;
24 Msg.info("Receiving on 'slave_"+input+"'");
26 Task task = Task.receive("slave_"+input);
28 if (task instanceof FinalizeTask) {
29 Msg.info("Got a finalize task. Let's forward that we're done.");
31 for (int cpt = firstOutput; cpt<=lastOutput; cpt++) {
32 Task tf = new FinalizeTask();
33 tf.send("slave_"+cpt);
37 int dest = firstOutput + (taskCount % slavesCount);
39 Msg.info("Sending \"" + task.getName() + "\" to \"slave_" + dest + "\"");
40 task.send("slave_"+dest);
46 Msg.info("I'm done. See you!");