File: activityset_awaitall.java

package info (click to toggle)
simgrid 4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 38,980 kB
  • sloc: cpp: 123,583; ansic: 66,779; python: 8,358; java: 6,406; fortran: 6,079; f90: 5,123; xml: 4,587; sh: 2,337; perl: 1,436; makefile: 105; lisp: 49; javascript: 7; sed: 6
file content (61 lines) | stat: -rw-r--r-- 1,753 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/* Copyright (c) 2010-2025. The SimGrid Team. All rights reserved.          */

/* This program is free software; you can redistribute it and/or modify it
 * under the terms of the license (GNU LGPL) which comes with this package. */

import java.util.List;
import org.simgrid.s4u.*;

class bob extends Actor {
  public void run() throws SimgridException
  {
    var e               = get_engine();
    Mailbox mbox        = e.mailbox_by_name("mbox");
    MessageQueue mqueue = e.message_queue_by_name("mqueue");
    Disk disk           = get_host().get_disks()[0];

    Engine.info("Create my asynchronous activities");
    ActivitySet pending_activities = new ActivitySet();
    pending_activities.push(this.exec_async(5e9));
    pending_activities.push(mbox.get_async());
    pending_activities.push(mqueue.get_async());
    pending_activities.push(disk.read_async(3e8));

    Engine.info("Wait for asynchronous activities to complete, all in one shot.");
    pending_activities.await_all();

    Engine.info("All activities are completed.");
  }
}

class alice extends Actor {
  public void run()
  {
    String payload = "Message";
    Engine.info("Send '%s'", payload);
    get_engine().mailbox_by_name("mbox").put(payload, 6e8);
  }
}

class carl extends Actor {
  public void run()
  {
    String payload = "Control Message";
    get_engine().message_queue_by_name("mqueue").put(payload);
  }
}

public class activityset_awaitall {
  public static void main(String[] args)
  {
    Engine e = new Engine(args);

    e.load_platform(args[0]);

    e.add_actor("bob", e.host_by_name("bob"), new bob());
    e.add_actor("alice", e.host_by_name("alice"), new alice());
    e.add_actor("carl", e.host_by_name("carl"), new carl());

    e.run();
  }
}