Logo AND Algorithmique Numérique Distribuée

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