1
This commit is contained in:
parent
dfa6dfb9cc
commit
e75261e41e
@ -1,13 +1,19 @@
|
|||||||
#include "precompile.h"
|
#include "precompile.h"
|
||||||
|
|
||||||
#include <a8/mutable_xobject.h>
|
#include <a8/mutable_xobject.h>
|
||||||
|
#include <a8/timer.h>
|
||||||
|
|
||||||
#include "gsmgr.h"
|
#include "gsmgr.h"
|
||||||
#include "GGListener.h"
|
#include "GGListener.h"
|
||||||
|
|
||||||
void GSMgr::Init()
|
void GSMgr::Init()
|
||||||
{
|
{
|
||||||
|
a8::Timer::Instance()->AddRepeatTimer(1000 * 2,
|
||||||
|
a8::XParams(),
|
||||||
|
[] (const a8::XParams& param)
|
||||||
|
{
|
||||||
|
GSMgr::Instance()->ClearTimeOutNode();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void GSMgr::UnInit()
|
void GSMgr::UnInit()
|
||||||
@ -59,6 +65,7 @@ void GSMgr::___GSReport(f8::JsonHttpRequest* request)
|
|||||||
itr->second.servicing = servicing;
|
itr->second.servicing = servicing;
|
||||||
RearrangeNode();
|
RearrangeNode();
|
||||||
}
|
}
|
||||||
|
itr->second.last_active_tick = a8::XGetTickCount();
|
||||||
} else {
|
} else {
|
||||||
GSNode gs;
|
GSNode gs;
|
||||||
gs.node_id = node_id;
|
gs.node_id = node_id;
|
||||||
@ -68,6 +75,7 @@ void GSMgr::___GSReport(f8::JsonHttpRequest* request)
|
|||||||
gs.ip = ip;
|
gs.ip = ip;
|
||||||
gs.port = port;
|
gs.port = port;
|
||||||
gs.servicing = servicing;
|
gs.servicing = servicing;
|
||||||
|
gs.last_active_tick = a8::XGetTickCount();
|
||||||
node_key_hash_[key] = gs;
|
node_key_hash_[key] = gs;
|
||||||
node_sorted_list_.push_back(&node_key_hash_[key]);
|
node_sorted_list_.push_back(&node_key_hash_[key]);
|
||||||
RearrangeNode();
|
RearrangeNode();
|
||||||
@ -128,3 +136,35 @@ void GSMgr::RearrangeNode()
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GSMgr::ClearTimeOutNode()
|
||||||
|
{
|
||||||
|
std::vector<GSNode*> time_out_nodes;
|
||||||
|
for (auto& pair : node_key_hash_) {
|
||||||
|
if (a8::XGetTickCount() - pair.second.last_active_tick > 1000 * 5) {
|
||||||
|
time_out_nodes.push_back(&pair.second);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (GSNode* node : time_out_nodes) {
|
||||||
|
{
|
||||||
|
for (size_t i = 0; i < node_sorted_list_.size(); ++i) {
|
||||||
|
if (node_sorted_list_[i] == node) {
|
||||||
|
node_sorted_list_.erase(node_sorted_list_.begin() + i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
{
|
||||||
|
std::vector<std::string> deleted_teams;
|
||||||
|
for (auto& pair : team_hash_) {
|
||||||
|
if (pair.second == node) {
|
||||||
|
deleted_teams.push_back(pair.first);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (const std::string& team_id : deleted_teams) {
|
||||||
|
team_hash_.erase(team_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
node_key_hash_.erase(node->key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -13,6 +13,7 @@ struct GSNode
|
|||||||
std::string ip;
|
std::string ip;
|
||||||
int port = 0;
|
int port = 0;
|
||||||
bool servicing = false;
|
bool servicing = false;
|
||||||
|
long long last_active_tick = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class GSMgr : public a8::Singleton<GSMgr>
|
class GSMgr : public a8::Singleton<GSMgr>
|
||||||
@ -38,6 +39,7 @@ class GSMgr : public a8::Singleton<GSMgr>
|
|||||||
GSNode* GetNodeByTeamId(const std::string& team_id);
|
GSNode* GetNodeByTeamId(const std::string& team_id);
|
||||||
GSNode* AllocNode();
|
GSNode* AllocNode();
|
||||||
void RearrangeNode();
|
void RearrangeNode();
|
||||||
|
void ClearTimeOutNode();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user