Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
merge xbt/ex.hpp into simgrid/exception.hpp
[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
8 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example");
9
10 static void dummy()
11 {
12   XBT_INFO("I start");
13   try {
14     simgrid::s4u::this_actor::sleep_for(200);
15     XBT_INFO("I stop");
16   } catch (xbt_ex& e) {
17     if (e.category == host_error) {
18       XBT_DEBUG("The host has died ... as expected. This actor silently stops");
19     } else {
20       XBT_ERROR("An unexpected exception has been raised.");
21       throw;
22     }
23   }
24 }
25
26 static void autostart()
27 {
28   simgrid::s4u::Host* host = simgrid::s4u::Host::by_name("Fafard");
29   XBT_INFO("starting a dummy process on %s ", host->get_cname());
30
31   simgrid::s4u::ActorPtr dummy_actor = simgrid::s4u::Actor::create("Dummy", host, dummy);
32   dummy_actor->set_auto_restart(true);
33
34   simgrid::s4u::this_actor::sleep_for(50);
35
36   XBT_INFO("powering off %s", host->get_cname());
37   host->turn_off();
38
39   simgrid::s4u::this_actor::sleep_for(10);
40
41   XBT_INFO("powering on %s", host->get_cname());
42   host->turn_on();
43   simgrid::s4u::this_actor::sleep_for(200);
44 }
45
46 int main(int argc, char* argv[])
47 {
48   simgrid::s4u::Engine e(&argc, argv);
49   e.load_platform(argv[1]);
50
51   simgrid::s4u::Actor::create("Autostart", simgrid::s4u::Host::by_name("Tremblay"), autostart);
52
53   e.run();
54   XBT_INFO("Simulation time %g", e.get_clock());
55
56   return 0;
57 }