Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branches 'auto_restart' and 'auto_restart' of framagit.org:simgrid/simgrid
[simgrid.git] / teshsuite / s4u / actor-autorestart / actor-autorestart.cpp
1 /* Copyright (c) 2017-2018. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #include "simgrid/s4u.hpp"
7 #include <xbt/ex.hpp>
8
9 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example");
10
11 static void dummy()
12 {
13   XBT_INFO("I start");
14   try {
15     simgrid::s4u::this_actor::sleep_for(200);
16     XBT_INFO("I stop");
17   } catch (xbt_ex& e) {
18     if (e.category == host_error) {
19       XBT_DEBUG("The host has died ... as expected. This actor silently stops");
20     } else {
21       XBT_ERROR("An unexpected exception has been raised.");
22       throw;
23     }
24   }
25 }
26
27 static void autostart()
28 {
29   simgrid::s4u::Host* host = simgrid::s4u::Host::by_name("Fafard");
30   XBT_INFO("starting a dummy process on %s ", host->get_cname());
31
32   simgrid::s4u::ActorPtr dummy_actor = simgrid::s4u::Actor::create("Dummy", host, dummy);
33   dummy_actor->set_auto_restart(true);
34
35   simgrid::s4u::this_actor::sleep_for(50);
36
37   XBT_INFO("powering off %s", host->get_cname());
38   host->turn_off();
39
40   simgrid::s4u::this_actor::sleep_for(10);
41
42   XBT_INFO("powering on %s", host->get_cname());
43   host->turn_on();
44   simgrid::s4u::this_actor::sleep_for(200);
45 }
46
47 int main(int argc, char* argv[])
48 {
49   simgrid::s4u::Engine e(&argc, argv);
50   e.load_platform(argv[1]);
51
52   simgrid::s4u::Actor::create("Autostart", simgrid::s4u::Host::by_name("Tremblay"), autostart);
53
54   e.run();
55   XBT_INFO("Simulation time %g", e.get_clock());
56
57   return 0;
58 }