WRENCH  1.11
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 #include <memory>
18 
19 #include "wrench/simgrid_S4U_util/S4U_Daemon.h"
20 #include "wrench/services/ServiceProperty.h"
21 #include "wrench/services/ServiceMessagePayload.h"
22 namespace wrench {
23  typedef std::map<WRENCH_PROPERTY_TYPE,std::string> WRENCH_PROPERTY_COLLECTION_TYPE;
24  typedef std::unordered_map<WRENCH_MESSAGEPAYLOAD_TYPE ,double> WRENCH_MESSAGE_PAYLOADCOLLECTION_TYPE;
25  class FailureCause;
26 
31 class Service : public S4U_Daemon, public std::enable_shared_from_this<Service> {
32 
33  public:
34 
35  /***********************/
37  /***********************/
38 
39  void start(std::shared_ptr<Service> this_service, bool daemonize, bool auto_restart);
40  virtual void stop();
41  void suspend();
42  void resume();
43 
44  std::string getHostname();
45  std::string getPhysicalHostname();
46 
47  bool isUp();
48 
49  std::string getPropertyValueAsString(WRENCH_PROPERTY_TYPE);
50  double getPropertyValueAsDouble(WRENCH_PROPERTY_TYPE);
51  unsigned long getPropertyValueAsUnsignedLong(WRENCH_PROPERTY_TYPE);
52  bool getPropertyValueAsBoolean(WRENCH_PROPERTY_TYPE);
53 
54  void assertServiceIsUp();
55 
56  double getNetworkTimeoutValue();
57  void setNetworkTimeoutValue(double value);
58 
59  /***********************/
61  /***********************/
62 
63  /***********************/
65  /***********************/
66 
67  double getMessagePayloadValue(WRENCH_MESSAGEPAYLOAD_TYPE);
68  const WRENCH_MESSAGE_PAYLOADCOLLECTION_TYPE& getMessagePayloadList() const;
69 
70  void setStateToDown();
71 
72  /***********************/
74  /***********************/
75 
76  protected:
77 
78  /***********************/
80  /***********************/
81 
86  static void assertServiceIsUp(std::shared_ptr<Service> s) { s->assertServiceIsUp(); };
87 
88  friend class Simulation;
89 
90  ~Service() override;
91 
92  Service(std::string hostname, std::string process_name_prefix);
93 
94  // Property stuff
95  void setProperty(WRENCH_PROPERTY_TYPE, const std::string&);
96 
97  void setProperties(WRENCH_PROPERTY_COLLECTION_TYPE default_property_values,
98  WRENCH_PROPERTY_COLLECTION_TYPE overriden_property_values);
99 
100  // MessagePayload stuff
101  void setMessagePayload(WRENCH_MESSAGEPAYLOAD_TYPE, double);
102 
103  void setMessagePayloads(WRENCH_MESSAGE_PAYLOADCOLLECTION_TYPE default_messagepayload_values,
104  WRENCH_MESSAGE_PAYLOADCOLLECTION_TYPE overriden_messagepayload_values);
105 
106 
107  void serviceSanityCheck();
108 
110  WRENCH_PROPERTY_COLLECTION_TYPE property_list;
111 
113  WRENCH_MESSAGE_PAYLOADCOLLECTION_TYPE messagepayload_list;
114 
116  std::string name;
117 
121  double network_timeout = 30.0;
122 
128  template <class T>
129  std::shared_ptr<T> getSharedPtr() {
130  return std::dynamic_pointer_cast<T>(this->shared_from_this());
131  }
132 
133 
135  bool shutting_down = false;
136 
137  private:
138 
139  /***********************/
141  /***********************/
142 
143  };
144 };
145 
146 
147 #endif //WRENCH_SERVICE_H
wrench::Service::setNetworkTimeoutValue
void setNetworkTimeoutValue(double value)
Sets the service's network timeout value.
Definition: Service.cpp:414
wrench::Service::getPropertyValueAsString
std::string getPropertyValueAsString(WRENCH_PROPERTY_TYPE)
Get a property of the Service as a string.
Definition: Service.cpp:86
wrench::Service::start
void start(std::shared_ptr< Service > this_service, bool daemonize, bool auto_restart)
Start the service.
Definition: Service.cpp:207
wrench::Service::getPropertyValueAsBoolean
bool getPropertyValueAsBoolean(WRENCH_PROPERTY_TYPE)
Get a property of the Service as a boolean.
Definition: Service.cpp:179
wrench::Service::getPropertyValueAsDouble
double getPropertyValueAsDouble(WRENCH_PROPERTY_TYPE)
Get a property of the Service as a double.
Definition: Service.cpp:102
wrench::Service::assertServiceIsUp
void assertServiceIsUp()
Throws an exception if the service is not up.
Definition: Service.cpp:422
wrench::Service::isUp
bool isUp()
Returns true if the service is UP, false otherwise.
Definition: Service.cpp:344
wrench
Definition: Action.cpp:28
wrench::Service::suspend
void suspend()
Suspend the service.
Definition: Service.cpp:294
wrench::Service::stop
virtual void stop()
Synchronously stop the service (does nothing if the service is already stopped)
Definition: Service.cpp:244
wrench::Service::getNetworkTimeoutValue
double getNetworkTimeoutValue()
Returns the service's network timeout value.
Definition: Service.cpp:405
wrench::Service::getPhysicalHostname
std::string getPhysicalHostname()
Get the physical name of the host on which the service is / will be running.
Definition: Service.cpp:332
wrench::Simulation
A class that provides basic simulation methods. Once the simulation object has been explicitly or imp...
Definition: Simulation.h:48
wrench::Service::getPropertyValueAsUnsignedLong
unsigned long getPropertyValueAsUnsignedLong(WRENCH_PROPERTY_TYPE)
Get a property of the Service as an unsigned long.
Definition: Service.cpp:128
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:31
wrench::Service::getHostname
std::string getHostname()
Get the name of the host on which the service is / will be running.
Definition: Service.cpp:324
wrench::Service::resume
void resume()
Resume the service.
Definition: Service.cpp:310