1
This commit is contained in:
parent
5587c3c85c
commit
8ef28cf556
@ -9,8 +9,6 @@
|
||||
|
||||
void JsonDataMgr::Init()
|
||||
{
|
||||
node_host_mutex_ = new std::mutex();
|
||||
|
||||
if (!f8::IsOnlineEnv()) {
|
||||
if (f8::IsTestEnv()) {
|
||||
work_path_ = a8::Format("../../../conf_test/game%d/wsproxy.test",
|
||||
@ -47,26 +45,12 @@ void JsonDataMgr::Init()
|
||||
|
||||
wsproxyserver_cluster_json_.ReadFromFile(wsproxyserver_cluster_json_file);
|
||||
masterserver_cluster_json_.ReadFromFile(masterserver_cluster_json_file);
|
||||
routing_tables_json_.ReadFromFile(routing_tables_json_file);
|
||||
node_host_mutex_->lock();
|
||||
for (int i = 0; i < routing_tables_json_.Size(); ++i) {
|
||||
auto node_conf = routing_tables_json_.At(i);
|
||||
int node_id = node_conf->At("node_id")->AsXValue();
|
||||
std::string host = node_conf->At("host")->AsXValue();
|
||||
if (node_host_hash_.find(node_id) != node_host_hash_.end()) {
|
||||
abort();
|
||||
}
|
||||
node_host_hash_[node_id] = host;
|
||||
}
|
||||
node_host_mutex_->unlock();
|
||||
udp_host_ = GetConf()->At("listen_udp_host")->AsXValue().GetString();
|
||||
udp_port_ = GetConf()->At("listen_udp_port")->AsXValue();
|
||||
}
|
||||
|
||||
void JsonDataMgr::UnInit()
|
||||
{
|
||||
delete node_host_mutex_;
|
||||
node_host_mutex_ = nullptr;
|
||||
}
|
||||
|
||||
std::shared_ptr<a8::XObject> JsonDataMgr::GetConf()
|
||||
@ -78,11 +62,6 @@ std::shared_ptr<a8::XObject> JsonDataMgr::GetConf()
|
||||
return wsproxyserver_cluster_json_[App::Instance()->GetInstanceId() - 1];
|
||||
}
|
||||
|
||||
std::shared_ptr<a8::XObject> JsonDataMgr::GetMasterServerClusterConf()
|
||||
{
|
||||
return std::make_shared<a8::XObject>(masterserver_cluster_json_);
|
||||
}
|
||||
|
||||
void JsonDataMgr::TraverseMaster(std::function<void (int, std::string, int)> cb)
|
||||
{
|
||||
for (int i = 0; i < masterserver_cluster_json_.Size(); ++i) {
|
||||
|
@ -12,19 +12,15 @@ class JsonDataMgr : public a8::Singleton<JsonDataMgr>
|
||||
void Init();
|
||||
void UnInit();
|
||||
|
||||
std::shared_ptr<a8::XObject> GetConf();
|
||||
std::shared_ptr<a8::XObject> GetMasterServerClusterConf();
|
||||
void TraverseMaster(std::function<void (int, std::string, int)> cb);
|
||||
std::string GetUdpHost() { return udp_host_; }
|
||||
int GetUdpPort() { return udp_port_; }
|
||||
std::shared_ptr<a8::XObject> GetConf();
|
||||
void TraverseMaster(std::function<void (int, std::string, int)> cb);
|
||||
|
||||
private:
|
||||
std::string work_path_ = "../config";
|
||||
a8::XObject wsproxyserver_cluster_json_;
|
||||
a8::XObject masterserver_cluster_json_;
|
||||
std::mutex* node_host_mutex_ = nullptr;
|
||||
a8::XObject routing_tables_json_;
|
||||
std::map<int, std::string> node_host_hash_;
|
||||
std::string udp_host_;
|
||||
int udp_port_ = 0;
|
||||
};
|
||||
|
@ -35,19 +35,15 @@ void MasterMgr::Init()
|
||||
{
|
||||
curr_context_id_ = a8::MakeInt64(0, time(nullptr) + 1000 * 60 * 10);
|
||||
|
||||
auto master_svr_cluster_conf = JsonDataMgr::Instance()->GetMasterServerClusterConf();
|
||||
for (int i = 0; i < master_svr_cluster_conf->Size(); ++i) {
|
||||
auto master_svr_conf = master_svr_cluster_conf->At(i);
|
||||
int instance_id = master_svr_conf->At("instance_id")->AsXValue();
|
||||
std::string remote_ip = master_svr_conf->At("ip")->AsXValue();
|
||||
int remote_port = master_svr_conf->At("port")->AsXValue();
|
||||
{
|
||||
auto conn = std::make_shared<Master>();
|
||||
conn->Init(instance_id, remote_ip, remote_port);
|
||||
mastersvr_hash_[conn->instance_id] = conn;
|
||||
conn->Open();
|
||||
}
|
||||
}
|
||||
JsonDataMgr::Instance()->TraverseMaster
|
||||
(
|
||||
[this] (int instance_id, std::string remote_ip, int remote_port)
|
||||
{
|
||||
auto conn = std::make_shared<Master>();
|
||||
conn->Init(instance_id, remote_ip, remote_port);
|
||||
mastersvr_hash_[conn->instance_id] = conn;
|
||||
conn->Open();
|
||||
});
|
||||
}
|
||||
|
||||
void MasterMgr::UnInit()
|
||||
|
Loading…
x
Reference in New Issue
Block a user