Logo AND Algorithmique Numérique Distribuée

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