Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
pingPong -> app/pingpong
[simgrid.git] / examples / java / app / pingpong / Receiver.java
1 /* Copyright (c) 2006-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 app.pingpong;
8 import org.simgrid.msg.Msg;
9 import org.simgrid.msg.Host;
10 import org.simgrid.msg.Task;
11 import org.simgrid.msg.Process;
12 import org.simgrid.msg.MsgException;
13 import org.simgrid.msg.NativeException;
14 import org.simgrid.msg.HostNotFoundException;
15
16 public class Receiver extends Process {
17   final double commSizeLat = 1;
18   final double commSizeBw = 100000000;
19   public Receiver(String hostname, String name, String[]args) throws HostNotFoundException, NativeException{
20     super(hostname,name,args);
21   }
22
23   public void main(String[] args) throws MsgException {
24     Msg.info("hello!");
25     double communicationTime=0;
26
27     double time = Msg.getClock();
28
29     Msg.info("try to get a task");
30
31     PingPongTask task = (PingPongTask)Task.receive(getHost().getName());
32     double timeGot = Msg.getClock();
33     double timeSent = task.getTime();
34
35     Msg.info("Got at time "+ timeGot);
36     Msg.info("Was sent at time "+timeSent);
37     time=timeSent;
38
39     communicationTime=timeGot - time;
40     Msg.info("Communication time : " + communicationTime);
41     Msg.info(" --- bw "+ commSizeBw/communicationTime + " ----");
42     Msg.info("goodbye!");
43   }
44 }