Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
2ae9c262c1af2b2818cd39939a4cef9ef3863370
[simgrid.git] / examples / java / async / waitall / Receiver.java
1 /* Copyright (c) 2006-2018. 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 async.waitall;
8 import org.simgrid.msg.Msg;
9 import org.simgrid.msg.Comm;
10 import org.simgrid.msg.Host;
11 import org.simgrid.msg.Task;
12 import org.simgrid.msg.Process;
13 import org.simgrid.msg.HostFailureException;
14 import org.simgrid.msg.TimeoutException;
15 import org.simgrid.msg.TransferFailureException;
16
17 public class Receiver extends Process {
18   public Receiver (Host host, String name) {
19     super(host,name);
20   }
21
22   @Override
23   public void main(String[] args) throws TransferFailureException, HostFailureException, TimeoutException {
24     Comm comm = Task.irecv(getHost().getName());
25     Msg.info("I started receiving on '"+ getHost().getName() +". Wait 0.1 second, and block on the communication.");
26     waitFor(0.1);
27     try {
28         comm.waitCompletion();
29     } catch (TimeoutException e) {
30         Msg.info("Timeout while waiting for my task");
31         throw e; // Stop this process
32     }
33     Msg.info("I got my task, good bye.");
34   }
35 }