Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
9644b4de1dc68a0b69852e0c6f809688a592fc45
[simgrid.git] / examples / java / app / pingpong / Sender.java
1 /* Copyright (c) 2006-2014, 2016. The SimGrid Team.
2  * All rights reserved.                                                     */
3
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. */
6
7 package app.pingpong;
8 import org.simgrid.msg.Msg;
9 import org.simgrid.msg.Host;
10 import org.simgrid.msg.Process;
11 import org.simgrid.msg.MsgException;
12 import org.simgrid.msg.NativeException;
13 import org.simgrid.msg.HostNotFoundException;
14
15 public class Sender extends Process {
16   private final double commSizeLat = 1;
17   final double commSizeBw = 100000000;
18
19   public Sender(String hostname, String name, String[] args) throws HostNotFoundException, NativeException {
20     super(hostname,name,args);
21   }
22
23   public void main(String[] args) throws MsgException {
24     Msg.info("hello!");
25
26     int hostCount = args.length;
27
28     Msg.info("host count: " + hostCount);
29     String mailboxes[] = new String[hostCount]; 
30     double time;
31     double computeDuration = 0;
32     PingPongTask task;
33
34     for(int pos = 0; pos < args.length ; pos++) {
35       try {
36         mailboxes[pos] = Host.getByName(args[pos]).getName();
37       } catch (HostNotFoundException e) {
38         Msg.info("Invalid deployment file: " + e.toString());
39         System.exit(1);
40       }
41     }
42
43     for (int pos = 0; pos < hostCount; pos++) { 
44       time = Msg.getClock(); 
45
46       Msg.info("sender time: " + time);
47
48       task = new PingPongTask("no name",computeDuration,commSizeLat);
49       task.setTime(time);
50
51       task.send(mailboxes[pos]);
52     }
53
54     Msg.info("goodbye!");
55   }
56 }