#ifndef DGRIDD_NODE_ARBITER_H #define DGRIDD_NODE_ARBITER_H #include #include #include #include #include #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& nodes); DGridResult table__request_passthru(const NodeID& node_id, const RequestType type, const RequestSubType subtype, const std::vector& payload, std::vector& response); protected: virtual void run(); void checkConnections(); void processEvents(); void eventHandler(std::shared_ptr 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 e); std::shared_ptr popEvent(); std::mutex equeue_mutex; std::queue > equeue; uint16_t redundancy_level; uint32_t reconnect_interval; std::set node_clients; std::map nodes_active; std::map nodes_lost; std::set nodes_dead; }; } // namespace DGrid #endif // DGRIDD_NODE_ARBITER_H