Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
kill tracing-gtnets examples
[simgrid.git] / examples / java / tracing / Receiver.java
1 /* Copyright (c) 2006-2007, 2012-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.Host;
9 import org.simgrid.msg.Msg;
10 import org.simgrid.msg.MsgException;
11 import org.simgrid.msg.Task;
12 import org.simgrid.msg.Process;
13 import org.simgrid.trace.Trace;
14
15 public class Receiver extends Process {
16   private  final double commSizeLat = 1;
17   private final double commSizeBw = 100000000;
18
19   public Receiver(Host host, String name, String[]args) {
20     super(host,name,args);
21   }
22
23   public void main(String[] args) throws MsgException {
24     Msg.info("hello!");
25     Trace.hostPushState (getHost().getName(), "PM_STATE", "waitingPing");
26     double communicationTime=0;
27
28     double time = Msg.getClock();
29
30     /* Wait for the ping */ 
31     Msg.info("try to get a task");
32
33     PingPongTask ping = (PingPongTask)Task.receive(getHost().getName());
34     double timeGot = Msg.getClock();
35     double timeSent = ping.getTime();
36
37     Msg.info("Got at time "+ timeGot);
38     Msg.info("Was sent at time "+timeSent);
39     time=timeSent;
40
41     communicationTime=timeGot - time;
42     Msg.info("Communication time : " + communicationTime);
43
44     Msg.info(" --- bw "+ commSizeBw/communicationTime + " ----");
45
46     /* Send the pong */
47     Trace.hostPushState (getHost().getName(), "PM_STATE", "sendingPong");
48     double computeDuration = 0;
49     PingPongTask pong = new PingPongTask("no name",computeDuration,commSizeLat);
50     pong.setTime(time);
51     pong.send(ping.getSource().getName());
52
53     /* Pop the two states */
54     Trace.hostPopState (getHost().getName(), "PM_STATE");
55     Trace.hostPopState (getHost().getName(), "PM_STATE");
56
57     Msg.info("goodbye!");
58   }
59 }