salsa 0.7.1
Loading...
Searching...
No Matches
Distributor.cc
1#include "Distributor.hh"
2namespace Salsa {
3Distributor::Distributor(std::string uuid, std::shared_ptr<Socket> pipe, NodeManager * pNodeMan)
4 : Object(), mUUID(uuid), mpPipe(pipe), mpNodeManager(pNodeMan)
5{
9}
17
18void Distributor::addClient(std::string uuid, std::string type)
19{
23 mClients.emplace(uuid, type);
24}
25
27{
31 mClients.erase(uuid);
32}
33
34void Distributor::addOther(std::string uuid, std::string type)
35{
39 mOthers.emplace(uuid, type);
40}
41
43{
47 mOthers.erase(uuid);
48}
49
51{
55 SPD_DEBUG("clients [{}] others [{}] pipe [{}]", mClients.size(), mOthers.size(), static_cast<void *>(mpPipe.get()));
56}
57
58void Distributor::onEnter(Message * /*inMsg*/, std::vector<std::string> & /*out*/, std::string /*type*/)
59{
63}
64void Distributor::onExit(Message * /*inMsg*/, std::vector<std::string> & /*out*/)
65{
69}
70void Distributor::onWhisper(Message * /*inMsg*/, std::vector<std::string> & /*out*/)
71{
75}
76
77std::shared_ptr<Socket> Distributor::pipe() const
78{
82 return mpPipe;
83}
84std::string Distributor::uuid() const
85{
89 return std::move(mUUID);
90}
91
92NodeInfo * Distributor::nodeInfo() const
93{
97 return mpNodeInfo;
98}
99
101{
105
106 if (mpNodeInfo == nullptr) return;
107
108 mJsonValue.clear();
109 mJsonValue["uuid"] = mpNodeInfo->uuid();
110 if (!mpNodeInfo->name().empty()) mJsonValue["name"] = mpNodeInfo->name();
111 if (!mpNodeInfo->name().empty()) mJsonValue["hostname"] = mpNodeInfo->hostname();
112 if (!mpNodeInfo->submiturl().empty()) mJsonValue["submitUrl"] = mpNodeInfo->submiturl();
113 mJsonValue["slots"] = mpNodeInfo->slots();
114 if (mpNodeInfo->hosts_size() > 0) {
115 for (auto hh : mpNodeInfo->hosts()) {
116 Json::Value h;
117 h["uuid"] = hh.uuid();
118 h["hostname"] = hh.hostname();
119 h["slots"] = hh.slots();
120 mJsonValue["hosts"].append(h);
121 }
122 }
123}
124
125} // namespace Salsa
virtual void onWhisper(Message *pInMsg, std::vector< std::string > &out)
std::map< std::string, std::string > mClients
List of clients.
Json::Value mJsonValue
Node Info as json value.
NodeInfo * nodeInfo() const
std::map< std::string, std::string > mOthers
List of others.
void addClient(std::string uuid, std::string type)
virtual void upadateJsonValueNodeInfo()
std::string mUUID
Self UUID.
void removeClient(std::string uuid)
void print() const
TODO Prints distributor's state.
std::shared_ptr< Socket > mpPipe
Pipe for messages (net connector)
NodeManager * mpNodeManager
Node Manager.
virtual ~Distributor()
void addOther(std::string uuid, std::string type)
virtual void onEnter(Message *pInMsg, std::vector< std::string > &out, std::string type)
TODO Three horsemen of apocalypse.
void removeOther(std::string uuid)
virtual void onExit(Message *pInMsg, std::vector< std::string > &out)
std::shared_ptr< Socket > pipe() const
TODO Returns distributor's pipe?
NodeInfo * mpNodeInfo
Node Info.
std::string uuid() const
Returns distributor's UUID.
Distributor(std::string uuid, std::shared_ptr< Socket > pPipe, NodeManager *pNM)
Definition Distributor.cc:3
Base Message class.
Definition Message.hh:15
NodeManager class.