Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Move Java examples to examples/java/.
[simgrid.git] / examples / java / tracing / Receiver.java
1 /*
2  * $Id$
3  *
4  * Copyright 2006,2007 Martin Quinson, Malek Cherier         
5  * Copyright 2012 The SimGrid Team. All rights reserved. 
6  * All rights reserved. 
7  *
8  * This program is free software; you can redistribute it and/or modify it
9  * under the terms of the license (GNU LGPL) which comes with this package. 
10  */
11 package tracing;
12 import org.simgrid.msg.Host;
13 import org.simgrid.msg.Msg;
14 import org.simgrid.msg.MsgException;
15 import org.simgrid.msg.Task;
16 import org.simgrid.msg.Process;
17 import org.simgrid.trace.Trace;
18
19 public class Receiver extends Process {
20   
21         private  final double commSizeLat = 1;
22   private final double commSizeBw = 100000000;
23                  
24         public Receiver(Host host, String name, String[]args) {
25                 super(host,name,args);
26    } 
27    
28    public void main(String[] args) throws MsgException {
29         
30       Msg.info("hello!");
31       Trace.hostPushState (host.getName(), "PM_STATE", "waitingPing");
32                         double communicationTime=0;
33
34       double time = Msg.getClock();
35     
36                         /* Wait for the ping */ 
37       Msg.info("try to get a task");
38         
39       PingPongTask ping = (PingPongTask)Task.receive(getHost().getName());
40       double timeGot = Msg.getClock();
41       double timeSent = ping.getTime();
42             
43       Msg.info("Got at time "+ timeGot);
44       Msg.info("Was sent at time "+timeSent);
45       time=timeSent;
46             
47       communicationTime=timeGot - time;
48       Msg.info("Communication time : " + communicationTime);
49             
50       Msg.info(" --- bw "+ commSizeBw/communicationTime + " ----");
51       
52                         /* Send the pong */
53                 Trace.hostPushState (host.getName(), "PM_STATE", "sendingPong");
54                         double computeDuration = 0;
55                         PingPongTask pong = new PingPongTask("no name",computeDuration,commSizeLat);
56                         pong.setTime(time);
57                         pong.send(ping.getSource().getName());
58
59                 /* Pop the two states */
60       Trace.hostPopState (host.getName(), "PM_STATE");
61       Trace.hostPopState (host.getName(), "PM_STATE");
62   
63                 Msg.info("goodbye!");
64     }
65 }