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::property_list
WRENCH_PROPERTY_COLLECTION_TYPE property_list
The service's property list.
Definition: Service.h:110
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::setStateToDown
void setStateToDown()
Set the state of the service to DOWN.
Definition: Service.cpp:351
wrench::Service::getPropertyValueAsBoolean
bool getPropertyValueAsBoolean(WRENCH_PROPERTY_TYPE)
Get a property of the Service as a boolean.
Definition: Service.cpp:179
wrench::Service::setProperties
void setProperties(WRENCH_PROPERTY_COLLECTION_TYPE default_property_values, WRENCH_PROPERTY_COLLECTION_TYPE overriden_property_values)
Set default and user-defined properties.
Definition: Service.cpp:360
wrench::Service::shutting_down
bool shutting_down
A boolean that indicates if the service is in the middle of shutting down.
Definition: Service.h:135
wrench::Service::getMessagePayloadList
const WRENCH_MESSAGE_PAYLOADCOLLECTION_TYPE & getMessagePayloadList() const
Get all message payloads and their values of the Service.
Definition: Service.cpp:168
wrench::Service::getPropertyValueAsDouble
double getPropertyValueAsDouble(WRENCH_PROPERTY_TYPE)
Get a property of the Service as a double.
Definition: Service.cpp:102
wrench::Service::messagepayload_list
WRENCH_MESSAGE_PAYLOADCOLLECTION_TYPE messagepayload_list
The service's messagepayload list.
Definition: Service.h:113
wrench::Service::name
std::string name
The service's name.
Definition: Service.h:116
wrench::Service::serviceSanityCheck
void serviceSanityCheck()
Check whether the service is properly configured and running.
Definition: Service.cpp:397
wrench::Service::assertServiceIsUp
void assertServiceIsUp()
Throws an exception if the service is not up.
Definition: Service.cpp:422
wrench::Service::setMessagePayload
void setMessagePayload(WRENCH_MESSAGEPAYLOAD_TYPE, double)
Set a message payload of the Service.
Definition: Service.cpp:68
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::setMessagePayloads
void setMessagePayloads(WRENCH_MESSAGE_PAYLOADCOLLECTION_TYPE default_messagepayload_values, WRENCH_MESSAGE_PAYLOADCOLLECTION_TYPE overriden_messagepayload_values)
Set default and user-defined message payloads.
Definition: Service.cpp:378
wrench::Service::getSharedPtr
std::shared_ptr< T > getSharedPtr()
Method to retrieve the shared_ptr to a service.
Definition: Service.h:129
wrench::Service::getMessagePayloadValue
double getMessagePayloadValue(WRENCH_MESSAGEPAYLOAD_TYPE)
Get a message payload of the Service as a double.
Definition: Service.cpp:155
wrench::Service::suspend
void suspend()
Suspend the service.
Definition: Service.cpp:294
wrench::Service::~Service
~Service() override
Destructor.
Definition: Service.cpp:34
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:121
wrench::Service::setProperty
void setProperty(WRENCH_PROPERTY_TYPE, const std::string &)
Set a property of the Service.
Definition: Service.cpp:53
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::S4U_Daemon
A generic "running daemon" abstraction that serves as a basis for all simulated processes.
Definition: S4U_Daemon.h:32
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::S4U_Daemon::hostname
std::string hostname
The name of the host on which the daemon is running.
Definition: S4U_Daemon.h:60
wrench::Simulation
A class that provides basic simulation methods. Once the simulation object has been explicitly or imp...
Definition: Simulation.h:48
wrench::Service::Service
Service(std::string hostname, std::string process_name_prefix)
Constructor.
Definition: Service.cpp:43
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::assertServiceIsUp
static void assertServiceIsUp(std::shared_ptr< Service > s)
Assert for the service being up.
Definition: Service.h:86
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