FrameworkServer.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. #include "FrameworkServer.h"
  2. #include "framework/ConfigImp.h"
  3. #include "framework/QueryImp.h"
  4. #include "framework/StatImp.h"
  5. #include "framework/LogImp.h"
  6. #include "HttpImp.h"
  7. #include "HelloImp.h"
  8. using namespace std;
  9. vector<map<tars::StatMicMsgHead, tars::StatMicMsgBody>> _clientStatData;
  10. vector<map<tars::StatMicMsgHead, tars::StatMicMsgBody>> _serverStatData;
  11. FrameworkServer::~FrameworkServer()
  12. {
  13. }
  14. void
  15. FrameworkServer::initialize()
  16. {
  17. addServant<ConfigImp>(ServerConfig::Application + "." + ServerConfig::ServerName + ".ConfigObj");
  18. addServant<QueryImp>(ServerConfig::Application + "." + ServerConfig::ServerName + ".QueryObj");
  19. addServant<StatImp>(ServerConfig::Application + "." + ServerConfig::ServerName + ".StatObj");
  20. addServant<LogImp>(ServerConfig::Application + "." + ServerConfig::ServerName + ".LogObj");
  21. string s;
  22. loadLogFormat("","",s);
  23. //日志路径
  24. g_globe._log_path = _conf["/tars/log<logpath>"];
  25. //启动写线程
  26. g_globe._group.start(TC_Common::strto<size_t>(_conf["/tars/log<logthread>"]));
  27. string prefix = TC_Common::lower(_conf.get("/tars/log<ipfix>","true"));
  28. g_globe._bIpPrefix = (prefix == "true") ? true : false;
  29. //增加对象
  30. addServant<LogImp>(ServerConfig::Application + "." + ServerConfig::ServerName +".LogObj");
  31. TARS_ADD_ADMIN_CMD_NORMAL("reloadLogFormat", FrameworkServer::loadLogFormat);
  32. }
  33. bool FrameworkServer::loadLogFormat(const string& command, const string& params, string& result)
  34. {
  35. TLOGDEBUG("FrameworkServer::loadLogFormat command:" << command << "|params:" << params << endl);
  36. try
  37. {
  38. TC_Config conf;
  39. conf.parseFile(ServerConfig::ConfigFile);
  40. vector<string> vHourlist;
  41. map<string,string> mLogType;
  42. try
  43. {
  44. string sHour = conf["/tars/log/format<hour>"];
  45. vHourlist = TC_Common::sepstr<string>(sHour,"|;,");
  46. sort(vHourlist.begin(),vHourlist.end());
  47. unique(vHourlist.begin(),vHourlist.end());
  48. result = "loadLogFormat succ:" + sHour;
  49. TLOGDEBUG("FrameworkServer::loadLogFormat result:" << result << endl);
  50. DLOG<< "FrameworkServer::loadLogFormat result:" << result << endl;
  51. //hour=app.server.file|app2.server2.file2
  52. map<string,string> mType;
  53. if(conf.getDomainMap("/tars/log/logtype", mType))
  54. {
  55. map<string,string>::iterator it = mType.begin();
  56. while(it != mType.end())
  57. {
  58. vector<string> vList = TC_Common::sepstr<string>(it->second,"|;,");
  59. for(size_t i = 0;i < vList.size();i++)
  60. {
  61. //app.server.file = hour
  62. mLogType[vList[i]] = it->first;
  63. TLOGDEBUG("FrameworkServer::loadLogFormat " << vList[i] << "|" << it->first << endl);
  64. DLOG<<"FrameworkServer::loadLogFormat " << vList[i] << "|" << it->first << endl;
  65. }
  66. it++;
  67. }
  68. }
  69. g_globe.update(vHourlist, mLogType);
  70. }
  71. catch(exception& e)
  72. {
  73. result += e.what();
  74. TLOGERROR("FrameworkServer::loadLogFormat command:" << command << "|params:" << params << "|result:" << result << endl);
  75. }
  76. return true;
  77. }
  78. catch(exception &e)
  79. {
  80. result += e.what();
  81. TLOGERROR("FrameworkServer::loadLogFormat command:" << command << "|params:" << params << "|result:" << result << endl);
  82. }
  83. return false;
  84. }
  85. void FrameworkServer::destroyApp()
  86. {
  87. }
  88. void FrameworkServer::run()
  89. {
  90. this->waitForShutdown();
  91. }
  92. /////////////////////////////////////////////////////////////////
  93. RpcServer::~RpcServer()
  94. {
  95. }
  96. void
  97. RpcServer::initialize()
  98. {
  99. addServant<HelloImp>(ServerConfig::Application + "." + ServerConfig::ServerName + ".HelloObj");
  100. addServant<HttpImp>(ServerConfig::Application + "." + ServerConfig::ServerName + ".HttpObj");
  101. addServantProtocol(ServerConfig::Application + "." + ServerConfig::ServerName + ".HttpObj", &TC_NetWorkBuffer::parseHttp);
  102. }
  103. /////////////////////////////////////////////////////////////////
  104. void RpcServer::destroyApp()
  105. {
  106. }
  107. void RpcServer::run()
  108. {
  109. this->waitForShutdown();
  110. }