WRENCH  1.11
Cyberinfrastructure Simulation Workbench
Overview Installation Getting Started WRENCH 101 WRENCH 102
Classes | Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions | Protected Attributes | List of all members
wrench::S4U_Daemon Class Referenceabstract

A generic "running daemon" abstraction that serves as a basis for all simulated processes. More...

#include <S4U_Daemon.h>

Inheritance diagram for wrench::S4U_Daemon:
wrench::Service wrench::ActionExecutionService wrench::Alarm wrench::BandwidthMeterService wrench::ComputeService wrench::ComputeThread wrench::DataMovementManager wrench::EnergyMeterService wrench::ExecutionController wrench::FileRegistryService wrench::FileTransferThread wrench::HostStateChangeDetector wrench::HTCondorNegotiatorService wrench::JobManager wrench::MemoryManager wrench::NetworkProximityDaemon wrench::NetworkProximityService wrench::ServiceTerminationDetector wrench::StorageService

Public Types

enum  State { UP, DOWN, SUSPENDED }
 Daemon states. More...
 

Public Member Functions

 S4U_Daemon (std::string hostname, std::string process_name_prefix)
 Constructor (daemon with a mailbox) More...
 
void acquireDaemonLock ()
 Method to acquire the daemon's lock. More...
 
virtual void cleanup (bool has_returned_from_main, int return_value)
 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 overriden in a daemons implements some fault-tolerant behavior, or is naturally tolerant. More...
 
void createLifeSaver (std::shared_ptr< S4U_Daemon > reference)
 Create a life saver for the daemon. More...
 
std::string getName ()
 Retrieve the process name. More...
 
int getReturnValue ()
 Returns the value returned by main() (if the daemon has returned from main) More...
 
SimulationgetSimulation ()
 Get the service's simulation. More...
 
S4U_Daemon::State getState ()
 Get the daemon's state. More...
 
bool hasReturnedFromMain ()
 Returns true if the daemon has returned from main() (i.e., not brutally killed) More...
 
bool isDaemonized ()
 Return the daemonized status of the daemon. More...
 
bool isSetToAutoRestart ()
 Return the auto-restart status of the daemon. More...
 
std::pair< bool, int > join ()
 Join (i.e., wait for) the daemon. More...
 
virtual int main ()=0
 The daemon's main method, to be overridden. More...
 
void releaseDaemonLock ()
 Method to release the daemon's lock. More...
 
void resumeActor ()
 Resume the daemon/actor.
 
void setSimulation (Simulation *simulation)
 Set the service's simulation. More...
 
void setupOnExitFunction ()
 Sets up the on_exit function for the actor.
 
void startDaemon (bool _daemonized, bool _auto_restart)
 Start the daemon. More...
 
void suspendActor ()
 Suspend the daemon/actor.
 

Static Public Member Functions

static simgrid::s4u::Mailbox * getRunningActorRecvMailbox ()
 Return the running actor's recv mailbox. More...
 

Public Attributes

std::string hostname
 The name of the host on which the daemon is running.
 
LifeSaver * life_saver = nullptr
 The daemon's life saver.
 
simgrid::s4u::Mailbox * mailbox
 The daemon's mailbox.
 
std::string process_name
 The name of the daemon.
 
simgrid::s4u::Mailbox * recv_mailbox
 The daemon's receive mailbox (to send to another daemon so that that daemon can reply)
 

Static Public Attributes

static std::unordered_map< aid_t, simgrid::s4u::Mailbox * > map_actor_to_recv_mailbox
 

Protected Member Functions

bool killActor ()
 Kill the daemon/actor (does nothing if already dead) More...
 
void runMainMethod ()
 Method that run's the user-defined main method (that's called by the S4U actor class)
 

Protected Attributes

unsigned int num_starts = 0
 The number of time that this daemon has started (i.e., 1 + number of restarts)
 
Simulationsimulation
 a pointer to the simulation object
 
State state
 The service's state.
 

Detailed Description

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

Member Enumeration Documentation

◆ State

Daemon states.

Enumerator
UP 

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

DOWN 

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

SUSPENDED 

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

Constructor & Destructor Documentation

◆ S4U_Daemon()

wrench::S4U_Daemon::S4U_Daemon ( std::string  hostname,
std::string  process_name_prefix 
)

Constructor (daemon with a mailbox)

Parameters
hostnamethe name of the host on which the daemon will run
process_name_prefixthe prefix of the name of the simulated process/actor

Member Function Documentation

◆ acquireDaemonLock()

void wrench::S4U_Daemon::acquireDaemonLock ( )

Method to acquire the daemon's lock.

Lock the daemon's lock.

◆ cleanup()

void wrench::S4U_Daemon::cleanup ( bool  has_returned_from_main,
int  return_value 
)
virtual

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 overriden in a daemons implements some fault-tolerant behavior, or is naturally tolerant.

Parameters
has_returned_from_mainwhether the daemon returned from main() by itself
return_valuethe return value from main (if has_terminated_cleanly is true)
Exceptions
std::runtime_error

Reimplemented in wrench::BareMetalComputeService, wrench::SimpleStorageService, wrench::FileTransferThread, wrench::ActionExecutor, and wrench::ComputeThread.

◆ createLifeSaver()

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

Create a life saver for the daemon.

Parameters
reference

◆ getName()

std::string wrench::S4U_Daemon::getName ( )

Retrieve the process name.

Returns
the name

◆ getReturnValue()

int wrench::S4U_Daemon::getReturnValue ( )

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

Returns
The return value

◆ getRunningActorRecvMailbox()

simgrid::s4u::Mailbox * wrench::S4U_Daemon::getRunningActorRecvMailbox ( )
static

Return the running actor's recv mailbox.

Returns
the mailbox

◆ getSimulation()

Simulation * wrench::S4U_Daemon::getSimulation ( )

Get the service's simulation.

Returns
a simulation

◆ getState()

S4U_Daemon::State wrench::S4U_Daemon::getState ( )

Get the daemon's state.

Returns
a state

◆ hasReturnedFromMain()

bool wrench::S4U_Daemon::hasReturnedFromMain ( )

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

Returns
The true or false

◆ isDaemonized()

bool wrench::S4U_Daemon::isDaemonized ( )

Return the daemonized status of the daemon.

Returns
true or false

◆ isSetToAutoRestart()

bool wrench::S4U_Daemon::isSetToAutoRestart ( )

Return the auto-restart status of the daemon.

Returns
true or false

◆ join()

std::pair< bool, int > wrench::S4U_Daemon::join ( )

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).

◆ killActor()

bool wrench::S4U_Daemon::killActor ( )
protected

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

Returns
true if actor was killed, false if not (e.g., daemon was already dead)
Exceptions
std::shared_ptr<FatalFailure>

◆ main()

virtual int wrench::S4U_Daemon::main ( )
pure virtual

◆ releaseDaemonLock()

void wrench::S4U_Daemon::releaseDaemonLock ( )

Method to release the daemon's lock.

Unlock the daemon's lock.

◆ setSimulation()

void wrench::S4U_Daemon::setSimulation ( Simulation simulation)

Set the service's simulation.

Parameters
simulationa simulation

◆ startDaemon()

void wrench::S4U_Daemon::startDaemon ( bool  daemonized,
bool  auto_restart 
)

Start the daemon.

Parameters
daemonizedwhether the S4U actor should be daemonized
auto_restartwhether the S4U actor should automatically restart after a host reboot
Exceptions
std::runtime_error
std::shared_ptr<HostError>

The documentation for this class was generated from the following files: