Logo AND Algorithmique Numérique Distribuée

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