#ifndef DGRIDD_NODE_ARBITER_H
|
#define DGRIDD_NODE_ARBITER_H
|
|
#include <map>
|
#include <set>
|
#include <queue>
|
#include <string>
|
#include <mutex>
|
#include "dgrid_thread.h"
|
|
namespace DGrid {
|
|
class DGridNodeClient;
|
|
class DGriddNodeArbiter: public DGriddThread
|
{
|
public:
|
DGriddNodeArbiter();
|
~DGriddNodeArbiter();
|
bool start();
|
void stop();
|
|
// stats
|
void showStats();
|
uint16_t activeNodesCount();
|
uint16_t knownNodesCount();
|
|
// data requests
|
DGridResult get_theme_simple(const std::string& session, const std::string& theme_name, SimpleValueMap& data, const NodeID& old_source);
|
DGridResult append_theme_simple(const std::string& session, const std::string& theme_name, const SimpleValueMap& data, const NodeID& old_source);
|
DGridResult sync_theme_simple(const std::string& session, const std::string& theme_name, SimpleValueMap& data);
|
|
DGridResult table__get_master_node(const TableFullID& full_id, TableID& table_id, NodeID& node_id);
|
DGridResult table__choose_fallback_nodes(std::vector<NodeID>& nodes);
|
DGridResult table__request_passthru(const NodeID& node_id, const RequestType type, const RequestSubType subtype, const std::vector<char>& payload, std::vector<char>& response);
|
|
protected:
|
virtual void run();
|
void checkConnections();
|
|
void processEvents();
|
void eventHandler(std::shared_ptr<DGridEvent> e);
|
DGridNodeClient* getNode(const NodeID& id);
|
DGridResult notify_old_source(const std::string& session, const std::string& theme_name, const SimpleValueMap& data, const NodeID& old_source);
|
|
private:
|
void pushEvent(std::shared_ptr<DGridEvent> e);
|
std::shared_ptr<DGridEvent> popEvent();
|
std::mutex equeue_mutex;
|
std::queue<std::shared_ptr<DGridEvent> > equeue;
|
|
uint16_t redundancy_level;
|
uint32_t reconnect_interval;
|
std::set<DGridNodeClient*> node_clients;
|
std::map<NodeID, DGridNodeClient*> nodes_active;
|
std::map<DGridNodeClient*, NodeID> nodes_lost;
|
std::set<NodeID> nodes_dead;
|
};
|
|
} // namespace DGrid
|
|
#endif // DGRIDD_NODE_ARBITER_H
|