Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
5f00d6f39812b68110cd84471bf77fe343faa69b
[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 static final double COMM_SIZE_LAT = 1;
17
18   public Sender(String hostname, String name, String[] args) throws HostNotFoundException, NativeException {
19     super(hostname,name,args);
20   }
21
22   public void main(String[] args) throws MsgException {
23     Msg.info("hello!");
24
25     int hostCount = args.length;
26
27     Msg.info("host count: " + hostCount);
28     String[] mailboxes = new String[hostCount]; 
29     double time;
30     double computeDuration = 0;
31     PingPongTask task;
32
33     for(int pos = 0; pos < args.length ; pos++) {
34       try {
35         mailboxes[pos] = Host.getByName(args[pos]).getName();
36       } catch (HostNotFoundException e) {
37         e.printStackTrace();
38         Msg.info("Invalid deployment file: " + e.toString());
39       }
40     }
41
42     for (int pos = 0; pos < hostCount; pos++) { 
43       time = Msg.getClock(); 
44
45       Msg.info("sender time: " + time);
46
47       task = new PingPongTask("no name",computeDuration,COMM_SIZE_LAT);
48       task.setTime(time);
49
50       task.send(mailboxes[pos]);
51     }
52
53     Msg.info("goodbye!");
54   }
55 }