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  /***********************/
32  /***********************/
33 
35  enum State {
37  UP,
40  };
41 
42  void start(std::shared_ptr<Service> this_service, bool daemonize, bool auto_restart);
43 
44  virtual void stop();
45 
46  std::string getHostname();
47 
48  bool isUp();
49 
50  std::string getPropertyValueAsString(std::string);
51 
52  double getPropertyValueAsDouble(std::string);
53 
54  bool getPropertyValueAsBoolean(std::string);
55 
56  double getNetworkTimeoutValue();
57 
58  void setNetworkTimeoutValue(double value);
59 
60  /***********************/
62  /***********************/
63 
64  /***********************/
66  /***********************/
67 
68  std::string getMessagePayloadValueAsString(std::string);
69 
70  double getMessagePayloadValueAsDouble(std::string);
71 
72  void setStateToDown();
73 
74  /***********************/
76  /***********************/
77 
78  protected:
79 
80  /***********************/
82  /***********************/
83 
84  friend class Simulation;
85 
86  Service(std::string hostname, std::string process_name_prefix, std::string mailbox_name_prefix);
87 
88  // Property stuff
89  void setProperty(std::string, std::string);
90 
91  void setProperties(std::map<std::string, std::string> default_property_values,
92  std::map<std::string, std::string> overriden_property_values);
93 
94  // MessagePayload stuff
95  void setMessagePayload(std::string, std::string);
96 
97  void setMessagePayloads(std::map<std::string, std::string> default_messagepayload_values,
98  std::map<std::string, std::string> overriden_messagepayload_values);
99 
100 
101  void serviceSanityCheck();
102 
104  std::map<std::string, std::string> property_list;
105 
107  std::map<std::string, std::string> messagepayload_list;
108 
109 
112 
114  std::string name;
115 
119  double network_timeout = 30.0;
120 
121  private:
122  bool shutting_down = false;
123 
124  /***********************/
126  /***********************/
127 
128  };
129 };
130 
131 
132 #endif //WRENCH_SERVICE_H
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:269
void setProperty(std::string, std::string)
Set a property of the Service.
Definition: Service.cpp:41
void setMessagePayload(std::string, std::string)
Set a message payload of the Service.
Definition: Service.cpp:55
std::map< std::string, std::string > property_list
The service&#39;s property list.
Definition: Service.h:104
double getMessagePayloadValueAsDouble(std::string)
Get a message payload of the Service as a double.
Definition: Service.cpp:132
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
DOWN state: the service has been shutdown and/or has terminated.
Definition: Service.h:39
std::string getMessagePayloadValueAsString(std::string)
Get a message payload of the Service as a string.
Definition: Service.cpp:93
UP state: the service has been started and is still running.
Definition: Service.h:37
std::string getHostname()
Get the name of the host on which the service is / will be running.
Definition: Service.cpp:245
void setMessagePayloads(std::map< std::string, std::string > default_messagepayload_values, std::map< std::string, std::string > overriden_messagepayload_values)
Set default and user-defined message payloads.
Definition: Service.cpp:287
void serviceSanityCheck()
Check whether the service is properly configured and running.
Definition: Service.cpp:305
Service(std::string hostname, std::string process_name_prefix, std::string mailbox_name_prefix)
Constructor.
Definition: Service.cpp:31
std::string getPropertyValueAsString(std::string)
Get a property of the Service as a string.
Definition: Service.cpp:78
std::string hostname
The name of the host on which the daemon is running.
Definition: S4U_Daemon.h:47
A class that provides basic simulation methods.
Definition: Simulation.h:34
virtual void stop()
Synchronously stop the service (does nothing if the service is already stopped)
Definition: Service.cpp:200
std::string name
The service&#39;s name.
Definition: Service.h:114
void setNetworkTimeoutValue(double value)
Sets the service&#39;s network timeout value.
Definition: Service.cpp:324
void setStateToDown()
Set the state of the service to DOWN.
Definition: Service.cpp:260
double getPropertyValueAsDouble(std::string)
Get a property of the Service as a double.
Definition: Service.cpp:109
double network_timeout
The time (in seconds) after which a service that doesn&#39;t send back a reply (control) message causes a...
Definition: Service.h:119
State
Service states.
Definition: Service.h:35
bool isUp()
Returns true if the service is UP, false otherwise.
Definition: Service.cpp:253
bool getPropertyValueAsBoolean(std::string)
Get a property of the Service as a boolean.
Definition: Service.cpp:157
State state
The service&#39;s state.
Definition: Service.h:111
std::map< std::string, std::string > messagepayload_list
The service&#39;s messagepayload list.
Definition: Service.h:107
double getNetworkTimeoutValue()
Returns the service&#39;s network timeout value.
Definition: Service.cpp:315
A generic "running daemon" abstraction that serves as a basis for all simulated processes.
Definition: S4U_Daemon.h:32
void start(std::shared_ptr< Service > this_service, bool daemonize, bool auto_restart)
Start the service.
Definition: Service.cpp:184
Definition: TerminalOutput.cpp:15