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::Alarm wrench::BandwidthMeterService wrench::ComputeService wrench::ComputeThread wrench::DataMovementManager wrench::EnergyMeterService wrench::FileRegistryService wrench::FileTransferThread wrench::HostStateChangeDetector wrench::HTCondorNegotiatorService wrench::JobManager wrench::NetworkProximityDaemon wrench::NetworkProximityService wrench::ServiceTerminationDetector wrench::StandardJobExecutor wrench::StorageService wrench::WMS wrench::WorkunitExecutor

Public Types

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

Public Member Functions

 S4U_Daemon (std::string hostname, std::string process_name_prefix, std::string mailbox_prefix)
 Constructor (daemon with a mailbox) More...
 
virtual ~S4U_Daemon ()
 
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...
 
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 resumeActor ()
 Resume the daemon/actor.
 
void setupOnExitFunction ()
 Sets up the on_exit functionf for the actor.
 
void startDaemon (bool daemonized, bool auto_restart)
 Start the daemon. More...
 
void suspendActor ()
 Suspend the daemon/actor.
 

Public Attributes

std::string hostname
 The name of the host on which the daemon is running.
 
std::string initial_mailbox_name
 The initial name of the daemon's mailbox.
 
LifeSaver * life_saver = nullptr
 The daemon's life saver.
 
std::string mailbox_name
 The current name of the daemon's mailbox.
 
std::string process_name
 The name of the daemon.
 
Simulationsimulation
 a pointer to the simulation object
 

Protected Member Functions

void acquireDaemonLock ()
 Lock the daemon's lock.
 
void killActor ()
 Kill the daemon/actor (does nothing if already dead) More...
 
void releaseDaemonLock ()
 Unlock the daemon's lock.
 
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)
 
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,
std::string  mailbox_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
mailbox_prefixthe prefix of the mailbox (to which a unique integer is appended)

◆ ~S4U_Daemon()

wrench::S4U_Daemon::~S4U_Daemon ( )
virtual

The code below was to avoid a memory leak on the actor! However, weirdly, it now causes problems due to SimGrid complaining that on_exit() functions shouldn't do blocking things.... So it's commented-out for now

Member Function Documentation

◆ 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::SimpleStorageService, wrench::FileTransferThread, 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

◆ 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()

void wrench::S4U_Daemon::killActor ( )
protected

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

Exceptions
std::shared_ptr<FatalFailure>

◆ main()

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

The daemon's main method, to be overridden.

Returns
0 on success, non-0 on failure!

Implemented in wrench::CloudComputeService, wrench::VirtualizedClusterComputeService, wrench::FileTransferThread, wrench::WorkloadTraceFileReplayerEventReceiver, and wrench::ComputeThread.

◆ 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: