-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathActivityServer.cpp
105 lines (91 loc) · 2.46 KB
/
ActivityServer.cpp
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
#include "ActivityServer.h"
#include "ActivityServantImp.h"
using namespace std;
ActivityServer g_app;
/////////////////////////////////////////////////////////////////
void
ActivityServer::initialize()
{
//initialize application here:
//...
addServant<ActivityServantImp>(ServerConfig::Application + "." + ServerConfig::ServerName + ".ActivityServantObj");
initOuterFactory();
initDBOperator();
// 注册动态加载命令
TARS_ADD_ADMIN_CMD_NORMAL("reload", ActivityServer::reloadSvrConfig);
}
/////////////////////////////////////////////////////////////////
void
ActivityServer::destroyApp()
{
//destroy application here:
//...
}
/*
* 配置变更,重新加载配置
*/
bool ActivityServer::reloadSvrConfig(const string &command, const string ¶ms, string &result)
{
try
{
//加载配置
getOuterFactoryPtr()->load();
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操作对象
*/
void ActivityServer::initDBOperator()
{
const DBConf &dbConf = getOuterFactoryPtr()->getDBConfig();
int iRet = DBOperatorSingleton::getInstance()->init(dbConf.Host, dbConf.user, dbConf.password, dbConf.dbname, dbConf.charset, dbConf.port);
if (iRet != 0)
{
ROLLLOG_ERROR << "Init DBOperator failed, exit server." << endl;
//terminate();
return;
}
}
int ActivityServer::initOuterFactory()
{
_pOuter = new OuterFactoryImp();
return 0;
}
/////////////////////////////////////////////////////////////////
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;
}
/////////////////////////////////////////////////////////////////