Logo AND Algorithmique Numérique Distribuée

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