WRENCH  1.10
Cyberinfrastructure Simulation Workbench
Overview Installation Getting Started WRENCH 101 WRENCH 102
Service.h
1 
11 #ifndef WRENCH_SERVICE_H
12 #define WRENCH_SERVICE_H
13 
14 
15 #include <string>
16 #include <map>
17 
18 #include <wrench/simgrid_S4U_util/S4U_Daemon.h>
19 
20 namespace wrench {
21 
26  class Service : public S4U_Daemon {
27 
28  public:
29 
30 
31 
32  /***********************/
34  /***********************/
35 
36  void start(std::shared_ptr<Service> this_service, bool daemonize, bool auto_restart);
37  virtual void stop();
38  void suspend();
39  void resume();
40 
41  std::string getHostname();
42 
43  bool isUp();
44 
45  std::string getPropertyValueAsString(std::string);
46  double getPropertyValueAsDouble(std::string);
47  unsigned long getPropertyValueAsUnsignedLong(std::string);
48  bool getPropertyValueAsBoolean(std::string);
49 
50  void assertServiceIsUp();
51 
52  double getNetworkTimeoutValue();
53  void setNetworkTimeoutValue(double value);
54 
55  /***********************/
57  /***********************/
58 
59  /***********************/
61  /***********************/
62 
63  double getMessagePayloadValue(std::string);
64 
65  void setStateToDown();
66 
68  static void clearTrackedServices();
69  static void cleanupTrackedServices();
70 
71  /***********************/
73  /***********************/
74 
75  protected:
76 
77  /***********************/
79  /***********************/
80 
85  static void assertServiceIsUp(std::shared_ptr<Service> s) { s->assertServiceIsUp(); };
86 
87  friend class Simulation;
88 
89  ~Service();
90 
91  Service(std::string hostname, std::string process_name_prefix, std::string mailbox_name_prefix);
92 
93  // Property stuff
94  void setProperty(std::string, std::string);
95 
96  void setProperties(std::map<std::string, std::string> default_property_values,
97  std::map<std::string, std::string> overriden_property_values);
98 
99  // MessagePayload stuff
100  void setMessagePayload(std::string, double);
101 
102  void setMessagePayloads(std::map<std::string, double> default_messagepayload_values,
103  std::map<std::string, double> overriden_messagepayload_values);
104 
105 
106  void serviceSanityCheck();
107 
109  std::map<std::string, std::string> property_list;
110 
112  std::map<std::string, double> messagepayload_list;
113 
115  std::string name;
116 
120  double network_timeout = 30.0;
121 
127  template <class T>
128  std::shared_ptr<T> getSharedPtr() {
129  if (Service::service_shared_ptr_map.find(this) == Service::service_shared_ptr_map.end()) {
130  throw std::runtime_error("Service::getSharedPtr(): master shared_ptr to service not found! This should happen only "
131  "if the service has not been started, in which case this method shouldn't have been called");
132  }
133  auto shared_ptr = std::dynamic_pointer_cast<T>(Service::service_shared_ptr_map[this]);
134  if (not shared_ptr) {
135  throw std::runtime_error("Service::getSharedPtr(): Invalid provided template");
136  }
137  return shared_ptr;
138  }
139 
146  template <class T>
147  static std::shared_ptr<T> getServiceByName(std::string name) {
148  for (auto const &s : Service::service_shared_ptr_map) {
149  if (s.first->getName() == name) {
150  return std::dynamic_pointer_cast<T>(s.second);
151  }
152  }
153  return nullptr;
154  }
155 
156 
157  private:
158 
159  static std::unordered_map<Service *, std::shared_ptr<Service>> service_shared_ptr_map;
160 
161  bool shutting_down = false;
162 
163  static unsigned long num_terminated_services;
164 
165 
166  /***********************/
168  /***********************/
169 
170  };
171 };
172 
173 
174 #endif //WRENCH_SERVICE_H
wrench::Service::setNetworkTimeoutValue
void setNetworkTimeoutValue(double value)
Sets the service's network timeout value.
Definition: Service.cpp:441
wrench::Service::start
void start(std::shared_ptr< Service > this_service, bool daemonize, bool auto_restart)
Start the service.
Definition: Service.cpp:248
wrench::Service::setStateToDown
void setStateToDown()
Set the state of the service to DOWN.
Definition: Service.cpp:378
wrench::Service::getPropertyValueAsBoolean
bool getPropertyValueAsBoolean(std::string)
Get a property of the Service as a boolean.
Definition: Service.cpp:220
wrench::Service::setProperty
void setProperty(std::string, std::string)
Set a property of the Service.
Definition: Service.cpp:101
wrench::Service::~Service
~Service()
Destructor.
Definition: Service.cpp:81
wrench::Service::increaseNumCompletedServicesCount
static void increaseNumCompletedServicesCount()
Increase the completed service count.
Definition: Service.cpp:36
wrench::Service::setProperties
void setProperties(std::map< std::string, std::string > default_property_values, std::map< std::string, std::string > overriden_property_values)
Set default and user-defined properties.
Definition: Service.cpp:387
wrench::Service::getPropertyValueAsDouble
double getPropertyValueAsDouble(std::string)
Get a property of the Service as a double.
Definition: Service.cpp:150
wrench::Service::name
std::string name
The service's name.
Definition: Service.h:115
wrench::Service::serviceSanityCheck
void serviceSanityCheck()
Check whether the service is properly configured and running.
Definition: Service.cpp:424
wrench::Service::assertServiceIsUp
void assertServiceIsUp()
Throws an exception if the service is not up.
Definition: Service.cpp:449
wrench::Service::clearTrackedServices
static void clearTrackedServices()
Forget all tracked services.
Definition: Service.cpp:43
wrench::Service::getMessagePayloadValue
double getMessagePayloadValue(std::string)
Get a message payload of the Service as a double.
Definition: Service.cpp:203
wrench::Service::getPropertyValueAsUnsignedLong
unsigned long getPropertyValueAsUnsignedLong(std::string)
Get a property of the Service as an unsigned long.
Definition: Service.cpp:176
wrench::Service::isUp
bool isUp()
Returns true if the service is UP, false otherwise.
Definition: Service.cpp:371
wrench
Definition: Alarm.cpp:20
wrench::Service::getSharedPtr
std::shared_ptr< T > getSharedPtr()
Method to retrieve the shared_ptr to a service.
Definition: Service.h:128
wrench::Service::suspend
void suspend()
Suspend the service.
Definition: Service.cpp:333
wrench::Service::Service
Service(std::string hostname, std::string process_name_prefix, std::string mailbox_name_prefix)
Constructor.
Definition: Service.cpp:91
wrench::Service::network_timeout
double network_timeout
The time (in seconds) after which a service that doesn't send back a reply (control) message causes a...
Definition: Service.h:120
wrench::Service::setMessagePayloads
void setMessagePayloads(std::map< std::string, double > default_messagepayload_values, std::map< std::string, double > overriden_messagepayload_values)
Set default and user-defined message payloads.
Definition: Service.cpp:405
wrench::Service::stop
virtual void stop()
Synchronously stop the service (does nothing if the service is already stopped)
Definition: Service.cpp:285
wrench::Service::getPropertyValueAsString
std::string getPropertyValueAsString(std::string)
Get a property of the Service as a string.
Definition: Service.cpp:134
wrench::Service::getNetworkTimeoutValue
double getNetworkTimeoutValue()
Returns the service's network timeout value.
Definition: Service.cpp:432
wrench::Service::messagepayload_list
std::map< std::string, double > messagepayload_list
The service's messagepayload list.
Definition: Service.h:112
wrench::S4U_Daemon
A generic "running daemon" abstraction that serves as a basis for all simulated processes.
Definition: S4U_Daemon.h:32
wrench::Service::cleanupTrackedServices
static void cleanupTrackedServices()
Go through the tracked services and remove all entries with a refcount of 1!
Definition: Service.cpp:50
wrench::S4U_Daemon::hostname
std::string hostname
The name of the host on which the daemon is running.
Definition: S4U_Daemon.h:51
wrench::Simulation
A class that provides basic simulation methods. Once the simulation object has been explicitly or imp...
Definition: Simulation.h:46
wrench::Service::getServiceByName
static std::shared_ptr< T > getServiceByName(std::string name)
Method to retrieve the shared_ptr to a service based on the service's name (not efficient)
Definition: Service.h:147
wrench::Service::assertServiceIsUp
static void assertServiceIsUp(std::shared_ptr< Service > s)
Assert for the service being up.
Definition: Service.h:85
wrench::Service
A service that can be added to the simulation and that can be used by a WMS when executing a workflow...
Definition: Service.h:26
wrench::Service::setMessagePayload
void setMessagePayload(std::string, double)
Set a message payload of the Service.
Definition: Service.cpp:116
wrench::Service::getHostname
std::string getHostname()
Get the name of the host on which the service is / will be running.
Definition: Service.cpp:363
wrench::Service::property_list
std::map< std::string, std::string > property_list
The service's property list.
Definition: Service.h:109
wrench::Service::resume
void resume()
Resume the service.
Definition: Service.cpp:349