Logo AND Algorithmique Numérique Distribuée

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