7#ifndef __DAEMON_H_IMPL__
8#define __DAEMON_H_IMPL__
10#include "phoenix_assert.h"
14template<
class _TBackend>
22template<
class _TBackend>
30template<
class _TBackend>
34 case PSocketMode::MOCK:
38 case PSocketMode::MOCK_RECORD:
52template<
class _TBackend>
56 case PClockMode::MOCK:
60 case PClockMode::MOCK_RECORD:
74template<
class _TBackend>
76 if(recvStatus == PRecvStatus::SOCKET_NOT_AVAILABLE){
78 p_log.getLogWarning() <<
"Daemon::checkRecvStatus : Socket not available" << std::endl;
80 if(recvStatus == PRecvStatus::SIGNAL_INTERRUPTION){
83 if(recvStatus == PRecvStatus::BROKEN_BACKEND){
86 if(recvStatus == PRecvStatus::BROKEN_SOCKET){
89 if(recvStatus == PRecvStatus::CANNOT_DESERIALIZE_DATA){
99template<
class _TBackend>
101 if(sendStatus == PSendStatus::SOCKET_NOT_AVAILABLE){
104 if(sendStatus == PSendStatus::NO_ROUTE_TO_RECEIVER){
107 if(sendStatus == PSendStatus::SIGNAL_INTERRUPTION){
108 p_log.criticalAndThrow<
Phoenix::SocketStatusException>(
"Daemon::checkSendStatus : Socket Backend caught a signal, aborting.",
"Socket Backend caught a signal, aborting.");
110 if(sendStatus == PSendStatus::BROKEN_BACKEND){
113 if(sendStatus == PSendStatus::BROKEN_SOCKET){
116 if(sendStatus == PSendStatus::CANNOT_SERIALIZE_DATA){
124template<
class _TBackend>
137 if(recvStatus == PRecvStatus::OK){
142 time_t currentTime =
p_backend.clock.now();
157template<
class _TBackend>
160 const PVecString & vecDestination = message.
getVecRecver();
161 for(PVecString::const_iterator it(vecDestination.begin()); it != vecDestination.end(); ++it){
172template<
class _TBackend>
187template<
class _TBackend>
201template<
class _TBackend>
205template<
class _TBackend>
209template<
class _TBackend>
215template<
class _TBackend>
231 getLog().getLogInfo() <<
"Daemon<_TBackend>::initialisationDaemonSocket() : initialise pull socket for daemon '" <<
p_config.getName() <<
"'" << std::endl;
232 phoenix_assert(
p_backend.socketManager.addServerSocket(
"pull",
233 PSocketParam{p_config.getHostName(), p_config.getReceivingPort(), p_mainConfig.recvTimeoutMs, p_mainConfig.sendTimeoutMs},
p_backend.extraServerParam,
238 if(it->second.getName() ==
p_config.getName()){
continue;}
239 getLog().getLogInfo() <<
"Daemon<_TBackend>::initialisationDaemonSocket() : initialise send socket for neighbour Daemon '"<<it->second.getName()<<
"'" << std::endl;
240 phoenix_assert(
p_backend.socketManager.addClientSocket(it->second.getName(),
241 PSocketParam{it->second.getHostName(), it->second.getReceivingPort(), p_mainConfig.recvTimeoutMs, p_mainConfig.sendTimeoutMs},
p_backend.extraClientParam,
245 getLog().getLogInfo() <<
"Daemon<_TBackend>::initialisationDaemonSocket() : all connection to neighbours Daemon initialised" << std::endl;
252template<
class _TBackend>
272 if(function == NULL){
275 time_t functionStartTime =
p_backend.clock.now();
277 getLog().getLogError() <<
"Daemon<_TBackend>::processInputMessage : cannot process data of type '"<<message.
getData().
getType()<<
"' from Daemon '"<<message.
getSender()<<
"'" << std::endl;
280 time_t functionEllapsedTime =
p_backend.clock.now() - functionStartTime;
281 getLog().getLogDebug() <<
"Daemon<_TBackend>::processInputMessage : function '"<<message.
getData().
getType()<<
"' processed data from daemon '"<<message.
getSender()<<
"' in "<<functionEllapsedTime<<
" nanoseconds" << std::endl;
291template<
class _TBackend>
300 getLog().getLogDebug() <<
"Daemon::sendStatToStatDaemon() : sending statistics to Stat Daemon '"<<
p_config.getStatDaemonName()<<
"'" << std::endl;
Abstract function definition which will be callable in Daemon.
virtual bool call(PLog &log, const Data &data)=0
PLog p_log
Logger of the current Daemon.
bool p_isRun
True if the current BaseDaemon is running.
void updateStatAccumulator(StatAccumulator &stat, float value)
Update a computing statistic with a new value.
bool p_isFullMockRecord
True if the daemon has to be executed in mock record mode for socket and clock.
DaemonMainConfig p_mainConfig
Main configuration of the Daemon.
bool p_isFullMock
True if the daemon has to be executed in mock mode for socket and clock.
void addMessageToConfirm(const Message &message)
Add a message to confirm.
AbstractDataFunction * getDataFunction(const Data &data)
Get the data function associated with the given data.
void fillDaemonStat(DaemonStat &stat, time_t startTimestamp, time_t endTimestamp)
Fill the DaemonStat with the current statistics of the daemon.
PLog & getLog()
Get the log of the current BaseDaemon.
void clearStat()
Clear all the statistics of the daemon.
void stop()
Stops the BaseDaemon.
void checkMessageTimeout(time_t currentTime)
Check if a message has reached the timeout.
DaemonConfig p_config
Configuration of the curent Daemon.
MapDaemonConfig p_mapDaemon
Map of the other Daemon of the Swarm.
size_t getMessageId()
Get current message id.
BaseDaemon()
Default constructor of BaseDaemon.
void processConfirmedMessage(size_t id, time_t currentTime)
Process confirmed message.
void setName(const PString &name)
Sets the name of the DaemonStat.
_TBackend p_backend
Full backend of the Daemon (for Socket and clock)
bool sendValue(const PString &destinationName, const T &data, bool isConfirmationNeeded=true)
Send data to other Daemon.
PTimer p_statTimer
Timer to send statistics to the Stat Daemon.
Daemon()
Default constructor of Daemon.
virtual void executeOnStop()
Method which is called on stop of the Daemon.
void sendStatToStatDaemon(time_t currentTime)
Send the statistics of the Daemon to the Stat Daemon.
PRecvStatus::PRecvStatus checkRecvStatus(PRecvStatus::PRecvStatus recvStatus)
Check the status of recv sockets.
time_t p_startTimestamp
Start timestamp of the current accumulation of statistics.
virtual ~Daemon()
Destructor of Daemon.
void setSocketMode(PSocketMode::PSocketMode mode)
Set the mode of the sockets of the SocketManager.
bool sendData(const PString &destinationName, const Data &data, bool isConfirmationNeeded)
Send data to other Daemon (specialization for Data)
bool sendMessage(const Message &message)
Send message to other Daemon.
void processInputMessage(Message &message)
Process an input message.
virtual void extraLoopProcessing()
Computing Method for each event loop (when receiving message from other Daemon)
void setClockMode(PClockMode::PClockMode mode)
Set the mode of the clock.
void initialisationDaemon()
Initialisation function of the class Daemon.
bool run()
Run the Daemon.
void initialisationDaemonSocket()
Initialise the Daemon Sockets.
void checkSendStatus(PSendStatus::PSendStatus sendStatus)
Check the status of recv sockets.
Basic Data exchanged in the swarm.
const PString & getType() const
Gets the type of the Data.
Message exchanged by Daemons.
const PString & getSender() const
Gets the sender of the Message.
void setType(const MessageType::MessageType &type)
Sets the type of the Message.
const std::vector< PString > & getVecRecver() const
Gets the vecRecver of the Message.
void setSendTime(const time_t &sendTime)
Sets the sendTime of the Message.
void setSender(const PString &sender)
Sets the sender of the Message.
const Data & getData() const
Gets the data of the Message.
size_t getId() const
Gets the id of the Message.
bool getIsConfirmationNeeded() const
Gets the isConfirmationNeeded of the Message.
void setIsConfirmationNeeded(bool isConfirmationNeeded)
Sets the isConfirmationNeeded of the Message.
void setId(size_t id)
Sets the id of the Message.
const MessageType::MessageType & getType() const
Gets the type of the Message.
const time_t & getSendTime() const
Gets the sendTime of the Message.
void setData(const Data &data)
Sets the data of the Message.
Exception for daemon configuration errors.
Exception for socket status errors.