-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGlobalServer.cpp
More file actions
128 lines (111 loc) · 2.91 KB
/
GlobalServer.cpp
File metadata and controls
128 lines (111 loc) · 2.91 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
#include "GlobalServer.h"
#include "GlobalServantImp.h"
#include "LogComm.h"
//
using namespace std;
//
GlobalServer g_app;
/////////////////////////////////////////////////////////////////
void GlobalServer::initialize()
{
//注册服务接口
addServant<GlobalServantImp>(ServerConfig::Application + "." + ServerConfig::ServerName + ".GlobalServantObj");
//初始化外部接口对象
initOuterFactory();
//注册动态加载命令
TARS_ADD_ADMIN_CMD_NORMAL("reload", GlobalServer::reloadSvrConfig);
//加载DB配置
TARS_ADD_ADMIN_CMD_NORMAL("reloaddb", GlobalServer::reloadDBConfig);
}
/////////////////////////////////////////////////////////////////
void GlobalServer::destroyApp()
{
//destroy application here:
//...
}
/*
* 配置变更,重新加载配置
*/
bool GlobalServer::reloadSvrConfig(const string &command, const string ¶ms, string &result)
{
try
{
getOuterFactoryPtr()->readAllConfig();
result = "reload server config success.";
LOG_DEBUG << "reloadSvrConfig: " << result << endl;
return true;
}
catch (TC_Exception const &e)
{
result = string("catch tc exception: ") + e.what();
}
catch (std::exception const &e)
{
result = string("catch std exception: ") + e.what();
}
catch (...)
{
result = "catch unknown exception.";
}
result += "\n fail, please check it.";
LOG_DEBUG << "reloadSvrConfig: " << result << endl;
return true;
}
/**
* 加载DB配置数据
*/
bool GlobalServer::reloadDBConfig(const string &command, const string ¶ms, string &result)
{
try
{
loadDBConfig();
result = "reload db config success.";
LOG_DEBUG << "reloadDBConfig: " << result << endl;
return true;
}
catch (TC_Exception const &e)
{
result = string("catch tc exception: ") + e.what();
}
catch (std::exception const &e)
{
result = string("catch std exception: ") + e.what();
}
catch (...)
{
result = "catch unknown exception.";
}
result += "\n fail, please check it.";
LOG_DEBUG << "reloadDBConfig: " << result << endl;
return true;
}
/**
* 初始化外部接口对象
**/
int GlobalServer::initOuterFactory()
{
_pOuter = new OuterFactoryImp();
return 0;
}
void GlobalServer::loadDBConfig()
{
}
/////////////////////////////////////////////////////////////////
int main(int argc, char *argv[])
{
try
{
g_app.main(argc, argv);
g_app.waitForShutdown();
}
catch (std::exception &e)
{
cerr << "std::exception : " << e.what() << std::endl;
}
catch (...)
{
cerr << "unknown exception." << std::endl;
}
return -1;
}
/////////////////////////////////////////////////////////////////