Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Various cleanups in the java world (1/2)
[simgrid.git] / examples / java / tracing / 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 tracing;
8 import org.simgrid.msg.Msg;
9 import org.simgrid.msg.Host;
10 import org.simgrid.msg.Task;
11 import org.simgrid.msg.Process;
12 import org.simgrid.msg.MsgException;
13 import org.simgrid.msg.HostNotFoundException;
14 import org.simgrid.trace.Trace;
15
16 public class Sender extends Process {
17   private final double commSizeLat = 1;
18   private final double commSizeBw = 100000000;
19
20   public Sender(Host host, String name, String[] args) {
21     super(host,name,args);
22   }
23
24   public void main(String[] args) throws MsgException {
25     Msg.info("hello !"); 
26     Trace.hostPushState (getHost().getName(), "PM_STATE", "sendingPing");
27
28     int hostCount = args.length;
29     Msg.info("host count: " + hostCount);
30     String mailboxes[] = new String[hostCount]; 
31     double time;
32     double computeDuration = 0;
33     PingPongTask ping, pong;
34
35     for(int pos = 0; pos < args.length ; pos++) {
36       try {
37         mailboxes[pos] = Host.getByName(args[pos]).getName();
38       } catch (HostNotFoundException e) {
39         Msg.info("Invalid deployment file: " + e.toString());
40         System.exit(1);
41       }
42     }
43
44     for (int pos = 0; pos < hostCount; pos++) { 
45       time = Msg.getClock(); 
46       Msg.info("sender time: " + time);
47       ping = new PingPongTask("no name",computeDuration,commSizeLat);
48       ping.setTime(time);
49       ping.send(mailboxes[pos]);
50
51       Trace.hostPushState (getHost().getName(), "PM_STATE", "waitingPong");
52       pong = (PingPongTask)Task.receive(getHost().getName());
53       double timeGot = Msg.getClock();
54       double timeSent = ping.getTime();
55       double communicationTime=0;
56
57       Msg.info("Got at time "+ timeGot);
58       Msg.info("Was sent at time "+timeSent);
59       time=timeSent;
60
61       communicationTime=timeGot - time;
62       Msg.info("Communication time : " + communicationTime);
63
64       Msg.info(" --- bw "+ commSizeBw/communicationTime + " ----");
65
66       /* Pop the last state (going back to sending ping) */  
67       Trace.hostPopState (getHost().getName(), "PM_STATE");
68     }
69
70     /* Pop the sendingPong state */  
71     Trace.hostPopState (getHost().getName(), "PM_STATE");
72     Msg.info("goodbye!");
73   }
74 }