11 #ifndef WRENCH_SERVICE_H
12 #define WRENCH_SERVICE_H
18 #include <wrench/simgrid_S4U_util/S4U_Daemon.h>
36 void start(std::shared_ptr<Service> this_service,
bool daemonize,
bool auto_restart);
63 double getMessagePayloadValue(std::string);
65 void setStateToDown();
67 static void increaseNumCompletedServicesCount();
68 static void clearTrackedServices();
69 static void cleanupTrackedServices();
85 static void assertServiceIsUp(std::shared_ptr<Service> s) { s->assertServiceIsUp(); };
91 Service(std::string hostname, std::string process_name_prefix, std::string mailbox_name_prefix);
94 void setProperty(std::string, std::string);
96 void setProperties(std::map<std::string, std::string> default_property_values,
97 std::map<std::string, std::string> overriden_property_values);
100 void setMessagePayload(std::string,
double);
102 void setMessagePayloads(std::map<std::string, double> default_messagepayload_values,
103 std::map<std::string, double> overriden_messagepayload_values);
106 void serviceSanityCheck();
109 std::map<std::string, std::string> property_list;
112 std::map<std::string, double> messagepayload_list;
120 double network_timeout = 30.0;
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");
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");
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);
159 static std::unordered_map<Service *, std::shared_ptr<Service>> service_shared_ptr_map;
161 bool shutting_down =
false;
163 static unsigned long num_terminated_services;
174 #endif //WRENCH_SERVICE_H
void setNetworkTimeoutValue(double value)
Sets the service's network timeout value.
Definition: Service.cpp:425
void start(std::shared_ptr< Service > this_service, bool daemonize, bool auto_restart)
Start the service.
Definition: Service.cpp:237
bool getPropertyValueAsBoolean(std::string)
Get a property of the Service as a boolean.
Definition: Service.cpp:209
double getPropertyValueAsDouble(std::string)
Get a property of the Service as a double.
Definition: Service.cpp:139
void assertServiceIsUp()
Throws an exception if the service is not up.
Definition: Service.cpp:433
unsigned long getPropertyValueAsUnsignedLong(std::string)
Get a property of the Service as an unsigned long.
Definition: Service.cpp:165
bool isUp()
Returns true if the service is UP, false otherwise.
Definition: Service.cpp:355
void suspend()
Suspend the service.
Definition: Service.cpp:317
virtual void stop()
Synchronously stop the service (does nothing if the service is already stopped)
Definition: Service.cpp:269
std::string getPropertyValueAsString(std::string)
Get a property of the Service as a string.
Definition: Service.cpp:123
double getNetworkTimeoutValue()
Returns the service's network timeout value.
Definition: Service.cpp:416
A class that provides basic simulation methods. Once the simulation object has been explicitly or imp...
Definition: Simulation.h:46
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
std::string getHostname()
Get the name of the host on which the service is / will be running.
Definition: Service.cpp:347
void resume()
Resume the service.
Definition: Service.cpp:333