/* 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();
  }
}
