wrench::S4U_Daemon

class S4U_Daemon : public std::enable_shared_from_this<S4U_Daemon>

A generic “running daemon” abstraction that serves as a basis for all simulated processes.

Subclassed by wrench::Service

Public Types

enum State

Daemon states.

Values:

enumerator CREATED

CREATED state: the daemon has been created but not started.

enumerator UP

UP state: the daemon has been started and is still running.

enumerator DOWN

DOWN state: the daemon has been shutdown and/or has terminated.

enumerator SUSPENDED

SUSPENDED state: the daemon has been suspended (and hopefully will be resumed0.

Public Functions

S4U_Daemon(const std::string &hostname, const std::string &process_name_prefix)

Constructor (daemon with a commport).

Parameters:
  • hostname – the name of the host on which the daemon will run

  • process_name_prefix – the prefix of the name of the simulated process/actor

virtual ~S4U_Daemon()

Destructor.

void acquireDaemonLock() const

Method to acquire the daemon’s lock.

Lock the daemon’s lock.

virtual void cleanup(bool has_returned_from_main, int return_value)

Release all mutexes that the running actor holds, if any.

Cleanup function called when the daemon terminates (for whatever reason). The default behavior is to throw an exception if the host is off. This method should be overridden in a daemons implements some fault-tolerant behavior, or is naturally tolerant.

Parameters:
  • has_returned_from_main – whether the daemon returned from main() by itself

  • return_value – the return value from main (if has_terminated_cleanly is true)

void createLifeSaver(std::shared_ptr<S4U_Daemon> reference)

Create a life-saver for the daemon.

Parameters:

reference –

void deleteLifeSaver()

Delete the daemon’s life-saver (use at your own risks, if you’re not the Simulation class).

S4U_CommPort *getCommPort()

Retrieve the daemon’s commport.

Returns:

A commport

std::string getName() const

Retrieve the process name.

Returns:

the name

int getReturnValue() const

Returns the value returned by main() (if the daemon has returned from main).

Returns:

The return value

Simulation *getSimulation() const

Get the service’s simulation.

Returns:

a simulation

S4U_Daemon::State getState() const

Get the daemon’s state.

Returns:

a state

bool hasReturnedFromMain() const

Returns true if the daemon has returned from main() (i.e., not brutally killed).

Returns:

The true or false

bool isDaemonized() const

Return the daemonized status of the daemon.

Returns:

true or false

bool isSetToAutoRestart() const

Return the auto-restart status of the daemon.

Returns:

true or false

std::pair<bool, int> join() const

Join (i.e., wait for) the daemon.

Returns:

a pair <A,B> where A is boolean (true if the daemon terminated cleanly (i.e., main() returned), or false otherwise) and B is the int returned from main() (if main returned).

bool killActor()

Kill the daemon/actor (does nothing if already dead).

Returns:

true if actor was killed, false if not (e.g., daemon was already dead)

virtual int main() = 0

The daemon’s main method, to be overridden.

Returns:

0 on success, non-0 on failure!

void releaseDaemonLock() const

Method to release the daemon’s lock.

Unlock the daemon’s lock.

void resumeActor() const

Resume the daemon/actor.

void setName(std::string name)

Set the service’s name.

Parameters:

name – the new name

void setSimulation(Simulation *simulation)

Set the service’s simulation.

Parameters:

simulation – a simulation

void setupOnExitFunction()

Sets up the on_exit function for the actor.

void startDaemon(bool daemonized, bool auto_restart)

Start the daemon.

Parameters:
  • daemonized – whether the S4U actor should be daemonized

  • auto_restart – whether the S4U actor should automatically restart after a host reboot

void suspendActor() const

Suspend the daemon/actor.

Public Members

std::string _hostname

The name of the host on which the daemon is running.

LifeSaver *life_saver = nullptr

The daemon’s life saver.

std::string process_name

The name of the daemon.

Public Static Functions

static S4U_CommPort *getRunningActorRecvCommPort()

Return the running actor’s recv commport.

Returns:

the commport

Public Static Attributes

static std::unordered_map<aid_t, std::set<simgrid::s4u::MutexPtr>> map_actor_to_held_mutexes

A map of actors to sets of held mutexes.

static std::unordered_map<aid_t, S4U_CommPort*> map_actor_to_recv_commport

A convenient map between actors and their default receive commports.