-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOuterFactoryImp.cpp
More file actions
257 lines (209 loc) · 6.69 KB
/
OuterFactoryImp.cpp
File metadata and controls
257 lines (209 loc) · 6.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
#include <sstream>
#include "OuterFactoryImp.h"
#include "LogComm.h"
#include "GlobalServer.h"
#include "util/tc_hash_fun.h"
//
using namespace wbl;
//
OuterFactoryImp::OuterFactoryImp() : _pFileConf(NULL)
{
createAllObject();
}
//
OuterFactoryImp::~OuterFactoryImp()
{
deleteAllObject();
}
//
void OuterFactoryImp::deleteAllObject()
{
if (_pFileConf)
{
delete _pFileConf;
_pFileConf = NULL;
}
}
//代理管理器
const OuterProxyFactoryPtr &OuterFactoryImp::getProxyFactory() const
{
return _pProxyFactory;
}
//获取服务配置
const tars::TC_Config &OuterFactoryImp::getConfig() const
{
return *_pFileConf;
}
//
void OuterFactoryImp::createAllObject()
{
__TRY__
deleteAllObject();
//tars代理Factory,访问其他tars接口时使用
_pProxyFactory = new OuterProxyFactory();
if (!_pProxyFactory)
{
ROLLLOG_ERROR << "create outer proxy factory fail, ptr null." << endl;
terminate();
}
LOG_DEBUG << "init proxy factory succ." << endl;
load();
__CATCH__
}
void OuterFactoryImp::load()
{
__TRY__
//拉取远程配置
g_app.addConfig(ServerConfig::ServerName + ".conf");
_pFileConf = new tars::TC_Config();
if (!_pFileConf)
{
ROLLLOG_ERROR << "create config parser fail, ptr null." << endl;
terminate();
}
_pFileConf->parseFile(ServerConfig::BasePath + ServerConfig::ServerName + ".conf");
LOG_DEBUG << "init config file succ, base path: " << ServerConfig::BasePath + ServerConfig::ServerName + ".conf" << endl;
readAllConfig();
__CATCH__
}
// 读取所有配置
void OuterFactoryImp::readAllConfig()
{
__TRY__
readPrxConfig();
printPrxConfig();
readListAllRoomAddress();
__CATCH__
}
//拆分字符串成整形
int OuterFactoryImp::splitInt(string szSrc, vector<int> &vecInt)
{
split_int(szSrc, "[ \t]*\\|[ \t]*", vecInt);
return 0;
}
//格式化时间
string OuterFactoryImp::timeFormat(const string &sFormat, time_t timeCluster)
{
//string sFormat("%Y-%m-%d %H:%M:%S");
if (sFormat.empty())
return "";
time_t t = timeCluster;
auto pTm = localtime(&t);
if (!pTm)
return "";
char sTimeString[255] = "\0";
strftime(sTimeString, sizeof(sTimeString), sFormat.c_str(), pTm);
return string(sTimeString);
}
//代理配置
void OuterFactoryImp::readPrxConfig()
{
_ConfigServantObj = (*_pFileConf).get("/Main/Interface/ConfigServer<ProxyObj>", "");
_DBAgentServantObj = (*_pFileConf).get("/Main/Interface/DBAgentServer<ProxyObj>", "");
_HallServantObj = (*_pFileConf).get("/Main/Interface/HallServer<ProxyObj>", "");
_PushServantObj = (*_pFileConf).get("/Main/Interface/PushServer<ProxyObj>", "");
}
//打印代理配置
void OuterFactoryImp::printPrxConfig()
{
FDLOG_CONFIG_INFO << "_ConfigServantObj ProxyObj : " << _ConfigServantObj << endl;
FDLOG_CONFIG_INFO << "_DBAgentServantObj ProxyObj : " << _DBAgentServantObj << endl;
FDLOG_CONFIG_INFO << "_HallServantObj ProxyObj : " << _HallServantObj << endl;
FDLOG_CONFIG_INFO << "_PushServantObj ProxyObj : " << _PushServantObj << endl;
}
void OuterFactoryImp::readListAllRoomAddress()
{
getConfigServantPrx()->listAllRoomAddress(_mapRoomServerFromRemote);
ROLLLOG_DEBUG << "readListAllRoomAddress _mapRoomServerFromRemote:" << _mapRoomServerFromRemote.size() << endl;
return ;
}
//游戏配置服务代理
const ConfigServantPrx OuterFactoryImp::getConfigServantPrx()
{
if (!_ConfigServerPrx)
{
_ConfigServerPrx = Application::getCommunicator()->stringToProxy<ConfigServantPrx>(_ConfigServantObj);
ROLLLOG_DEBUG << "Init _ConfigServantObj succ, _ConfigServantObj : " << _ConfigServantObj << endl;
}
return _ConfigServerPrx;
}
//数据库代理服务代理
const DBAgentServantPrx OuterFactoryImp::getDBAgentServantPrx(const long uid)
{
if (!_DBAgentServerPrx)
{
_DBAgentServerPrx = Application::getCommunicator()->stringToProxy<dbagent::DBAgentServantPrx>(_DBAgentServantObj);
ROLLLOG_DEBUG << "Init _DBAgentServantObj succ, _DBAgentServantObj : " << _DBAgentServantObj << endl;
}
if (_DBAgentServerPrx)
{
return _DBAgentServerPrx->tars_hash(uid);
}
return NULL;
}
//数据库代理服务代理
const DBAgentServantPrx OuterFactoryImp::getDBAgentServantPrx(const string key)
{
if (!_DBAgentServerPrx)
{
_DBAgentServerPrx = Application::getCommunicator()->stringToProxy<dbagent::DBAgentServantPrx>(_DBAgentServantObj);
ROLLLOG_DEBUG << "Init _DBAgentServantObj succ, _DBAgentServantObj : " << _DBAgentServantObj << endl;
}
if (_DBAgentServerPrx)
{
return _DBAgentServerPrx->tars_hash(tars::hash<string>()(key));
}
return NULL;
}
//
const hall::HallServantPrx OuterFactoryImp::getHallServantPrx(const int64_t uid)
{
if (!_HallServerPrx)
{
_HallServerPrx = Application::getCommunicator()->stringToProxy<hall::HallServantPrx>(_HallServantObj);
ROLLLOG_DEBUG << "Init _HallServantObj succ, _HallServantObj:" << _HallServantObj << endl;
}
if (_HallServerPrx)
{
return _HallServerPrx->tars_hash(uid);
}
return NULL;
}
//PushServer代理
const PushServantPrx OuterFactoryImp::getPushServantPrx(const long uid)
{
if (!_PushServerPrx)
{
_PushServerPrx = Application::getCommunicator()->stringToProxy<push::PushServantPrx>(_PushServantObj);
ROLLLOG_DEBUG << "Init _PushServantObj succ, _PushServantObj:" << _PushServantObj << endl;
}
if (_PushServerPrx)
{
return _PushServerPrx->tars_hash(uid);
}
return NULL;
}
//RoomServant代理
const RoomServantPrx OuterFactoryImp::getRoomServantPrx(const long uid, const string &sRoomID)
{
auto itAddress = _mapRoomServerFromRemote.find(sRoomID);
if (itAddress == _mapRoomServerFromRemote.end())
{
ROLLLOG_ERROR << "_mapRoomServerFromRemote size: " << _mapRoomServerFromRemote.size() << ", sRoomID: "<< sRoomID << endl;
return NULL;
}
auto RoomServerPrx = Application::getCommunicator()->stringToProxy<JFGame::RoomServantPrx>(itAddress->second);
return RoomServerPrx->tars_hash(uid);
}
//格式化时间
string OuterFactoryImp::GetTimeFormat()
{
string sFormat("%Y-%m-%d %H:%M:%S");
time_t t = TNOW;
auto pTm = localtime(&t);
if (pTm == NULL)
return "";
char sTimeString[255] = "\0";
strftime(sTimeString, sizeof(sTimeString), sFormat.c_str(), pTm);
return string(sTimeString);
}