#include "../shared/GlobalConfigFile.h" #include "../shared/ContainerThread.h" #include "../shared/SimpleLogFile.h" #include "RecordDispatcher.h" #include "AlertRecordMultiCast.h" #include "MultiCastFeedNextServer.h" class MultiCastFeedNextServer : private ForeverThreadUser { private: enum { mtNewRecord, mtNewStatus }; AlertRecordMultiCastSender _sender; // From ForeverThreadUser virtual void handleRequestInThread(Request *request) override { switch (request->callbackId) { case mtNewRecord: { NewRecord *current = dynamic_cast< NewRecord * >(request); _sender.send(current->record); break; } case mtNewStatus: { ProviderStatus *current = dynamic_cast< ProviderStatus * >(request); _sender.send(current->name); break; } } } MultiCastFeedNextServer(IRecordDispatcher *source) : ForeverThreadUser(IContainerThread::create ("MultiCastFeedNextServer " + source->getBaseName(), false, strtolDefault(getConfigItem(source->getBaseName() + "_queueSize"), 3000))), // getConfigItem: alerts_queueSize & top_list_queueSize // getConfigItem: How far behind should this thread get before it reports // getConfigItem: something to the log? These values are shared with // getConfigItem: FeedNextServer.C. _sender(source->getBaseName(), getContainer()) { const bool success = _sender.isOkay(); TclList msg; msg<getBaseName()<<(char const *)(success?"success":"_sender FAILED"); sendToLogFile(msg); if (success) { source->listenForRecords(this, mtNewRecord); source->listenForStatus(this, mtNewStatus); start(); } } public: static void init(IRecordDispatcher *source) { // getConfigItem: alerts_multicast_feed_next_server & // getConfigItem: top_list_multicast_feed_next_server // getConfigItem: By default, the master will send multicast messages to // getConfigItem: the slaves, but slaves will not send multicast data. // getConfigItem: But these config items can override this in either // getConfigItem: direction. 1 means to send every record to the multicast // getConfigItem: group. 0 disables this feature, mostly so you won't have // getConfigItem: duplicate records. bool create = source->isMaster(); std::string value = getConfigItem(source->getBaseName() + "_multicast_feed_next_server"); if (value == "1") create = true; else if (value == "0") create = false; if (create) new MultiCastFeedNextServer(source); } }; void initMultiCastFeedNextServer() { MultiCastFeedNextServer::init(IRecordDispatcher::getAlerts()); MultiCastFeedNextServer::init(IRecordDispatcher::getTopList()); }