4 * Copyright 2006,2007,2010 The SimGrid Team
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.
13 public class Forwarder extends simgrid.msg.Process {
15 public void main(String[] args) throws JniException, NativeException {
16 if (args.length < 3) {
17 Msg.info("Forwarder needs 3 arguments (input mailbox, first output mailbox, last one)");
18 Msg.info("Got "+args.length+" instead");
21 int input = Integer.valueOf(args[0]).intValue();
22 int firstOutput = Integer.valueOf(args[1]).intValue();
23 int lastOutput = Integer.valueOf(args[2]).intValue();
26 int slavesCount = lastOutput - firstOutput + 1;
27 Msg.info("Receiving on 'slave_"+input+"'");
29 Task task = Task.receive("slave_"+input);
31 if (task instanceof FinalizeTask) {
32 Msg.info("Got a finalize task. Let's forward that we're done.");
34 for (int cpt = firstOutput; cpt<=lastOutput; cpt++) {
35 Task tf = new FinalizeTask();
36 tf.send("slave_"+cpt);
40 int dest = firstOutput + (taskCount % slavesCount);
42 Msg.info("Sending \"" + task.getName() + "\" to \"slave_" + dest + "\"");
43 task.send("slave_"+dest);
49 Msg.info("I'm done. See you!");