| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /*************************************** | ||
| 2 | Auteur : Pierre Aubert | ||
| 3 | Mail : pierre.aubert@lapp.in2p3.fr | ||
| 4 | Licence : CeCILL-C | ||
| 5 | ****************************************/ | ||
| 6 | |||
| 7 | #ifndef __DAEMON_H_IMPL__ | ||
| 8 | #define __DAEMON_H_IMPL__ | ||
| 9 | |||
| 10 | #include "phoenix_assert.h" | ||
| 11 | #include "Daemon.h" | ||
| 12 | |||
| 13 | using namespace Swarm; | ||
| 14 | |||
| 15 | ///Default constructor of Daemon | ||
| 16 | template<class _TBackend> | ||
| 17 | 17 | Daemon<_TBackend>::Daemon() | |
| 18 |
2/2✓ Branch 0 (3→4) taken 17 times.
✓ Branch 2 (4→5) taken 17 times.
|
17 | :BaseDaemon() |
| 19 | { | ||
| 20 | 17 | initialisationDaemon(); | |
| 21 | 17 | } | |
| 22 | |||
| 23 | ///Destructor of Daemon | ||
| 24 | template<class _TBackend> | ||
| 25 | 17 | Daemon<_TBackend>::~Daemon(){ | |
| 26 | |||
| 27 | 17 | } | |
| 28 | |||
| 29 | ///Set the mode of the sockets of the SocketManager | ||
| 30 | /** @param mode : mode of the socket manager (NO_MOCK, MOCK, MOCK_RECORD) | ||
| 31 | */ | ||
| 32 | template<class _TBackend> | ||
| 33 | 18 | void Daemon<_TBackend>::setSocketMode(PSocketMode::PSocketMode mode){ | |
| 34 | 18 | p_backend.socketManager.setMode(mode); | |
| 35 |
3/3✓ Branch 0 (3→4) taken 16 times.
✓ Branch 1 (3→5) taken 1 times.
✓ Branch 2 (3→6) taken 1 times.
|
18 | switch(mode){ |
| 36 | 16 | case PSocketMode::MOCK: | |
| 37 | 16 | p_isFullMock = true; | |
| 38 | 16 | p_isFullMockRecord = false; | |
| 39 | 16 | break; | |
| 40 | 1 | case PSocketMode::MOCK_RECORD: | |
| 41 | 1 | p_isFullMock = false; | |
| 42 | 1 | p_isFullMockRecord = true; | |
| 43 | 1 | break; | |
| 44 | 1 | default: | |
| 45 | 1 | p_isFullMock = false; | |
| 46 | 1 | p_isFullMockRecord = false; | |
| 47 | 1 | break; | |
| 48 | } | ||
| 49 | 18 | } | |
| 50 | |||
| 51 | ///Set the mode of the clock | ||
| 52 | /** @param mode : mode of the clock (NO_MOCK, MOCK, MOCK_RECORD) | ||
| 53 | */ | ||
| 54 | template<class _TBackend> | ||
| 55 | 18 | void Daemon<_TBackend>::setClockMode(PClockMode::PClockMode mode){ | |
| 56 | 18 | p_backend.clock.setMode(mode); | |
| 57 |
3/3✓ Branch 0 (3→4) taken 16 times.
✓ Branch 1 (3→5) taken 1 times.
✓ Branch 2 (3→6) taken 1 times.
|
18 | switch(mode){ |
| 58 | 16 | case PClockMode::MOCK: | |
| 59 | 16 | p_isFullMock = true; | |
| 60 | 16 | p_isFullMockRecord = false; | |
| 61 | 16 | break; | |
| 62 | 1 | case PClockMode::MOCK_RECORD: | |
| 63 | 1 | p_isFullMock = false; | |
| 64 | 1 | p_isFullMockRecord = true; | |
| 65 | 1 | break; | |
| 66 | 1 | default: | |
| 67 | 1 | p_isFullMock = false; | |
| 68 | 1 | p_isFullMockRecord = false; | |
| 69 | 1 | break; | |
| 70 | } | ||
| 71 | 18 | } | |
| 72 | |||
| 73 | ///Check the status of recv sockets | ||
| 74 | /** @param recvStatus : status to be checked | ||
| 75 | */ | ||
| 76 | template<class _TBackend> | ||
| 77 | 1095 | PRecvStatus::PRecvStatus Daemon<_TBackend>::checkRecvStatus(PRecvStatus::PRecvStatus recvStatus){ | |
| 78 |
1/2✗ Branch 0 (2→3) not taken.
✓ Branch 1 (2→6) taken 1095 times.
|
1095 | if(recvStatus == PRecvStatus::SOCKET_NOT_AVAILABLE){ |
| 79 | // p_log.errorAndThrow<Phoenix::SocketStatusException>("Daemon::checkRecvStatus : Socket not available", "Socket not available"); | ||
| 80 | ✗ | p_log.getLogWarning() << "Daemon::checkRecvStatus : Socket not available" << std::endl; | |
| 81 | } | ||
| 82 |
1/2✗ Branch 0 (6→7) not taken.
✓ Branch 1 (6→11) taken 1095 times.
|
1095 | if(recvStatus == PRecvStatus::SIGNAL_INTERRUPTION){ |
| 83 | ✗ | p_log.criticalAndThrow<Phoenix::SocketStatusException>("Daemon::checkRecvStatus : Socket Backend caught a signal, aborting", "Socket Backend caught a signal, aborting"); | |
| 84 | } | ||
| 85 |
1/2✗ Branch 0 (11→12) not taken.
✓ Branch 1 (11→16) taken 1095 times.
|
1095 | if(recvStatus == PRecvStatus::BROKEN_BACKEND){ |
| 86 | ✗ | p_log.criticalAndThrow<Phoenix::SocketStatusException>("Daemon::checkRecvStatus : Back-end is in invalid state", "Back-end is in invalid state"); | |
| 87 | } | ||
| 88 |
1/2✗ Branch 0 (16→17) not taken.
✓ Branch 1 (16→21) taken 1095 times.
|
1095 | if(recvStatus == PRecvStatus::BROKEN_SOCKET){ |
| 89 | ✗ | p_log.criticalAndThrow<Phoenix::SocketStatusException>("Daemon::checkRecvStatus : Socket is in invalid state", "Socket is in invalid state"); | |
| 90 | } | ||
| 91 |
1/2✗ Branch 0 (21→22) not taken.
✓ Branch 1 (21→26) taken 1095 times.
|
1095 | if(recvStatus == PRecvStatus::CANNOT_DESERIALIZE_DATA){ |
| 92 | ✗ | p_log.errorAndThrow<Phoenix::SocketStatusException>("Daemon::checkRecvStatus : Cannot deserialize data", "Cannot deserialize data"); | |
| 93 | } | ||
| 94 | 1095 | return recvStatus; | |
| 95 | } | ||
| 96 | |||
| 97 | |||
| 98 | ///Check the status of recv sockets | ||
| 99 | /** @param sendStatus : status to be checked | ||
| 100 | */ | ||
| 101 | template<class _TBackend> | ||
| 102 | 20 | void Daemon<_TBackend>::checkSendStatus(PSendStatus::PSendStatus sendStatus){ | |
| 103 |
1/2✗ Branch 0 (2→3) not taken.
✓ Branch 1 (2→7) taken 20 times.
|
20 | if(sendStatus == PSendStatus::SOCKET_NOT_AVAILABLE){ |
| 104 | ✗ | p_log.errorAndThrow<Phoenix::SocketStatusException>("Daemon::checkSendStatus : Socket not available", "Socket not available"); | |
| 105 | } | ||
| 106 |
1/2✗ Branch 0 (7→8) not taken.
✓ Branch 1 (7→12) taken 20 times.
|
20 | if(sendStatus == PSendStatus::NO_ROUTE_TO_RECEIVER){ |
| 107 | ✗ | p_log.errorAndThrow<Phoenix::SocketStatusException>("Daemon::checkSendStatus : Receiver not reachable", "Receiver not reachable"); | |
| 108 | } | ||
| 109 |
1/2✗ Branch 0 (12→13) not taken.
✓ Branch 1 (12→17) taken 20 times.
|
20 | if(sendStatus == PSendStatus::SIGNAL_INTERRUPTION){ |
| 110 | ✗ | p_log.criticalAndThrow<Phoenix::SocketStatusException>("Daemon::checkSendStatus : Socket Backend caught a signal, aborting.", "Socket Backend caught a signal, aborting."); | |
| 111 | } | ||
| 112 |
1/2✗ Branch 0 (17→18) not taken.
✓ Branch 1 (17→22) taken 20 times.
|
20 | if(sendStatus == PSendStatus::BROKEN_BACKEND){ |
| 113 | ✗ | p_log.criticalAndThrow<Phoenix::SocketStatusException>("Daemon::checkSendStatus : Back-end is in invalid state", "Back-end is in invalid state"); | |
| 114 | } | ||
| 115 |
2/2✓ Branch 0 (22→23) taken 1 times.
✓ Branch 1 (22→27) taken 19 times.
|
20 | if(sendStatus == PSendStatus::BROKEN_SOCKET){ |
| 116 |
1/2✓ Branch 0 (23→24) taken 1 times.
✗ Branch 2 (24→25) not taken.
|
2 | p_log.criticalAndThrow<Phoenix::SocketStatusException>("Daemon::checkSendStatus : Socket is in invalid state", "Socket is in invalid state"); |
| 117 | } | ||
| 118 |
1/2✗ Branch 0 (27→28) not taken.
✓ Branch 1 (27→32) taken 19 times.
|
19 | if(sendStatus == PSendStatus::CANNOT_SERIALIZE_DATA){ |
| 119 | ✗ | p_log.errorAndThrow<Phoenix::SocketStatusException>("Daemon::checkSendStatus : Cannot serialize data", "Cannot serialize data"); | |
| 120 | } | ||
| 121 | 19 | } | |
| 122 | |||
| 123 | ///Run the Daemon | ||
| 124 | /** @return true if the run was a success, false otherwise | ||
| 125 | */ | ||
| 126 | template<class _TBackend> | ||
| 127 | 9 | bool Daemon<_TBackend>::run(){ | |
| 128 | 9 | p_isRun = true; | |
| 129 | //Let's initialise all connexions | ||
| 130 | 9 | initialisationDaemonSocket(); | |
| 131 | 9 | p_startTimestamp = p_backend.clock.now(); | |
| 132 | 9 | p_statTimer.setEllapsedTime(p_config.getStatTimerPeriodMs()); | |
| 133 | 9 | p_statTimer.setStartTime(p_startTimestamp); | |
| 134 |
2/2✓ Branch 0 (27→8) taken 1093 times.
✓ Branch 1 (27→28) taken 8 times.
|
2194 | while(p_isRun){ |
| 135 | //Let's get the last received message | ||
| 136 | //If there is not message, we treat the rest of the loop | ||
| 137 |
1/1✓ Branch 0 (8→9) taken 1093 times.
|
1093 | Message message; |
| 138 |
3/3✓ Branch 0 (9→10) taken 1093 times.
✓ Branch 2 (10→11) taken 1093 times.
✓ Branch 4 (11→12) taken 1093 times.
|
1093 | PRecvStatus::PRecvStatus recvStatus = checkRecvStatus(p_backend.socketManager.recvData("pull", message, p_mainConfig.recvFlag)); |
| 139 |
2/2✓ Branch 0 (13→14) taken 20 times.
✓ Branch 1 (13→15) taken 1073 times.
|
1093 | if(recvStatus == PRecvStatus::OK){ |
| 140 |
1/1✓ Branch 0 (14→15) taken 19 times.
|
20 | processInputMessage(message); |
| 141 | } | ||
| 142 |
1/1✓ Branch 0 (15→16) taken 1092 times.
|
1092 | extraLoopProcessing(); |
| 143 | |||
| 144 |
1/1✓ Branch 0 (16→17) taken 1092 times.
|
1092 | time_t currentTime = p_backend.clock.now(); |
| 145 |
1/1✓ Branch 0 (17→18) taken 1092 times.
|
1092 | checkMessageTimeout(currentTime); |
| 146 |
7/7✓ Branch 0 (18→19) taken 1092 times.
✓ Branch 2 (19→20) taken 860 times.
✓ Branch 3 (19→21) taken 232 times.
✓ Branch 4 (20→21) taken 7 times.
✓ Branch 5 (20→22) taken 853 times.
✓ Branch 6 (23→24) taken 239 times.
✓ Branch 7 (23→25) taken 853 times.
|
1092 | if(p_statTimer.isTime(currentTime) || !p_isRun){ |
| 147 |
1/1✓ Branch 0 (24→25) taken 239 times.
|
239 | sendStatToStatDaemon(currentTime); |
| 148 | } | ||
| 149 | } | ||
| 150 | //Let's execute a last command before stop | ||
| 151 | 8 | executeOnStop(); | |
| 152 | 8 | return true; | |
| 153 | } | ||
| 154 | |||
| 155 | ///Send message to other Daemon | ||
| 156 | /** @param message : message to be sent | ||
| 157 | * @return true on success, false otherwise (maybe received method does not exist) | ||
| 158 | */ | ||
| 159 | template<class _TBackend> | ||
| 160 | 10 | bool Daemon<_TBackend>::sendMessage(const Message & message){ | |
| 161 | 10 | bool b(true); | |
| 162 | 10 | const PVecString & vecDestination = message.getVecRecver(); | |
| 163 |
2/2✓ Branch 0 (17→4) taken 10 times.
✓ Branch 1 (17→18) taken 9 times.
|
38 | for(PVecString::const_iterator it(vecDestination.begin()); it != vecDestination.end(); ++it){ |
| 164 |
1/1✓ Branch 0 (6→7) taken 9 times.
|
10 | b &= sendMessage(*it, message); |
| 165 | } | ||
| 166 | 9 | return b; | |
| 167 | } | ||
| 168 | |||
| 169 | ///Send message to other Daemon | ||
| 170 | /** @param destinationName : name of the destination Daemon of the message | ||
| 171 | * @param message : message to be sent | ||
| 172 | * @return true on success, false otherwise (maybe received method does not exist) | ||
| 173 | */ | ||
| 174 | template<class _TBackend> | ||
| 175 | 20 | bool Daemon<_TBackend>::sendMessage(const PString & destinationName, const Message & message){ | |
| 176 |
2/2✓ Branch 0 (3→4) taken 10 times.
✓ Branch 1 (3→5) taken 10 times.
|
20 | if(message.getIsConfirmationNeeded()){ |
| 177 | 10 | addMessageToConfirm(message); | |
| 178 | } | ||
| 179 | 20 | checkSendStatus(p_backend.socketManager.sendData(destinationName, message, p_mainConfig.sendFlag)); | |
| 180 | 19 | return true; | |
| 181 | } | ||
| 182 | |||
| 183 | ///Send data to other Daemon (specialization for Data) | ||
| 184 | /** @param destinationName : name of the destination Daemon of the data | ||
| 185 | * @param data : data to be sent | ||
| 186 | * @param isConfirmationNeeded : true if a confirmation is needed | ||
| 187 | * @return true on success, false otherwise (maybe received method does not exist) | ||
| 188 | */ | ||
| 189 | template<class _TBackend> | ||
| 190 | 10 | bool Daemon<_TBackend>::sendData(const PString & destinationName, const Data & data, bool isConfirmationNeeded){ | |
| 191 |
1/1✓ Branch 0 (2→3) taken 10 times.
|
10 | Message message; |
| 192 |
2/2✓ Branch 0 (3→4) taken 10 times.
✓ Branch 2 (4→5) taken 10 times.
|
10 | message.setSendTime(p_backend.clock.now()); |
| 193 |
1/1✓ Branch 0 (5→6) taken 10 times.
|
10 | message.setData(data); |
| 194 |
2/2✓ Branch 0 (6→7) taken 10 times.
✓ Branch 2 (7→8) taken 10 times.
|
10 | message.setId(getMessageId()); |
| 195 |
1/1✓ Branch 0 (8→9) taken 10 times.
|
10 | message.setIsConfirmationNeeded(isConfirmationNeeded); |
| 196 |
1/1✓ Branch 0 (9→10) taken 10 times.
|
10 | message.setType(MessageType::RESULT_DATA); |
| 197 |
2/2✓ Branch 0 (10→11) taken 10 times.
✓ Branch 2 (11→12) taken 10 times.
|
10 | message.setSender(p_config.getName()); |
| 198 |
2/2✓ Branch 0 (12→13) taken 10 times.
✓ Branch 2 (13→14) taken 10 times.
|
10 | message.getVecRecver().push_back(destinationName); |
| 199 |
1/1✓ Branch 0 (14→15) taken 10 times.
|
20 | return sendMessage(destinationName, message); |
| 200 | 10 | } | |
| 201 | |||
| 202 | ///Computing Method for each event loop (when receiving message from other Daemon) | ||
| 203 | template<class _TBackend> | ||
| 204 | 432 | void Daemon<_TBackend>::extraLoopProcessing(){} | |
| 205 | |||
| 206 | ///Method which is called on stop of the Daemon | ||
| 207 | template<class _TBackend> | ||
| 208 | 6 | void Daemon<_TBackend>::executeOnStop(){} | |
| 209 | |||
| 210 | ///Initialisation function of the class Daemon | ||
| 211 | template<class _TBackend> | ||
| 212 | 17 | void Daemon<_TBackend>::initialisationDaemon(){ | |
| 213 | |||
| 214 | 17 | } | |
| 215 | |||
| 216 | ///Initialise the Daemon Sockets | ||
| 217 | template<class _TBackend> | ||
| 218 | 9 | void Daemon<_TBackend>::initialisationDaemonSocket(){ | |
| 219 |
1/2✗ Branch 0 (4→5) not taken.
✓ Branch 1 (4→10) taken 9 times.
|
9 | if(p_config.getName() == ""){ |
| 220 | ✗ | getLog().criticalAndThrow<Phoenix::ConfigException>("Daemon::initialisationDaemonSocket", "daemon has no name"); | |
| 221 | } | ||
| 222 |
1/2✗ Branch 0 (10→11) not taken.
✓ Branch 1 (10→13) taken 9 times.
|
9 | if(p_isFullMockRecord){ |
| 223 | ✗ | setSocketMode(PSocketMode::MOCK_RECORD); | |
| 224 | ✗ | setClockMode(PClockMode::MOCK_RECORD); | |
| 225 | }else{ | ||
| 226 |
2/2✓ Branch 0 (13→14) taken 6 times.
✓ Branch 1 (13→16) taken 3 times.
|
9 | if(p_isFullMock){ |
| 227 | 6 | setSocketMode(PSocketMode::MOCK); | |
| 228 | 6 | setClockMode(PClockMode::MOCK); | |
| 229 | } | ||
| 230 | } | ||
| 231 | //Let's send when we are a client and recv when we are a server | ||
| 232 | //By doing this way, we have one server per Daemon and as many clients as other Daemon | ||
| 233 | 9 | getLog().getLogInfo() << "Daemon<_TBackend>::initialisationDaemonSocket() : initialise pull socket for daemon '" << p_config.getName() << "'" << std::endl; | |
| 234 |
9/9✓ Branch 0 (23→24) taken 9 times.
✓ Branch 2 (24→25) taken 9 times.
✓ Branch 4 (28→29) taken 9 times.
✓ Branch 6 (29→30) taken 9 times.
✓ Branch 8 (30→31) taken 9 times.
✓ Branch 10 (33→34) taken 9 times.
✓ Branch 12 (36→37) taken 9 times.
✓ Branch 14 (39→40) taken 9 times.
✓ Branch 16 (40→41) taken 9 times.
|
81 | phoenix_assert(p_backend.socketManager.addServerSocket("pull", |
| 235 | PSocketParam{p_config.getHostName(), p_config.getReceivingPort(), p_mainConfig.recvTimeoutMs, p_mainConfig.sendTimeoutMs}, p_backend.extraServerParam, | ||
| 236 | "./" + p_config.getName() + "_", p_backend.extraMockServerParam)); | ||
| 237 | |||
| 238 | //Now let's initialise connexions to other | ||
| 239 |
2/2✓ Branch 0 (104→54) taken 10 times.
✓ Branch 1 (104→105) taken 9 times.
|
19 | for(MapDaemonConfig::iterator it(p_mapDaemon.begin()); it != p_mapDaemon.end(); ++it){ |
| 240 |
3/4✓ Branch 0 (55→56) taken 10 times.
✓ Branch 2 (56→57) taken 10 times.
✗ Branch 4 (58→59) not taken.
✓ Branch 5 (58→60) taken 10 times.
|
10 | if(it->second.getName() == p_config.getName()){continue;} |
| 241 |
7/7✓ Branch 0 (60→61) taken 10 times.
✓ Branch 2 (61→62) taken 10 times.
✓ Branch 4 (62→63) taken 10 times.
✓ Branch 6 (64→65) taken 10 times.
✓ Branch 8 (65→66) taken 10 times.
✓ Branch 10 (66→67) taken 10 times.
✓ Branch 12 (67→68) taken 10 times.
|
10 | getLog().getLogInfo() << "Daemon<_TBackend>::initialisationDaemonSocket() : initialise send socket for neighbour Daemon '"<<it->second.getName()<<"'" << std::endl; |
| 242 |
10/10✓ Branch 0 (69→70) taken 10 times.
✓ Branch 2 (71→72) taken 10 times.
✓ Branch 4 (74→75) taken 10 times.
✓ Branch 6 (76→77) taken 10 times.
✓ Branch 8 (77→78) taken 10 times.
✓ Branch 10 (78→79) taken 10 times.
✓ Branch 12 (81→82) taken 10 times.
✓ Branch 14 (84→85) taken 10 times.
✓ Branch 16 (87→88) taken 10 times.
✓ Branch 18 (88→89) taken 10 times.
|
100 | phoenix_assert(p_backend.socketManager.addClientSocket(it->second.getName(), |
| 243 | PSocketParam{it->second.getHostName(), it->second.getReceivingPort(), p_mainConfig.recvTimeoutMs, p_mainConfig.sendTimeoutMs}, p_backend.extraClientParam, | ||
| 244 | "./" + p_config.getName() + "_", p_backend.extraMockClientParam)); | ||
| 245 | // p_backend.socketManager.getSocket(it->second.getName())->waitUntilConnection(500000lu, 30lu); //0.5 s per check and 30 checks | ||
| 246 | } | ||
| 247 | 9 | getLog().getLogInfo() << "Daemon<_TBackend>::initialisationDaemonSocket() : all connection to neighbours Daemon initialised" << std::endl; | |
| 248 |
4/4✓ Branch 0 (109→110) taken 9 times.
✓ Branch 2 (110→111) taken 9 times.
✓ Branch 4 (111→112) taken 9 times.
✓ Branch 6 (112→113) taken 9 times.
|
9 | p_backend.clock.setMockPrefix("./" + p_config.getName() + "_"); |
| 249 |
7/13✓ Branch 0 (25→26) taken 9 times.
✓ Branch 2 (26→27) taken 9 times.
✓ Branch 4 (27→28) taken 9 times.
✗ Branch 6 (50→51) not taken.
✓ Branch 7 (50→52) taken 9 times.
✓ Branch 8 (72→73) taken 10 times.
✓ Branch 10 (75→76) taken 10 times.
✗ Branch 12 (98→99) not taken.
✓ Branch 13 (98→100) taken 10 times.
✗ Branch 14 (145→146) not taken.
✗ Branch 15 (145→147) not taken.
✗ Branch 16 (178→179) not taken.
✗ Branch 17 (178→180) not taken.
|
57 | } |
| 250 | |||
| 251 | ///Process an input message | ||
| 252 | /** @param[out] message : received Message to be processed | ||
| 253 | */ | ||
| 254 | template<class _TBackend> | ||
| 255 | 22 | void Daemon<_TBackend>::processInputMessage(Message & message){ | |
| 256 | //Check is the message needs a confirmation | ||
| 257 |
2/2✓ Branch 0 (3→4) taken 10 times.
✓ Branch 1 (3→18) taken 12 times.
|
22 | if(message.getIsConfirmationNeeded()){ |
| 258 |
1/1✓ Branch 0 (4→5) taken 10 times.
|
10 | Message confirmation; |
| 259 | //We do not need to change the time of the message because it has to be in the clock reference of the sender | ||
| 260 |
2/2✓ Branch 0 (5→6) taken 10 times.
✓ Branch 2 (6→7) taken 10 times.
|
10 | confirmation.setSendTime(message.getSendTime()); |
| 261 |
2/2✓ Branch 0 (7→8) taken 10 times.
✓ Branch 2 (8→9) taken 10 times.
|
10 | confirmation.setId(message.getId()); |
| 262 |
2/2✓ Branch 0 (9→10) taken 10 times.
✓ Branch 2 (10→11) taken 10 times.
|
10 | confirmation.setSender(p_config.getName()); |
| 263 |
1/1✓ Branch 0 (11→12) taken 10 times.
|
10 | confirmation.setType(MessageType::MESSAGE_CONFIRMATION); |
| 264 |
3/3✓ Branch 0 (12→13) taken 10 times.
✓ Branch 2 (13→14) taken 10 times.
✓ Branch 4 (14→15) taken 10 times.
|
10 | confirmation.getVecRecver().push_back(message.getSender()); |
| 265 |
1/1✓ Branch 0 (15→16) taken 9 times.
|
10 | sendMessage(confirmation); |
| 266 | 10 | } | |
| 267 | |||
| 268 | //Let's check is we receive a stop message | ||
| 269 |
2/2✓ Branch 0 (19→20) taken 5 times.
✓ Branch 1 (19→21) taken 16 times.
|
21 | if(message.getType() == MessageType::STOP){stop();} |
| 270 |
2/2✓ Branch 0 (22→23) taken 7 times.
✓ Branch 1 (22→26) taken 9 times.
|
16 | else if(message.getType() == MessageType::MESSAGE_CONFIRMATION){ |
| 271 | 7 | processConfirmedMessage(message.getId(), p_backend.clock.now()); | |
| 272 |
1/2✓ Branch 0 (27→28) taken 9 times.
✗ Branch 1 (27→80) not taken.
|
9 | }else if(message.getType() == MessageType::RESULT_DATA){ |
| 273 | 9 | AbstractDataFunction* function = getDataFunction(message.getData()); | |
| 274 |
1/2✗ Branch 0 (30→31) not taken.
✓ Branch 1 (30→32) taken 9 times.
|
9 | if(function == NULL){ |
| 275 | ✗ | return; | |
| 276 | } | ||
| 277 | 9 | time_t functionStartTime = p_backend.clock.now(); | |
| 278 |
1/2✗ Branch 0 (35→36) not taken.
✓ Branch 1 (35→48) taken 9 times.
|
9 | if(!function->call(p_log, message.getData())){ |
| 279 | ✗ | getLog().getLogError() << "Daemon<_TBackend>::processInputMessage : cannot process data of type '"<<message.getData().getType()<<"' from Daemon '"<<message.getSender()<<"'" << std::endl; | |
| 280 | ✗ | return; | |
| 281 | } | ||
| 282 | 9 | time_t functionEllapsedTime = p_backend.clock.now() - functionStartTime; | |
| 283 | 9 | getLog().getLogDebug() << "Daemon<_TBackend>::processInputMessage : function '"<<message.getData().getType()<<"' processed data from daemon '"<<message.getSender()<<"' in "<<functionEllapsedTime<<" nanoseconds" << std::endl; | |
| 284 |
6/6✓ Branch 0 (64→65) taken 7 times.
✓ Branch 1 (64→70) taken 2 times.
✓ Branch 2 (68→69) taken 5 times.
✓ Branch 3 (68→70) taken 2 times.
✓ Branch 4 (71→72) taken 5 times.
✓ Branch 5 (71→80) taken 4 times.
|
9 | if(p_config.getStatDaemonName() != "" && p_config.getStatDaemonName() != p_config.getName()){ |
| 285 |
6/6✓ Branch 0 (72→73) taken 5 times.
✓ Branch 2 (73→74) taken 5 times.
✓ Branch 4 (74→75) taken 5 times.
✓ Branch 6 (75→76) taken 5 times.
✓ Branch 8 (76→77) taken 5 times.
✓ Branch 10 (78→79) taken 5 times.
|
5 | updateStatAccumulator(p_config.getDaemonStatAccumulator().getMapStatComputing().find(message.getData().getType())->second, functionEllapsedTime); |
| 286 | } | ||
| 287 | } | ||
| 288 | } | ||
| 289 | |||
| 290 | ///Send the statistics of the Daemon to the Stat Daemon | ||
| 291 | /** @param[out] currentTime : current time to be used for the statistics | ||
| 292 | */ | ||
| 293 | template<class _TBackend> | ||
| 294 | 239 | void Daemon<_TBackend>::sendStatToStatDaemon(time_t currentTime){ | |
| 295 | //Let's fill the Stat | ||
| 296 |
1/1✓ Branch 0 (2→3) taken 239 times.
|
239 | Stat stat; |
| 297 |
1/1✓ Branch 0 (3→4) taken 239 times.
|
239 | fillDaemonStat(stat, p_startTimestamp, currentTime); |
| 298 |
2/2✓ Branch 0 (4→5) taken 239 times.
✓ Branch 2 (5→6) taken 239 times.
|
239 | stat.setName(p_config.getName()); |
| 299 | |||
| 300 | //Let's send it to the Stat Daemon | ||
| 301 |
10/10✓ Branch 0 (6→7) taken 239 times.
✓ Branch 2 (7→8) taken 239 times.
✓ Branch 4 (8→9) taken 234 times.
✓ Branch 5 (8→14) taken 5 times.
✓ Branch 6 (9→10) taken 234 times.
✓ Branch 8 (10→11) taken 234 times.
✓ Branch 10 (12→13) taken 2 times.
✓ Branch 11 (12→14) taken 232 times.
✓ Branch 12 (15→16) taken 2 times.
✓ Branch 13 (15→25) taken 237 times.
|
239 | if(p_config.getStatDaemonName() != "" && p_config.getStatDaemonName() != p_config.getName()){ |
| 302 |
7/7✓ Branch 0 (16→17) taken 2 times.
✓ Branch 2 (17→18) taken 2 times.
✓ Branch 4 (18→19) taken 2 times.
✓ Branch 6 (19→20) taken 2 times.
✓ Branch 8 (20→21) taken 2 times.
✓ Branch 10 (21→22) taken 2 times.
✓ Branch 12 (22→23) taken 2 times.
|
2 | getLog().getLogDebug() << "Daemon::sendStatToStatDaemon() : sending statistics to Stat Daemon '"<<p_config.getStatDaemonName()<<"'" << std::endl; |
| 303 |
2/2✓ Branch 0 (23→24) taken 2 times.
✓ Branch 2 (24→25) taken 2 times.
|
2 | sendValue(p_config.getStatDaemonName(), stat, true); |
| 304 | } | ||
| 305 | |||
| 306 |
1/1✓ Branch 0 (25→26) taken 239 times.
|
239 | clearStat(); |
| 307 | 239 | p_startTimestamp = currentTime; | |
| 308 | 239 | } | |
| 309 | |||
| 310 | #endif | ||
| 311 | |||
| 312 |