Pārlūkot izejas kodu

feat: Application::ApplicationConfig to replace ServerConfig
feat: move ClientConfig to Communicator, field remove static
feat: AppCache no longer uses a single instance
feat: Each application has an independent communicator, which no longer shares the global communicator. In order to better support multiple applications in one process

ruanshudong 1 gadu atpakaļ
vecāks
revīzija
b1f718c5b2

+ 7 - 7
examples/PushCallbackDemo/Server/Hello.h

@@ -85,7 +85,7 @@ namespace TestApp
                         {
                             _trace_param_ = "{\"trace_param_over_max_len\":true}";
                         }
-                        TARS_TRACE(_pSptd_->getTraceKey(ServantProxyThreadData::TraceContext::EST_CR), TRACE_ANNOTATION_CR, "", ServerConfig::Application + "." + ServerConfig::ServerName, "registerPush", 0, _trace_param_, "");
+                        TARS_TRACE(_pSptd_->getTraceKey(ServantProxyThreadData::TraceContext::EST_CR), TRACE_ANNOTATION_CR, "", _msg_->moduleName(), "registerPush", 0, _trace_param_, "");
                     }
 
                     CallbackThreadData * pCbtd = CallbackThreadData::getData();
@@ -290,7 +290,7 @@ namespace TestApp
                 {
                     _trace_param_ = "{\"trace_param_over_max_len\":true}";
                 }
-                TARS_TRACE(_pSptd_->getTraceKey(ServantProxyThreadData::TraceContext::EST_CS), TRACE_ANNOTATION_CS, ServerConfig::Application + "." + ServerConfig::ServerName, tars_name(), "registerPush", 0, _trace_param_, "");
+                TARS_TRACE(_pSptd_->getTraceKey(ServantProxyThreadData::TraceContext::EST_CS), TRACE_ANNOTATION_CS, this->tars_communicator()->clientConfig().ModuleName, tars_name(), "registerPush", 0, _trace_param_, "");
             }
 
             std::map<string, string> _mStatus;
@@ -318,7 +318,7 @@ namespace TestApp
                 {
                     _trace_param_ = "{\"trace_param_over_max_len\":true}";
                 }
-                TARS_TRACE(_pSptd_->getTraceKey(ServantProxyThreadData::TraceContext::EST_CR), TRACE_ANNOTATION_CR, ServerConfig::Application + "." + ServerConfig::ServerName, tars_name(), "registerPush", 0, _trace_param_, "");
+                TARS_TRACE(_pSptd_->getTraceKey(ServantProxyThreadData::TraceContext::EST_CR), TRACE_ANNOTATION_CR, this->tars_communicator()->clientConfig().ModuleName, tars_name(), "registerPush", 0, _trace_param_, "");
             }
 
             return _ret;
@@ -343,7 +343,7 @@ namespace TestApp
                 {
                     _trace_param_ = "{\"trace_param_over_max_len\":true}";
                 }
-                TARS_TRACE(_pSptd_->getTraceKey(ServantProxyThreadData::TraceContext::EST_CS), TRACE_ANNOTATION_CS, ServerConfig::Application + "." + ServerConfig::ServerName, tars_name(), "registerPush", 0, _trace_param_, "");
+                TARS_TRACE(_pSptd_->getTraceKey(ServantProxyThreadData::TraceContext::EST_CS), TRACE_ANNOTATION_CS, this->tars_communicator()->clientConfig().ModuleName, tars_name(), "registerPush", 0, _trace_param_, "");
             }
             tars_invoke_async(tars::TARSNORMAL,"registerPush", _os, context, _mStatus, callback);
         }
@@ -443,7 +443,7 @@ namespace TestApp
                 {
                     _trace_param_ = "{\"trace_param_over_max_len\":true}";
                 }
-                TARS_TRACE(_current_->getTraceKey(), TRACE_ANNOTATION_SS, "", ServerConfig::Application + "." + ServerConfig::ServerName, "registerPush", 0, _trace_param_, "");
+                TARS_TRACE(_current_->getTraceKey(), TRACE_ANNOTATION_SS, "", _current_->getServantHandle()->getApplication()->getThisCommunicator()->clientConfig().ModuleName, "registerPush", 0, _trace_param_, "");
             }
 
         }
@@ -500,7 +500,7 @@ namespace TestApp
                         {
                             _trace_param_ = "{\"trace_param_over_max_len\":true}";
                         }
-                        TARS_TRACE(_pSptd_->getTraceKey(ServantProxyThreadData::TraceContext::EST_SR), TRACE_ANNOTATION_SR, "", ServerConfig::Application + "." + ServerConfig::ServerName, "registerPush", 0, _trace_param_, "");
+                        TARS_TRACE(_pSptd_->getTraceKey(ServantProxyThreadData::TraceContext::EST_SR), TRACE_ANNOTATION_SR, "", _current->moduleName(), "registerPush", 0, _trace_param_, "");
                     }
 
                     tars::Int32 _ret = registerPush(_current);
@@ -540,7 +540,7 @@ namespace TestApp
                             {
                                 _trace_param_ = "{\"trace_param_over_max_len\":true}";
                             }
-                            TARS_TRACE(_pSptd_->getTraceKey(ServantProxyThreadData::TraceContext::EST_SS), TRACE_ANNOTATION_SS, "", ServerConfig::Application + "." + ServerConfig::ServerName, "registerPush", 0, _trace_param_, "");
+                            TARS_TRACE(_pSptd_->getTraceKey(ServantProxyThreadData::TraceContext::EST_SS), TRACE_ANNOTATION_SS, "", _current->moduleName(), "registerPush", 0, _trace_param_, "");
                         }
 
                     }

+ 7 - 7
examples/PushCallbackDemo/Server/Push.h

@@ -88,7 +88,7 @@ namespace TestApp
                         {
                             _trace_param_ = "{\"trace_param_over_max_len\":true}";
                         }
-                        TARS_TRACE(_pSptd_->getTraceKey(ServantProxyThreadData::TraceContext::EST_CR), TRACE_ANNOTATION_CR, "", ServerConfig::Application + "." + ServerConfig::ServerName, "pushMsg", 0, _trace_param_, "");
+                        TARS_TRACE(_pSptd_->getTraceKey(ServantProxyThreadData::TraceContext::EST_CR), TRACE_ANNOTATION_CR, "", _msg_->moduleName(), "pushMsg", 0, _trace_param_, "");
                     }
 
                     CallbackThreadData * pCbtd = CallbackThreadData::getData();
@@ -298,7 +298,7 @@ namespace TestApp
                 {
                     _trace_param_ = "{\"trace_param_over_max_len\":true}";
                 }
-                TARS_TRACE(_pSptd_->getTraceKey(ServantProxyThreadData::TraceContext::EST_CS), TRACE_ANNOTATION_CS, ServerConfig::Application + "." + ServerConfig::ServerName, tars_name(), "pushMsg", 0, _trace_param_, "");
+                TARS_TRACE(_pSptd_->getTraceKey(ServantProxyThreadData::TraceContext::EST_CS), TRACE_ANNOTATION_CS, this->tars_communicator()->clientConfig().ModuleName, tars_name(), "pushMsg", 0, _trace_param_, "");
             }
 
             std::map<string, string> _mStatus;
@@ -328,7 +328,7 @@ namespace TestApp
                 {
                     _trace_param_ = "{\"trace_param_over_max_len\":true}";
                 }
-                TARS_TRACE(_pSptd_->getTraceKey(ServantProxyThreadData::TraceContext::EST_CR), TRACE_ANNOTATION_CR, ServerConfig::Application + "." + ServerConfig::ServerName, tars_name(), "pushMsg", 0, _trace_param_, "");
+                TARS_TRACE(_pSptd_->getTraceKey(ServantProxyThreadData::TraceContext::EST_CR), TRACE_ANNOTATION_CR, this->tars_communicator()->clientConfig().ModuleName, tars_name(), "pushMsg", 0, _trace_param_, "");
             }
 
             return _ret;
@@ -353,7 +353,7 @@ namespace TestApp
                 {
                     _trace_param_ = "{\"trace_param_over_max_len\":true}";
                 }
-                TARS_TRACE(_pSptd_->getTraceKey(ServantProxyThreadData::TraceContext::EST_CS), TRACE_ANNOTATION_CS, ServerConfig::Application + "." + ServerConfig::ServerName, tars_name(), "pushMsg", 0, _trace_param_, "");
+                TARS_TRACE(_pSptd_->getTraceKey(ServantProxyThreadData::TraceContext::EST_CS), TRACE_ANNOTATION_CS, this->tars_communicator()->clientConfig().ModuleName, tars_name(), "pushMsg", 0, _trace_param_, "");
             }
             tars_invoke_async(tars::TARSNORMAL,"pushMsg", _os, context, _mStatus, callback);
         }
@@ -458,7 +458,7 @@ namespace TestApp
                 {
                     _trace_param_ = "{\"trace_param_over_max_len\":true}";
                 }
-                TARS_TRACE(_current_->getTraceKey(), TRACE_ANNOTATION_SS, "", ServerConfig::Application + "." + ServerConfig::ServerName, "pushMsg", 0, _trace_param_, "");
+                TARS_TRACE(_current_->getTraceKey(), TRACE_ANNOTATION_SS, "", _current_->getServantHandle()->getApplication()->getThisCommunicator()->clientConfig().ModuleName, "pushMsg", 0, _trace_param_, "");
             }
 
         }
@@ -521,7 +521,7 @@ namespace TestApp
                         {
                             _trace_param_ = "{\"trace_param_over_max_len\":true}";
                         }
-                        TARS_TRACE(_pSptd_->getTraceKey(ServantProxyThreadData::TraceContext::EST_SR), TRACE_ANNOTATION_SR, "", ServerConfig::Application + "." + ServerConfig::ServerName, "pushMsg", 0, _trace_param_, "");
+                        TARS_TRACE(_pSptd_->getTraceKey(ServantProxyThreadData::TraceContext::EST_SR), TRACE_ANNOTATION_SR, "", _current->moduleName(), "pushMsg", 0, _trace_param_, "");
                     }
 
                     tars::Int32 _ret = pushMsg(sRsp, _current);
@@ -565,7 +565,7 @@ namespace TestApp
                             {
                                 _trace_param_ = "{\"trace_param_over_max_len\":true}";
                             }
-                            TARS_TRACE(_pSptd_->getTraceKey(ServantProxyThreadData::TraceContext::EST_SS), TRACE_ANNOTATION_SS, "", ServerConfig::Application + "." + ServerConfig::ServerName, "pushMsg", 0, _trace_param_, "");
+                            TARS_TRACE(_pSptd_->getTraceKey(ServantProxyThreadData::TraceContext::EST_SS), TRACE_ANNOTATION_SS, "", _current->moduleName(), "pushMsg", 0, _trace_param_, "");
                         }
 
                     }

+ 4 - 3
servant/libservant/AdapterProxy.cpp

@@ -269,13 +269,14 @@ TC_NetWorkBuffer::PACKET_TYPE AdapterProxy::onVerifyAuthCallback(TC_NetWorkBuffe
 void AdapterProxy::initStatHead()
 {
 	vector <string> vtSetInfo;
-	if(!ClientConfig::SetDivision.empty() && StatReport::divison2SetInfo(ClientConfig::SetDivision, vtSetInfo)) 	{
+	auto clientConfig = this->_communicator->clientConfig();
+	if(!clientConfig.SetDivision.empty() && StatReport::divison2SetInfo(clientConfig.SetDivision, vtSetInfo)) 	{
 		//主调(client)启用set
-		_statHead.masterName = StatReport::trimAndLimitStr(ClientConfig::ModuleName + "." + vtSetInfo[0] + vtSetInfo[1] + vtSetInfo[2] + "@" + ClientConfig::TarsVersion, StatReport::MAX_MASTER_NAME_LEN);
+		_statHead.masterName = StatReport::trimAndLimitStr(clientConfig.ModuleName + "." + vtSetInfo[0] + vtSetInfo[1] + vtSetInfo[2] + "@" + clientConfig.TarsVersion, StatReport::MAX_MASTER_NAME_LEN);
 	}
 	else
 	{
-		_statHead.masterName = StatReport::trimAndLimitStr(ClientConfig::ModuleName + "@" + ClientConfig::TarsVersion, StatReport::MAX_MASTER_NAME_LEN);
+		_statHead.masterName = StatReport::trimAndLimitStr(clientConfig.ModuleName + "@" + clientConfig.TarsVersion, StatReport::MAX_MASTER_NAME_LEN);
 	}
 
     string sSlaveSet = _ep.setDivision();

+ 2 - 1
servant/libservant/AppCache.cpp

@@ -51,6 +51,7 @@ void AppCache::setCacheInfo(const string &sFile,int32_t iSynInterval)
     }
     catch(exception &e)
     {
+		TC_File::removeFile(_file, false);
         TLOGERROR("[TARS][AppCache setCacheInfo ex:" << e.what() << "]" << endl);
     }
 }
@@ -115,7 +116,7 @@ int AppCache::set(const string &sName,const string &sValue,const string sDomain)
         if(_lastSynTime == 0)   //第一次写数据 打印tarsversion
         {
             m.clear();
-            m["tarsversion"] = ClientConfig::TarsVersion;
+            m["tarsversion"] = _communicator->clientConfig().TarsVersion;
             tConf.insertDomainParam(string(APPCACHE_ROOT_PATH),m,true);
         }
 

+ 271 - 178
servant/libservant/Application.cpp

@@ -89,9 +89,17 @@ std::string ServerConfig::Ciphers;
 
 map<string, string> ServerConfig::Context;
 
+#define SYNC_SERVER_CONFIG(x, y) \
+if(_serverConfig.x != serverConfig.x) \
+{	\
+ServerConfig::y = _serverConfig.x; 	\
+}	\
+if(ServerConfig::y != serverConfig.x) \
+{	\
+_serverConfig.x = ServerConfig::y;	\
+}
+
 ///////////////////////////////////////////////////////////////////////////////////////////
-//TC_Config                       Application::_conf;
-//TC_EpollServerPtr               Application::_epollServer  = NULL;
 CommunicatorPtr                 Application::_communicator = NULL;
 
 PropertyReportPtr g_pReportRspQueue;
@@ -116,13 +124,51 @@ Application::Application()
 
 Application::~Application()
 {
-	if(_epollServer)
+	if (_epollServer)
 	{
 		_epollServer->terminate();
 		_epollServer = NULL;
 	}
 #if TARGET_PLATFORM_WINDOWS
-    WSACleanup();
+	WSACleanup();
+#endif
+}
+
+void Application::ApplicationConfig::copyToStatic()
+{
+	ServerConfig::TarsPath = tarsPath;
+	ServerConfig::Application  = application;
+	ServerConfig::ServerName = serverName;
+	ServerConfig::LocalIp = localIp;
+	ServerConfig::BasePath = basePath;
+	ServerConfig::DataPath = dataPath;
+	ServerConfig::Local = local;
+	ServerConfig::Node = node;
+	ServerConfig::Log = log;
+	ServerConfig::Config = config;
+	ServerConfig::Notify = notify;
+	ServerConfig::LogPath = logPath;
+	ServerConfig::LogSize = logSize;
+	ServerConfig::LogNum = logNum;
+	ServerConfig::LogLevel = logLevel;
+	ServerConfig::ConfigFile = configFile;
+	ServerConfig::ReportFlow = reportFlow;
+	ServerConfig::IsCheckSet = isCheckSet;
+	ServerConfig::OpenCoroutine = openCoroutine;
+	ServerConfig::CoroutineMemSize = coroutineMemSize;
+	ServerConfig::CoroutineStackSize = coroutineStackSize;
+	ServerConfig::ManualListen = manualListen;
+	ServerConfig::NetThread = netThread;
+	ServerConfig::CloseCout = closeCout;
+	ServerConfig::BackPacketLimit = backPacketLimit;
+	ServerConfig::BackPacketMin = backPacketMin;
+	ServerConfig::CheckBindAdapter = checkBindAdapter;
+#if TARS_SSL
+	std::string ServerConfig::CA = ca;
+	std::string ServerConfig::Cert = cert;
+	std::string ServerConfig::Key = key;
+	bool ServerConfig::VerifyClient = verifyClient;
+	std::string ServerConfig::Ciphers = ciphers;
 #endif
 }
 
@@ -136,6 +182,11 @@ CommunicatorPtr& Application::getCommunicator()
     return _communicator;
 }
 
+CommunicatorPtr Application::getThisCommunicator()
+{
+	return _thisCommunicator;
+}
+
 void reportRspQueue(TC_EpollServer *epollServer)
 {
     if (!g_pReportRspQueue)
@@ -258,7 +309,7 @@ bool Application::cmdCloseCoreDump(const string& command, const string& params,
 
     TLOGDEBUG("before :cur:" << tlimit.rlim_cur << ";max: " << tlimit.rlim_max << endl);
 
-    os << (ServerConfig::Application + "." + ServerConfig::ServerName);
+    os << (_serverConfig.application + "." + _serverConfig.serverName);
 
     os << "|before set:cur:" << tlimit.rlim_cur << ";max: " << tlimit.rlim_max;
 
@@ -309,11 +360,13 @@ bool Application::cmdSetLogLevel(const string& command, const string& params, st
 
     if (ret == 0)
     {
-        ServerConfig::LogLevel = TC_Common::upper(level);
+		_serverConfig.logLevel = TC_Common::upper(level);
+
+		ServerConfig::LogLevel = _serverConfig.logLevel;
 
         result = "set log level [" + level + "] ok";
 
-        AppCache::getInstance()->set("logLevel", level);
+		_thisCommunicator->getAppCache()->set("logLevel", level);
     }
     else
     {
@@ -372,7 +425,6 @@ bool Application::cmdEnableDayLog(const string& command, const string& params, s
         result = "set " + vParams[0] + " " + vParams[1] + " " + vParams[2] + " ok";
     }
 
-
     if (vParams[0] == "local")
     {
         RemoteTimeLogger::getInstance()->enableLocal(sFile, bEnable);
@@ -479,7 +531,7 @@ bool Application::cmdViewBuildID(const string& command, const string& params, st
 
     char buildTime[50] = {0};
     sprintf(buildTime, "%d.%02d%02d.%06d", YEARSUF, MONTH + 1, DAY, TIMEINT);
-    result = "$" + ServerConfig::Application + "." + ServerConfig::ServerName + "-" + string(buildTime) + "$";
+    result = "$" + _serverConfig.application + "." + _serverConfig.serverName + "-" + string(buildTime) + "$";
     return true;
 }
 
@@ -490,36 +542,39 @@ bool Application::cmdLoadProperty(const string& command, const string& params, s
         TLOGTARS("Application::cmdLoadProperty:" << command << " " << params << endl);
 
         //重新解析配置文件
-        _conf.parseFile(ServerConfig::ConfigFile);
+        _conf.parseFile(_serverConfig.configFile);
 
         string sResult = "";
 
         //加载通讯器属性
-        _communicator->setProperty(_conf);
+        _thisCommunicator->setProperty(_conf);
 
-        _communicator->reloadProperty(sResult);
+        _thisCommunicator->reloadProperty(sResult);
 
         //加载远程对象
-        ServerConfig::Log = _conf.get("/tars/application/server<log>");
+		_serverConfig.log = _conf.get("/tars/application/server<log>");
+		ServerConfig::Log = _serverConfig.log;
 
-        RemoteTimeLogger::getInstance()->setLogInfo(_communicator, ServerConfig::Log, ServerConfig::Application, ServerConfig::ServerName, ServerConfig::LogPath,setDivision());
+        RemoteTimeLogger::getInstance()->setLogInfo(_thisCommunicator, _serverConfig.log, _serverConfig.application, _serverConfig.serverName, _serverConfig.logPath,setDivision());
 
-        ServerConfig::Config = _conf.get("/tars/application/server<config>");
+        _serverConfig.config = _conf.get("/tars/application/server<config>");
+		ServerConfig::Config = _serverConfig.config;
 
-        RemoteConfig::getInstance()->setConfigInfo(_communicator, ServerConfig::Config, ServerConfig::Application, ServerConfig::ServerName, ServerConfig::BasePath,setDivision(), 5);
+        RemoteConfig::getInstance()->setConfigInfo(_thisCommunicator, _serverConfig.config, _serverConfig.application, _serverConfig.serverName, _serverConfig.basePath,setDivision(), 5);
 
-        ServerConfig::Notify = _conf.get("/tars/application/server<notify>");
+        _serverConfig.notify = _conf.get("/tars/application/server<notify>");
+		ServerConfig::Notify = _serverConfig.notify;
 
-        RemoteNotify::getInstance()->setNotifyInfo(_communicator, ServerConfig::Notify, ServerConfig::Application, ServerConfig::ServerName, setDivision(), ServerConfig::LocalIp);
+        RemoteNotify::getInstance()->setNotifyInfo(_thisCommunicator, _serverConfig.notify, _serverConfig.application, _serverConfig.serverName, setDivision(), _serverConfig.localIp);
 
         result = "loaded config items:\r\n" + sResult +
-                 "log=" + ServerConfig::Log + "\r\n" +
-                 "config=" + ServerConfig::Config + "\r\n" +
-                 "notify=" + ServerConfig::Notify + "\r\n";
+                 "log=" + _serverConfig.log + "\r\n" +
+                 "config=" + _serverConfig.config + "\r\n" +
+                 "notify=" + _serverConfig.notify + "\r\n";
     }
     catch (TC_Config_Exception & ex)
     {
-        result = "load config " + ServerConfig::ConfigFile + " error:" + ex.what();
+        result = "load config " + _serverConfig.configFile + " error:" + ex.what();
     }
     catch (exception &ex)
     {
@@ -564,11 +619,11 @@ bool Application::cmdCloseCout(const string& command, const string& params, stri
 
     if (s == "yes")
     {
-        AppCache::getInstance()->set("closeCout", "1");
+        _thisCommunicator->getAppCache()->set("closeCout", "1");
     }
     else
     {
-        AppCache::getInstance()->set("closeCout", "0");
+		_thisCommunicator->getAppCache()->set("closeCout", "0");
     }
 
     result = "set closeCout  [" + s + "] ok";
@@ -585,14 +640,14 @@ bool Application::cmdReloadLocator(const string& command, const string& params,
     bool bSucc(true);
     if (sPara == "reload")
     {
-    	TLOGDEBUG(__FUNCTION__ << "|" << __LINE__ << "|conf file:" << ServerConfig::ConfigFile << endl);
+    	TLOGDEBUG(__FUNCTION__ << "|" << __LINE__ << "|conf file:" << _serverConfig.configFile << endl);
 
         TC_Config reloadConf;
 
-        reloadConf.parseFile(ServerConfig::ConfigFile);
+        reloadConf.parseFile(_serverConfig.configFile);
         string sLocator = reloadConf.get("/tars/application/client/<locator>", "");
 
-        TLOGDEBUG(__FUNCTION__ << "|" << __LINE__ << "|conf file:" << ServerConfig::ConfigFile << "\n"
+        TLOGDEBUG(__FUNCTION__ << "|" << __LINE__ << "|conf file:" << _serverConfig.configFile << "\n"
             << "|sLocator:" << sLocator << endl);
 
         if (sLocator.empty())
@@ -602,8 +657,8 @@ bool Application::cmdReloadLocator(const string& command, const string& params,
         }
         else
         {
-            _communicator->setProperty("locator", sLocator);
-            _communicator->reloadLocator();
+            _thisCommunicator->setProperty("locator", sLocator);
+            _thisCommunicator->reloadLocator();
             result = sLocator + " set succ.";
         }
 
@@ -623,7 +678,7 @@ bool Application::cmdViewResource(const string& command, const string& params, s
 
 	ostringstream os;
 
-	os << _communicator->getResourcesInfo() << endl;
+	os << _thisCommunicator->getResourcesInfo() << endl;
 
 	os << OUT_LINE << endl;
 
@@ -706,18 +761,18 @@ void Application::main(const TC_Option &option)
 	}
 
 	//加载配置文件
-	ServerConfig::ConfigFile = option.getValue("config");
+	_serverConfig.configFile = option.getValue("config");
 
-	if (ServerConfig::ConfigFile == "")
+	if (_serverConfig.configFile == "")
 	{
 		cerr << "start server with config, for example: exe --config=config.conf" << endl;
 
 		exit(-1);
 	}
 
-	string config = TC_File::load2str(ServerConfig::ConfigFile);
+	string config = TC_File::load2str(_serverConfig.configFile);
 
-	__out__.debug() << "config:" << ServerConfig::ConfigFile << endl;
+	__out__.debug() << "config:" << _serverConfig.configFile << endl;
 	__out__.debug() << "config:" << config << endl;
 
 	main(config);
@@ -870,7 +925,7 @@ void Application::main(const string &config)
 	    });
 
 #if TARGET_PLATFORM_LINUX || TARGET_PLATFORM_IOS
-        if(_conf.get("/tars/application/server<closecout>",AppCache::getInstance()->get("closeCout")) != "0")
+        if(_conf.get("/tars/application/server<closecout>", _thisCommunicator->getAppCache()->get("closeCout")) != "0")
         {
             // 重定向stdin、stdout、stderr
             int fd = open("/dev/null", O_RDWR );
@@ -904,7 +959,6 @@ void Application::main(const string &config)
     LocalRollLogger::getInstance()->sync(false);
 }
 
-
 void Application::parseConfig(const string &config)
 {
     _conf.parseString(config);
@@ -942,8 +996,18 @@ void Application::initializeClient()
 {
 	__out__.info()  << "\n" << OUT_LINE_LONG << endl;
 
-    //初始化通信器
-    _communicator = CommunicatorFactory::getInstance()->getCommunicator(_conf);
+	if(CommunicatorFactory::getInstance()->hasCommunicator())
+	{
+		//已经存在缺省通信器了, 创建新的通信器
+		_thisCommunicator = CommunicatorFactory::getInstance()->getCommunicator(_conf, "application-" + TC_Common::tostr(this));
+	}
+	else
+	{
+		//初始化缺省通信器
+		_communicator = CommunicatorFactory::getInstance()->getCommunicator(_conf);
+
+		_thisCommunicator = _communicator;
+	}
 
 	__out__.info()  << TC_Common::outfill("[proxy config]:") << endl;
 
@@ -958,21 +1022,19 @@ void Application::outClient(ostream &os)
 {
 	os << OUT_LINE << "\n" << TC_Common::outfill("[load client]:") << endl;
 
-    os << TC_Common::outfill("locator")                     << _communicator->getProperty("locator") << endl;
-    os << TC_Common::outfill("sync-invoke-timeout")         << _communicator->getProperty("sync-invoke-timeout") << endl;
-    os << TC_Common::outfill("async-invoke-timeout")        << _communicator->getProperty("async-invoke-timeout") << endl;
-    os << TC_Common::outfill("refresh-endpoint-interval")   << _communicator->getProperty("refresh-endpoint-interval") << endl;
-    os << TC_Common::outfill("stat")                        << _communicator->getProperty("stat") << endl;
-    os << TC_Common::outfill("property")                    << _communicator->getProperty("property") << endl;
-    os << TC_Common::outfill("report-interval")             << _communicator->getProperty("report-interval") << endl;
-    os << TC_Common::outfill("keep-alive-interval")             << _communicator->getProperty("keep-alive-interval") << endl;
-//    os << TC_Common::outfill("sample-rate")                 << _communicator->getProperty("sample-rate") << endl;
-//    os << TC_Common::outfill("max-sample-count")            << _communicator->getProperty("max-sample-count") << endl;
-    os << TC_Common::outfill("netthread")                  << _communicator->getProperty("netthread") << endl;
-    os << TC_Common::outfill("asyncthread")                 << _communicator->getProperty("asyncthread") << endl;
-    os << TC_Common::outfill("modulename")                  << _communicator->getProperty("modulename") << endl;
-    os << TC_Common::outfill("enableset")                     << _communicator->getProperty("enableset") << endl;
-    os << TC_Common::outfill("setdivision")                 << _communicator->getProperty("setdivision") << endl;
+    os << TC_Common::outfill("locator")                     << _thisCommunicator->getProperty("locator") << endl;
+    os << TC_Common::outfill("sync-invoke-timeout")         << _thisCommunicator->getProperty("sync-invoke-timeout") << endl;
+    os << TC_Common::outfill("async-invoke-timeout")        << _thisCommunicator->getProperty("async-invoke-timeout") << endl;
+    os << TC_Common::outfill("refresh-endpoint-interval")   << _thisCommunicator->getProperty("refresh-endpoint-interval") << endl;
+    os << TC_Common::outfill("stat")                        << _thisCommunicator->getProperty("stat") << endl;
+    os << TC_Common::outfill("property")                    << _thisCommunicator->getProperty("property") << endl;
+    os << TC_Common::outfill("report-interval")             << _thisCommunicator->getProperty("report-interval") << endl;
+    os << TC_Common::outfill("keep-alive-interval")         << _thisCommunicator->getProperty("keep-alive-interval") << endl;
+    os << TC_Common::outfill("netthread")                  	<< _thisCommunicator->getProperty("netthread") << endl;
+    os << TC_Common::outfill("asyncthread")                 << _thisCommunicator->getProperty("asyncthread") << endl;
+    os << TC_Common::outfill("modulename")                  << _thisCommunicator->getProperty("modulename") << endl;
+    os << TC_Common::outfill("enableset")                   << _thisCommunicator->getProperty("enableset") << endl;
+    os << TC_Common::outfill("setdivision")                 << _thisCommunicator->getProperty("setdivision") << endl;
 }
 
 string Application::toDefault(const string &s, const string &sDefault)
@@ -1016,61 +1078,86 @@ void Application::onAccept(TC_EpollServer::Connection* cPtr)
     }
 }
 
-//void Application::addServantOnClose(const string& servant, const TC_EpollServer::close_functor& cf)
-//{
-//    string adapterName = _servantHelper->getServantAdapter(servant);
-//
-//    if (adapterName.empty())
-//    {
-//        throw runtime_error("setServantOnClose fail, no found adapter for servant:" + servant);
-//    }
-//
-//    getEpollServer()->getBindAdapter(adapterName)->setOnClose(cf);
-//}
-
 void Application::outServer(ostream &os)
 {
-	os << TC_Common::outfill("Application(app)")            << ServerConfig::Application << endl;
-	os << TC_Common::outfill("ServerName(server)")          << ServerConfig::ServerName << endl;
-	os << TC_Common::outfill("BasePath(basepath)")          << ServerConfig::BasePath << endl;
-	os << TC_Common::outfill("DataPath(datapath)")          << ServerConfig::DataPath << endl;
-	os << TC_Common::outfill("LocalIp(localip)")            << ServerConfig::LocalIp << endl;
-	os << TC_Common::outfill("Local(local)")                << ServerConfig::Local << endl;
-	os << TC_Common::outfill("LogPath(logpath)")            << ServerConfig::LogPath << endl;
-	os << TC_Common::outfill("LogSize(logsize)")            << ServerConfig::LogSize << endl;
-	os << TC_Common::outfill("LogNum(lognum)")              << ServerConfig::LogNum << endl;
-	os << TC_Common::outfill("LogLevel(loglevel)")          << ServerConfig::LogLevel << endl;
-	os << TC_Common::outfill("Log(log)")                    << ServerConfig::Log << endl;
-	os << TC_Common::outfill("Node(node)")                  << ServerConfig::Node << endl;
-	os << TC_Common::outfill("Config(config)")              << ServerConfig::Config << endl;
-	os << TC_Common::outfill("Notify(notify)")              << ServerConfig::Notify << endl;
-	os << TC_Common::outfill("OpenCoroutine(opencoroutine)")      << ServerConfig::OpenCoroutine << endl;
-	os << TC_Common::outfill("CoroutineMemSize(coroutinememsize)")   << ServerConfig::CoroutineMemSize << endl;
-	os << TC_Common::outfill("CoroutineStackSize(coroutinestack)") << ServerConfig::CoroutineStackSize << endl;
-	os << TC_Common::outfill("CloseCout(closecout)")          << ServerConfig::CloseCout << endl;
-	os << TC_Common::outfill("NetThread(netthread)")          << ServerConfig::NetThread << endl;
-	os << TC_Common::outfill("ManualListen(manuallisten)")       << ServerConfig::ManualListen << endl;
-//	os << TC_Common::outfill("MergeNetImp(mergenetimp)")       << ServerConfig::MergeNetImp << endl;
-	os << TC_Common::outfill("ReportFlow(reportflow)")                  << ServerConfig::ReportFlow<< endl;
-	os << TC_Common::outfill("BackPacketLimit(backpacketlimit)")  << ServerConfig::BackPacketLimit<< endl;
-	os << TC_Common::outfill("BackPacketMin(backpacketmin)")  << ServerConfig::BackPacketMin<< endl;
+	os << TC_Common::outfill("Application(app)")            << _serverConfig.application << endl;
+	os << TC_Common::outfill("ServerName(server)")          << _serverConfig.serverName << endl;
+	os << TC_Common::outfill("BasePath(basepath)")          << _serverConfig.basePath << endl;
+	os << TC_Common::outfill("DataPath(datapath)")          << _serverConfig.dataPath << endl;
+	os << TC_Common::outfill("LocalIp(localip)")            << _serverConfig.localIp << endl;
+	os << TC_Common::outfill("Local(local)")                << _serverConfig.local << endl;
+	os << TC_Common::outfill("LogPath(logpath)")            << _serverConfig.logPath << endl;
+	os << TC_Common::outfill("LogSize(logsize)")            << _serverConfig.logSize << endl;
+	os << TC_Common::outfill("LogNum(lognum)")              << _serverConfig.logNum << endl;
+	os << TC_Common::outfill("LogLevel(loglevel)")          << _serverConfig.logLevel << endl;
+	os << TC_Common::outfill("Log(log)")                    << _serverConfig.log << endl;
+	os << TC_Common::outfill("Node(node)")                  << _serverConfig.node << endl;
+	os << TC_Common::outfill("Config(config)")              << _serverConfig.config << endl;
+	os << TC_Common::outfill("Notify(notify)")              << _serverConfig.notify << endl;
+	os << TC_Common::outfill("OpenCoroutine(opencoroutine)")      << _serverConfig.openCoroutine << endl;
+	os << TC_Common::outfill("CoroutineMemSize(coroutinememsize)")   << _serverConfig.coroutineMemSize << endl;
+	os << TC_Common::outfill("CoroutineStackSize(coroutinestack)") << _serverConfig.coroutineStackSize << endl;
+	os << TC_Common::outfill("CloseCout(closecout)")          << _serverConfig.closeCout << endl;
+	os << TC_Common::outfill("NetThread(netthread)")          << _serverConfig.netThread << endl;
+	os << TC_Common::outfill("ManualListen(manuallisten)")       << _serverConfig.manualListen << endl;
+	os << TC_Common::outfill("ReportFlow(reportflow)")                  << _serverConfig.reportFlow<< endl;
+	os << TC_Common::outfill("BackPacketLimit(backpacketlimit)")  << _serverConfig.backPacketLimit<< endl;
+	os << TC_Common::outfill("BackPacketMin(backpacketmin)")  << _serverConfig.backPacketMin<< endl;
 
 #if TARS_SSL
-	os << TC_Common::outfill("Ca(ca)")                    << ServerConfig::CA << endl;
-	os << TC_Common::outfill("Cert(cert)")              << ServerConfig::Cert << endl;
-	os << TC_Common::outfill("Key(key)")                  << ServerConfig::Key << endl;
-	os << TC_Common::outfill("VerifyClient(verifyclient)")      << ServerConfig::VerifyClient << endl;
-	os << TC_Common::outfill("Ciphers(ciphers)")               << ServerConfig::Ciphers << endl;
+	os << TC_Common::outfill("Ca(ca)")                    << _serverConfig.ca << endl;
+	os << TC_Common::outfill("Cert(cert)")              << _serverConfig.cert << endl;
+	os << TC_Common::outfill("Key(key)")                  << _serverConfig.key << endl;
+	os << TC_Common::outfill("VerifyClient(verifyclient)")      << _serverConfig.verifyClient << endl;
+	os << TC_Common::outfill("Ciphers(ciphers)")               << _serverConfig.ciphers << endl;
 #endif
 
 }
 
+void Application::syncServerConfig(const ApplicationConfig &serverConfig)
+{
+	SYNC_SERVER_CONFIG(tarsPath, TarsPath);
+	SYNC_SERVER_CONFIG(application, Application);
+	SYNC_SERVER_CONFIG(serverName, ServerName);
+	SYNC_SERVER_CONFIG(localIp, LocalIp);
+	SYNC_SERVER_CONFIG(basePath, BasePath);
+	SYNC_SERVER_CONFIG(dataPath, DataPath);
+	SYNC_SERVER_CONFIG(local, Local);
+	SYNC_SERVER_CONFIG(node, Node);
+	SYNC_SERVER_CONFIG(log, Log);
+	SYNC_SERVER_CONFIG(config, Config);
+	SYNC_SERVER_CONFIG(notify, Notify);
+	SYNC_SERVER_CONFIG(logPath, LogPath);
+	SYNC_SERVER_CONFIG(logSize, LogSize);
+	SYNC_SERVER_CONFIG(logNum, LogNum);
+	SYNC_SERVER_CONFIG(logLevel, LogLevel);
+	SYNC_SERVER_CONFIG(configFile, ConfigFile);
+	SYNC_SERVER_CONFIG(reportFlow, ReportFlow);
+	SYNC_SERVER_CONFIG(isCheckSet, IsCheckSet);
+	SYNC_SERVER_CONFIG(openCoroutine, OpenCoroutine);
+	SYNC_SERVER_CONFIG(coroutineMemSize, CoroutineMemSize);
+	SYNC_SERVER_CONFIG(coroutineStackSize, CoroutineStackSize);
+	SYNC_SERVER_CONFIG(manualListen, ManualListen);
+	SYNC_SERVER_CONFIG(netThread, NetThread);
+	SYNC_SERVER_CONFIG(closeCout, CloseCout);
+	SYNC_SERVER_CONFIG(backPacketLimit, BackPacketLimit);
+	SYNC_SERVER_CONFIG(backPacketMin, BackPacketMin);
+	SYNC_SERVER_CONFIG(checkBindAdapter, CheckBindAdapter);
+
+#if TARS_SSL
+	SYNC_SERVER_CONFIG(ca, CA);
+	SYNC_SERVER_CONFIG(cert, Cert);
+	SYNC_SERVER_CONFIG(key, Key);
+	SYNC_SERVER_CONFIG(verifyClient, VerifyClient);
+	SYNC_SERVER_CONFIG(ciphers, Ciphers);
+#endif
+}
 
 void Application::initializeServer()
 {
 	__out__.info()  << OUT_LINE << "\n" << TC_Common::outfill("[server config]:") << endl;
 
-    ServerConfig::Application  = toDefault(_conf.get("/tars/application/server<app>"), "UNKNOWN");
+    _serverConfig.application  = toDefault(_conf.get("/tars/application/server<app>"), "UNKNOWN");
 
     //缺省采用进程名称
     string exe = "";
@@ -1085,122 +1172,130 @@ void Application::initializeServer()
         exe = _conf.get("/tars/application/server<localip>");
     }
 
-    ServerConfig::ServerName        = toDefault(_conf.get("/tars/application/server<server>"), exe);
+    _serverConfig.serverName        = toDefault(_conf.get("/tars/application/server<server>"), exe);
 
 
 #if TARGET_PLATFORM_WINDOWS    
-    ServerConfig::BasePath          = TC_File::simplifyDirectory(_conf.get("/tars/application/server<basepath.win>")) + FILE_SEP;
-    if (ServerConfig::BasePath == FILE_SEP)
+    _serverConfig.basePath          = TC_File::simplifyDirectory(_conf.get("/tars/application/server<basepath.win>")) + FILE_SEP;
+    if (_serverConfig.basePath == FILE_SEP)
     {
-        ServerConfig::BasePath          = TC_File::simplifyDirectory(toDefault(_conf.get("/tars/application/server<basepath>"), ".")) + FILE_SEP;
+        _serverConfig.basePath          = TC_File::simplifyDirectory(toDefault(_conf.get("/tars/application/server<basepath>"), ".")) + FILE_SEP;
     }
 
-    ServerConfig::DataPath          = TC_File::simplifyDirectory(_conf.get("/tars/application/server<datapath.win>")) + FILE_SEP;
-    if(ServerConfig::DataPath == FILE_SEP)
+    _serverConfig.dataPath          = TC_File::simplifyDirectory(_conf.get("/tars/application/server<datapath.win>")) + FILE_SEP;
+    if(_serverConfig.dataPath == FILE_SEP)
     {
-        ServerConfig::DataPath          = TC_File::simplifyDirectory(toDefault(_conf.get("/tars/application/server<datapath>"), ".")) + FILE_SEP;
+        _serverConfig.dataPath          = TC_File::simplifyDirectory(toDefault(_conf.get("/tars/application/server<datapath>"), ".")) + FILE_SEP;
     }
 
-    ServerConfig::LogPath           = TC_File::simplifyDirectory(_conf.get("/tars/application/server<logpath.win>")) + FILE_SEP;
-    if(ServerConfig::LogPath == FILE_SEP)
+    _serverConfig.logPath           = TC_File::simplifyDirectory(_conf.get("/tars/application/server<logpath.win>")) + FILE_SEP;
+    if(_serverConfig.logPath == FILE_SEP)
     {
-        ServerConfig::LogPath       = TC_File::simplifyDirectory(toDefault(_conf.get("/tars/application/server<logpath>"),  ".")) + FILE_SEP;
+        _serverConfig.logPath       = TC_File::simplifyDirectory(toDefault(_conf.get("/tars/application/server<logpath>"),  ".")) + FILE_SEP;
     }
 #else
-    ServerConfig::BasePath          = TC_File::simplifyDirectory(toDefault(_conf.get("/tars/application/server<basepath>"), ".")) + FILE_SEP;
-    ServerConfig::DataPath          = TC_File::simplifyDirectory(toDefault(_conf.get("/tars/application/server<datapath>"), ".")) + FILE_SEP;
-    ServerConfig::LogPath           = TC_File::simplifyDirectory(toDefault(_conf.get("/tars/application/server<logpath>"),  ".")) + FILE_SEP;
+    _serverConfig.basePath          = TC_File::simplifyDirectory(toDefault(_conf.get("/tars/application/server<basepath>"), ".")) + FILE_SEP;
+    _serverConfig.dataPath          = TC_File::simplifyDirectory(toDefault(_conf.get("/tars/application/server<datapath>"), ".")) + FILE_SEP;
+    _serverConfig.logPath           = TC_File::simplifyDirectory(toDefault(_conf.get("/tars/application/server<logpath>"),  ".")) + FILE_SEP;
 
 #endif
-    ServerConfig::TarsPath           = TC_File::simplifyDirectory(ServerConfig::LogPath + FILE_SEP + ".." + FILE_SEP) + FILE_SEP;
-    ServerConfig::LogSize           = TC_Common::toSize(toDefault(_conf.get("/tars/application/server<logsize>"), "52428800"), 52428800);
-    ServerConfig::LogNum            = TC_Common::strto<int>(toDefault(_conf.get("/tars/application/server<lognum>"), "10"));
-    ServerConfig::LocalIp           = _conf.get("/tars/application/server<localip>");
-    ServerConfig::Local             = _conf.get("/tars/application/server<local>");
-    ServerConfig::Node              = _conf.get("/tars/application/server<node>");
-    ServerConfig::Log               = _conf.get("/tars/application/server<log>");
-    ServerConfig::Config            = _conf.get("/tars/application/server<config>");
-    ServerConfig::Notify            = _conf.get("/tars/application/server<notify>");
-    ServerConfig::ReportFlow        = _conf.get("/tars/application/server<reportflow>")=="0"?0:1;
-    ServerConfig::IsCheckSet        = _conf.get("/tars/application/server<checkset>","1")=="0"?0:1;
-    ServerConfig::OpenCoroutine     = TC_Common::strto<int>(toDefault(_conf.get("/tars/application/server<opencoroutine>"), "0"));
-    ServerConfig::CoroutineMemSize  =  TC_Common::toSize(toDefault(_conf.get("/tars/application/server<coroutinememsize>"), "1G"), 1024*1024*1024);
-    ServerConfig::CoroutineStackSize= (uint32_t)TC_Common::toSize(toDefault(_conf.get("/tars/application/server<coroutinestack>"), "128K"), 1024*128);
-    ServerConfig::ManualListen      = _conf.get("/tars/application/server<manuallisten>", "0") == "0" ? false : true;
-//	ServerConfig::MergeNetImp       = _conf.get("/tars/application/server<mergenetimp>", "0") == "0" ? false : true;
-	ServerConfig::NetThread         = TC_Common::strto<int>(toDefault(_conf.get("/tars/application/server<netthread>"), "1"));
-	ServerConfig::CloseCout        	= _conf.get("/tars/application/server<closecout>","1")=="0"?0:1;
-	ServerConfig::BackPacketLimit  	= TC_Common::strto<int>(_conf.get("/tars/application/server<backpacketlimit>", TC_Common::tostr(100*1024*1024)));
-	ServerConfig::BackPacketMin    	= TC_Common::strto<int>(_conf.get("/tars/application/server<backpacketmin>", "1024"));
-	ServerConfig::CheckBindAdapter	= _conf.get("/tars/application/server<checkbindadapter>","1")=="0"?false:true;
-
-	ServerConfig::Context["node_name"] = ServerConfig::LocalIp;
+    _serverConfig.tarsPath           = TC_File::simplifyDirectory(_serverConfig.logPath + FILE_SEP + ".." + FILE_SEP) + FILE_SEP;
+    _serverConfig.logSize           = TC_Common::toSize(toDefault(_conf.get("/tars/application/server<logsize>"), "52428800"), 52428800);
+    _serverConfig.logNum            = TC_Common::strto<int>(toDefault(_conf.get("/tars/application/server<lognum>"), "10"));
+    _serverConfig.localIp           = _conf.get("/tars/application/server<localip>");
+    _serverConfig.local             = _conf.get("/tars/application/server<local>");
+    _serverConfig.node              = _conf.get("/tars/application/server<node>");
+    _serverConfig.log               = _conf.get("/tars/application/server<log>");
+    _serverConfig.config            = _conf.get("/tars/application/server<config>");
+    _serverConfig.notify            = _conf.get("/tars/application/server<notify>");
+    _serverConfig.reportFlow        = _conf.get("/tars/application/server<reportflow>")=="0"?0:1;
+    _serverConfig.isCheckSet        = _conf.get("/tars/application/server<checkset>","1")=="0"?0:1;
+    _serverConfig.openCoroutine     = TC_Common::strto<int>(toDefault(_conf.get("/tars/application/server<opencoroutine>"), "0"));
+    _serverConfig.coroutineMemSize  =  TC_Common::toSize(toDefault(_conf.get("/tars/application/server<coroutinememsize>"), "1G"), 1024*1024*1024);
+    _serverConfig.coroutineStackSize= (uint32_t)TC_Common::toSize(toDefault(_conf.get("/tars/application/server<coroutinestack>"), "128K"), 1024*128);
+    _serverConfig.manualListen      = _conf.get("/tars/application/server<manuallisten>", "0") == "0" ? false : true;
+	_serverConfig.netThread         = TC_Common::strto<int>(toDefault(_conf.get("/tars/application/server<netthread>"), "1"));
+	_serverConfig.closeCout        	= _conf.get("/tars/application/server<closecout>","1")=="0"?0:1;
+	_serverConfig.backPacketLimit  	= TC_Common::strto<int>(_conf.get("/tars/application/server<backpacketlimit>", TC_Common::tostr(100*1024*1024)));
+	_serverConfig.backPacketMin    	= TC_Common::strto<int>(_conf.get("/tars/application/server<backpacketmin>", "1024"));
+	_serverConfig.checkBindAdapter	= _conf.get("/tars/application/server<checkbindadapter>","1")=="0"?false:true;
+
 #if TARS_SSL
-	ServerConfig::CA                = _conf.get("/tars/application/server<ca>");
-	ServerConfig::Cert              = _conf.get("/tars/application/server<cert>");
-	ServerConfig::Key               = _conf.get("/tars/application/server<key>");
-	ServerConfig::VerifyClient      = _conf.get("/tars/application/server<verifyclient>","0")=="0"?false:true;
-	ServerConfig::Ciphers           = _conf.get("/tars/application/server<ciphers>");
+	_serverConfig.ca                = _conf.get("/tars/application/server<ca>");
+	_serverConfig.cert              = _conf.get("/tars/application/server<cert>");
+	_serverConfig.key               = _conf.get("/tars/application/server<key>");
+	_serverConfig.verifyClient      = _conf.get("/tars/application/server<verifyclient>","0")=="0"?false:true;
+	_serverConfig.ciphers           = _conf.get("/tars/application/server<ciphers>");
 
-	if(!ServerConfig::Cert.empty()) {
-		_ctx = TC_OpenSSL::newCtx(ServerConfig::CA, ServerConfig::Cert, ServerConfig::Key, ServerConfig::VerifyClient, ServerConfig::Ciphers);
+	if(!_serverConfig.Cert.empty()) {
+		_ctx = TC_OpenSSL::newCtx(_serverConfig.ca, _serverConfig.cert, _serverConfig.key, _serverConfig.verifyClient, _serverConfig.ciphers);
 
 		if (!_ctx) {
-			TLOGERROR("[load server ssl error, ca:" << ServerConfig::CA << endl);
+			TLOGERROR("[load server ssl error, ca:" << _serverConfig.ca << endl);
 			exit(-1);
 		}
 	}
 #endif
 
-
-    if (ServerConfig::LocalIp.empty())
+    if (_serverConfig.localIp.empty())
     {
-        // ServerConfig::LocalIp = "127.0.0.1";
         vector<string> v = TC_Socket::getLocalHosts();
 
-        ServerConfig::LocalIp = "127.0.0.1";
+        _serverConfig.localIp = "127.0.0.1";
         //获取第一个非127.0.0.1的IP
         for(size_t i = 0; i < v.size(); i++)
         {
             if(v[i] != "127.0.0.1")
             {
-                ServerConfig::LocalIp = v[i];
+                _serverConfig.localIp = v[i];
                 break;
             }
         }
     }
 
+	ServerConfig::Context["node_name"] = _serverConfig.localIp;
+
+	//保存之前的
+	ApplicationConfig serverConfig = _serverConfig;
+
+	//配置文件copy到静态
+	_serverConfig.copyToStatic();
+
+	//让业务有修改配置的机会
     onServerConfig();
 
+	//检查变更
+	syncServerConfig(serverConfig);
+
 	ostringstream os;
     //输出信息
     outServer(os);
 
 	__out__.info() << os.str();
 
-	if (ServerConfig::NetThread < 1)
+	if (_serverConfig.netThread < 1)
     {
-        ServerConfig::NetThread = 1;
+        _serverConfig.netThread = 1;
 	    __out__.info()  << OUT_LINE << "\nwarning:netThreadNum < 1." << endl;
     }
 
     //网络线程的配置数目不能15个
-    if (ServerConfig::NetThread > 15)
+    if (_serverConfig.netThread > 15)
     {
-        ServerConfig::NetThread = 15;
+        _serverConfig.netThread = 15;
 	    __out__.info()  << OUT_LINE << "\nwarning:netThreadNum > 15." << endl;
     }
 
-    if(ServerConfig::CoroutineMemSize/ServerConfig::CoroutineStackSize <= 0)
+    if(_serverConfig.coroutineMemSize/_serverConfig.coroutineStackSize <= 0)
 	{
 		__out__.error()  << OUT_LINE << "\nerror:coroutine paramter error: coroutinememsize/coroutinestack <= 0!." << endl;
 		exit(-1);
 	}
     _epollServer = new TC_EpollServer();
 
-    _epollServer->setThreadNum(ServerConfig::NetThread);
-    _epollServer->setOpenCoroutine((TC_EpollServer::SERVER_OPEN_COROUTINE)ServerConfig::OpenCoroutine);
-	_epollServer->setCoroutineStack(ServerConfig::CoroutineMemSize/ServerConfig::CoroutineStackSize, ServerConfig::CoroutineStackSize);
+    _epollServer->setThreadNum(_serverConfig.netThread);
+    _epollServer->setOpenCoroutine((TC_EpollServer::SERVER_OPEN_COROUTINE)_serverConfig.openCoroutine);
+	_epollServer->setCoroutineStack(_serverConfig.coroutineMemSize/_serverConfig.coroutineStackSize, _serverConfig.coroutineStackSize);
 
     _epollServer->setOnAccept(std::bind(&Application::onAccept, this, std::placeholders::_1));
 
@@ -1210,58 +1305,57 @@ void Application::initializeServer()
 //    _epollServer->enAntiEmptyConnAttack(bEnable);
     _epollServer->setEmptyConnTimeout(TC_Common::strto<int>(toDefault(_conf.get("/tars/application/server<emptyconntimeout>"), "0")));
 
-
     ///////////////////////////////////////////////////////////////////////////////////////////////////
     //初始化本地文件cache
 	__out__.info()  << OUT_LINE << "\n" << TC_Common::outfill("[set file cache ]") << "OK" << endl;
-    AppCache::getInstance()->setCacheInfo(ServerConfig::DataPath + ServerConfig::ServerName + ".tarsdat", 0);
+	_thisCommunicator->getAppCache()->setCacheInfo(_serverConfig.dataPath + _serverConfig.serverName + ".tarsdat", 0);
 
     ///////////////////////////////////////////////////////////////////////////////////////////////////
     //初始化本地Log
     __out__.info() << OUT_LINE << "\n" << TC_Common::outfill("[set roll logger] ") << "OK" << endl;
-    LocalRollLogger::getInstance()->setLogInfo(ServerConfig::Application, ServerConfig::ServerName, ServerConfig::LogPath, ServerConfig::LogSize, ServerConfig::LogNum, _communicator, ServerConfig::Log);
+    LocalRollLogger::getInstance()->setLogInfo(_serverConfig.application, _serverConfig.serverName, _serverConfig.logPath, _serverConfig.logSize, _serverConfig.logNum, _thisCommunicator, _serverConfig.log);
     _epollServer->setLocalLogger(LocalRollLogger::getInstance()->logger());
 
     //初始化是日志为同步
     LocalRollLogger::getInstance()->sync(true);
 
     //设置日志级别
-    string level = AppCache::getInstance()->get("logLevel");
+    string level = _thisCommunicator->getAppCache()->get("logLevel");
     if(level.empty())
     {
         level = _conf.get("/tars/application/server<logLevel>","DEBUG");
     }
 
-	ServerConfig::LogLevel = TC_Common::upper(level);
+	_serverConfig.logLevel = TC_Common::upper(level);
 
-	LocalRollLogger::getInstance()->logger()->setLogLevel(ServerConfig::LogLevel);
+	LocalRollLogger::getInstance()->logger()->setLogLevel(_serverConfig.logLevel);
 
     ///////////////////////////////////////////////////////////////////////////////////////////////////
     //初始化到LogServer代理
     __out__.info() << OUT_LINE << "\n" << TC_Common::outfill("[set time logger] ") << "OK" << endl;
     bool bLogStatReport = (_conf.get("/tars/application/server<logstatreport>", "0") == "1") ? true : false;
-    RemoteTimeLogger::getInstance()->setLogInfo(_communicator, ServerConfig::Log, ServerConfig::Application, ServerConfig::ServerName, ServerConfig::LogPath, setDivision(), bLogStatReport);
+    RemoteTimeLogger::getInstance()->setLogInfo(_thisCommunicator, _serverConfig.log, _serverConfig.application, _serverConfig.serverName, _serverConfig.logPath, setDivision(), bLogStatReport);
 
     ///////////////////////////////////////////////////////////////////////////////////////////////////
     //初始化到配置中心代理
     __out__.info() << OUT_LINE << "\n" << TC_Common::outfill("[set remote config] ") << "OK" << endl;
-    RemoteConfig::getInstance()->setConfigInfo(_communicator, ServerConfig::Config, ServerConfig::Application, ServerConfig::ServerName, ServerConfig::BasePath,setDivision());
+    RemoteConfig::getInstance()->setConfigInfo(_thisCommunicator, _serverConfig.config, _serverConfig.application, _serverConfig.serverName, _serverConfig.basePath,setDivision());
 
     ///////////////////////////////////////////////////////////////////////////////////////////////////
     //初始化到信息中心代理
     __out__.info() << OUT_LINE << "\n" << TC_Common::outfill("[set remote notify] ") << "OK" << endl;
-    RemoteNotify::getInstance()->setNotifyInfo(_communicator, ServerConfig::Notify, ServerConfig::Application, ServerConfig::ServerName, setDivision(), ServerConfig::LocalIp);
+    RemoteNotify::getInstance()->setNotifyInfo(_thisCommunicator, _serverConfig.notify, _serverConfig.application, _serverConfig.serverName, setDivision(), _serverConfig.localIp);
 
     ///////////////////////////////////////////////////////////////////////////////////////////////////
     //初始化到Node的代理
     __out__.info() << OUT_LINE << "\n" << TC_Common::outfill("[set node proxy]") << "OK" << endl;
-    KeepAliveNodeFHelper::getInstance()->setNodeInfo(_communicator, ServerConfig::Node, ServerConfig::Application, ServerConfig::ServerName);
+    KeepAliveNodeFHelper::getInstance()->setNodeInfo(_thisCommunicator, _serverConfig.node, _serverConfig.application, _serverConfig.serverName);
 
     ///////////////////////////////////////////////////////////////////////////////////////////////////
     //初始化管理对象
     __out__.info()  << OUT_LINE << "\n" << TC_Common::outfill("[set admin adapter]") << "OK" << endl;
 
-    if (!ServerConfig::Local.empty())
+    if (!_serverConfig.local.empty())
     {
         _servantHelper->addServant<AdminServant>("AdminObj", this);
 
@@ -1269,7 +1363,7 @@ void Application::initializeServer()
 
 	    _servantHelper->setAdapterServant(adminAdapter, "AdminObj");
 
-        TC_EpollServer::BindAdapterPtr lsPtr = _epollServer->createBindAdapter<ServantHandle>(adminAdapter, ServerConfig::Local, 1, this);
+        TC_EpollServer::BindAdapterPtr lsPtr = _epollServer->createBindAdapter<ServantHandle>(adminAdapter, _serverConfig.local, 1, this);
 
 	    setAdapter(lsPtr, adminAdapter);
 
@@ -1288,15 +1382,15 @@ void Application::initializeServer()
     }
 
     //队列取平均值
-    if(!_communicator->getProperty("property").empty())
+    if(!_thisCommunicator->getProperty("property").empty())
     {
         string sRspQueue("");
-        sRspQueue += ServerConfig::Application;
+        sRspQueue += _serverConfig.application;
         sRspQueue += ".";
-        sRspQueue += ServerConfig::ServerName;
+        sRspQueue += _serverConfig.serverName;
         sRspQueue += ".sendrspqueue";
 
-        g_pReportRspQueue = _communicator->getStatReport()->createPropertyReport(sRspQueue, PropertyReport::avg());
+        g_pReportRspQueue = _thisCommunicator->getStatReport()->createPropertyReport(sRspQueue, PropertyReport::avg());
     }
 
     TarsTimeLogger::getInstance()->enableLocal(TRACE_LOG_FILENAME, false);
@@ -1344,7 +1438,7 @@ void Application::setAdapter(TC_EpollServer::BindAdapterPtr& adapter, const stri
 
 void Application::bindAdapter(vector<TC_EpollServer::BindAdapterPtr>& adapters)
 {
-    string sPrefix = ServerConfig::Application + "." + ServerConfig::ServerName + ".";
+    string sPrefix = _serverConfig.application + "." + _serverConfig.serverName + ".";
 
     vector<string> adapterName;
 
@@ -1365,7 +1459,7 @@ void Application::bindAdapter(vector<TC_EpollServer::BindAdapterPtr>& adapters)
             ep.parse(_conf[sLastPath + "<endpoint>"]);
             if (ep.getHost() == "localip")
             {
-                ep.setHost(ServerConfig::LocalIp);
+                ep.setHost(_serverConfig.localIp);
             }
 
             TC_EpollServer::BindAdapterPtr bindAdapter = _epollServer->createBindAdapter<ServantHandle>(adapterName[i], _conf[sLastPath + "<endpoint>"], TC_Common::strto<int>(_conf.get(sLastPath + "<threads>", "1")), this);
@@ -1387,9 +1481,9 @@ void Application::bindAdapter(vector<TC_EpollServer::BindAdapterPtr>& adapters)
 
             bindAdapter->setProtocolName(_conf.get(sLastPath + "<protocol>", "tars"));
 
-	        bindAdapter->setBackPacketBuffLimit(ServerConfig::BackPacketLimit);
+	        bindAdapter->setBackPacketBuffLimit(_serverConfig.backPacketLimit);
 
-	        bindAdapter->setBackPacketBuffMin(ServerConfig::BackPacketMin);
+	        bindAdapter->setBackPacketBuffMin(_serverConfig.backPacketMin);
 
 	        if (bindAdapter->isTarsProtocol())
             {
@@ -1405,7 +1499,7 @@ void Application::bindAdapter(vector<TC_EpollServer::BindAdapterPtr>& adapters)
             }
 #endif
 
-            if(ServerConfig::ManualListen) {
+            if(_serverConfig.manualListen) {
                 //手工监听
                 bindAdapter->enableManualListen();
             }
@@ -1415,16 +1509,16 @@ void Application::bindAdapter(vector<TC_EpollServer::BindAdapterPtr>& adapters)
             adapters.push_back(bindAdapter);
 
             //队列取平均值
-            if(!_communicator->getProperty("property").empty())
+            if(!_thisCommunicator->getProperty("property").empty())
             {
                 PropertyReportPtr p;
-                p = _communicator->getStatReport()->createPropertyReport(bindAdapter->getName() + ".queue", PropertyReport::avg());
+                p = _thisCommunicator->getStatReport()->createPropertyReport(bindAdapter->getName() + ".queue", PropertyReport::avg());
                 bindAdapter->_pReportQueue = p.get();
 
-                p = _communicator->getStatReport()->createPropertyReport(bindAdapter->getName() + ".connectRate", PropertyReport::avg());
+                p = _thisCommunicator->getStatReport()->createPropertyReport(bindAdapter->getName() + ".connectRate", PropertyReport::avg());
                 bindAdapter->_pReportConRate = p.get();
 
-                p = _communicator->getStatReport()->createPropertyReport(bindAdapter->getName() + ".timeoutNum", PropertyReport::sum());
+                p = _thisCommunicator->getStatReport()->createPropertyReport(bindAdapter->getName() + ".timeoutNum", PropertyReport::sum());
                 bindAdapter->_pReportTimeoutNum = p.get();
             }
         }
@@ -1458,7 +1552,6 @@ void Application::outAdapter(ostream &os, const string &v, TC_EpollServer::BindA
     os << TC_Common::outfill("order")            << (lsPtr->getOrder() == TC_EpollServer::BindAdapter::ALLOW_DENY ? "allow,deny" : "deny,allow") << endl;
     os << TC_Common::outfill("allow")            << TC_Common::tostr(lsPtr->getAllow()) << endl;
     os << TC_Common::outfill("deny")             << TC_Common::tostr(lsPtr->getDeny()) << endl;
-    // os << outfill("queuesize")        << lsPtr->getRecvBufferSize() << endl;
     os << TC_Common::outfill("connections")      << lsPtr->getNowConnection() << endl;
     os << TC_Common::outfill("protocol")         << lsPtr->getProtocolName() << endl;
     os << TC_Common::outfill("handlethread")     << lsPtr->getHandleNum() << endl;

+ 35 - 34
servant/libservant/Communicator.cpp

@@ -26,25 +26,25 @@ namespace tars
 {
 
 //////////////////////////////////////////////////////////////////////////////////////////////
-
-string ClientConfig::LocalIp = "127.0.0.1";
-
-string ClientConfig::ModuleName = "unknown";
-
-set<string> ClientConfig::SetLocalIp;
-
-bool ClientConfig::SetOpen = false;
-
-string ClientConfig::SetDivision = "";
-
-string ClientConfig::TarsVersion = string(TARS_VERSION);
+//
+//string ClientConfig::LocalIp = "127.0.0.1";
+//
+//string ClientConfig::ModuleName = "unknown";
+//
+//set<string> ClientConfig::SetLocalIp;
+//
+//bool ClientConfig::SetOpen = false;
+//
+//string ClientConfig::SetDivision = "";
+//
+//string ClientConfig::TarsVersion = string(TARS_VERSION);
 
 //////////////////////////////////////////////////////////////////////////////////////////////
 
 Communicator::Communicator()
 : _initialized(false)
 , _terminating(false)
-
+, _appCache(this)
 , _statReport(NULL)
 , _timeoutLogFlag(true)
 
@@ -63,6 +63,7 @@ Communicator::Communicator()
 Communicator::Communicator(TC_Config& conf, const string& domain/* = CONFIG_ROOT_PATH*/)
 : _initialized(false)
 , _terminating(false)
+, _appCache(this)
 , _timeoutLogFlag(true)
 , _keepAliveInterval(0)
 // #ifdef TARS_OPENTRACKING
@@ -242,15 +243,15 @@ void Communicator::initialize()
 	});
 
 
-	ClientConfig::TarsVersion   = TARS_VERSION;
+	_clientConfig.TarsVersion   = TARS_VERSION;
 
-    ClientConfig::SetOpen = TC_Common::lower(getProperty("enableset", "n")) == "y" ? true : false;
+    _clientConfig.SetOpen = TC_Common::lower(getProperty("enableset", "n")) == "y" ? true : false;
 
-    if (ClientConfig::SetOpen)
+    if (_clientConfig.SetOpen)
     {
-        ClientConfig::SetDivision = getProperty("setdivision");
+        _clientConfig.SetDivision = getProperty("setdivision");
 
-        vector<string> vtSetDivisions = TC_Common::sepstr<string>(ClientConfig::SetDivision, ".");
+        vector<string> vtSetDivisions = TC_Common::sepstr<string>(_clientConfig.SetDivision, ".");
 
         string sWildCard = "*";
 
@@ -259,24 +260,24 @@ void Communicator::initialize()
             || vtSetDivisions[1] == sWildCard)
         {
             //set分组名不对时默认没有打开set分组
-            ClientConfig::SetOpen = false;
+            _clientConfig.SetOpen = false;
             setProperty("enableset", "n");
-            TLOGERROR("[set division name error:" << ClientConfig::SetDivision << ", client failed to open set]" << endl);
+            TLOGERROR("[set division name error:" << _clientConfig.SetDivision << ", client failed to open set]" << endl);
         }
     }
 
-    ClientConfig::LocalIp = getProperty("localip", "");
+    _clientConfig.LocalIp = getProperty("localip", "");
 
-    if (ClientConfig::SetLocalIp.empty())
+    if (_clientConfig.SetLocalIp.empty())
     {
         vector<string> v = TC_Socket::getLocalHosts();
         for (size_t i = 0; i < v.size(); i++)
         {
-            if (v[i] != "127.0.0.1" && ClientConfig::LocalIp.empty())
+            if (v[i] != "127.0.0.1" && _clientConfig.LocalIp.empty())
             {
-                ClientConfig::LocalIp = v[i];
+                _clientConfig.LocalIp = v[i];
             }
-            ClientConfig::SetLocalIp.insert(v[i]);
+            _clientConfig.SetLocalIp.insert(v[i]);
         }
     }
 
@@ -290,10 +291,10 @@ void Communicator::initialize()
     catch (TC_File_Exception& ex)
     {
         //取失败则使用ip代替进程名
-        exe = ClientConfig::LocalIp;
+        exe = _clientConfig.LocalIp;
     }
 
-    ClientConfig::ModuleName = getProperty("modulename", exe);
+    _clientConfig.ModuleName = getProperty("modulename", exe);
 
 #if TARS_SSL
 
@@ -378,7 +379,7 @@ void Communicator::initialize()
     }
 
     //异步队列数目上报
-    _reportAsyncQueue= getStatReport()->createPropertyReport(ClientConfig::ModuleName  + ".asyncqueue", PropertyReport::avg());
+    _reportAsyncQueue= getStatReport()->createPropertyReport(_clientConfig.ModuleName  + ".asyncqueue", PropertyReport::avg());
     
     //初始化统计上报接口
     string statObj = getProperty("stat", "");
@@ -414,8 +415,8 @@ void Communicator::initialize()
         propertyPrx = stringToProxy<PropertyFPrx>(propertyObj);
     }
 
-    string sSetDivision = ClientConfig::SetOpen ? ClientConfig::SetDivision : "";
-    _statReport->setReportInfo(statPrx, propertyPrx, ClientConfig::ModuleName, ClientConfig::LocalIp, sSetDivision, iReportInterval, 0, 0, iMaxReportSize, iReportTimeout);
+    string sSetDivision = _clientConfig.SetOpen ? _clientConfig.SetDivision : "";
+    _statReport->setReportInfo(statPrx, propertyPrx, _clientConfig.ModuleName, _clientConfig.LocalIp, sSetDivision, iReportInterval, 0, 0, iMaxReportSize, iReportTimeout);
 
 #if TARS_OPENTRACKING
 	string collector_host = getProperty("collector_host", "");
@@ -424,8 +425,8 @@ void Communicator::initialize()
     {
         //init zipkin config
         zipkin::ZipkinOtTracerOptions options;
-        options.service_name = ClientConfig::ModuleName;
-        options.service_address = {zipkin::IpVersion::v4, ClientConfig::LocalIp};
+        options.service_name = _clientConfig.ModuleName;
+        options.service_address = {zipkin::IpVersion::v4, _clientConfig.LocalIp};
 
         options.sample_rate = strtod(getProperty("sample_rate", "1.0").c_str(), NULL);
         options.collector_host = collector_host;
@@ -565,8 +566,8 @@ int Communicator::reloadProperty(string & sResult)
         propertyPrx = stringToProxy<PropertyFPrx>(propertyObj);
     }
 
-    string sSetDivision = ClientConfig::SetOpen ? ClientConfig::SetDivision : "";
-    _statReport->setReportInfo(statPrx, propertyPrx, ClientConfig::ModuleName, ClientConfig::LocalIp, sSetDivision, iReportInterval, 0, 0, iMaxReportSize, iReportTimeout);
+    string sSetDivision = _clientConfig.SetOpen ? _clientConfig.SetDivision : "";
+    _statReport->setReportInfo(statPrx, propertyPrx, _clientConfig.ModuleName, _clientConfig.LocalIp, sSetDivision, iReportInterval, 0, 0, iMaxReportSize, iReportTimeout);
 
     sResult = "locator=" + getProperty("locator", "") + "\r\n" +
         "stat=" + statObj + "\r\n" + "property=" + propertyObj + "\r\n" +

+ 11 - 3
servant/libservant/Current.cpp

@@ -51,10 +51,13 @@ Current::~Current()
         {
             reportToStat("stat_from_server");
         }
-        else if (!_isTars && ServerConfig::ReportFlow)
+        else if (!_isTars && _servantHandle)
         {
-            //非tars客户端 从服务端上报调用信息
-            reportToStat("not_tars_client");
+			if(_servantHandle->getApplication()->applicationConfig().reportFlow)
+			{
+				//非tars客户端 从服务端上报调用信息
+				reportToStat("not_tars_client");
+			}
         }
     }
 }
@@ -444,6 +447,11 @@ bool Current::connectionExists() const
 	return _data->connectionExists();
 }
 
+const string &Current::moduleName() const
+{
+	return _servantHandle->getApplication()->getThisCommunicator()->clientConfig().ModuleName;
+}
+
 
 ////////////////////////////////////////////////////////////////////////////
 }

+ 15 - 16
servant/libservant/EndpointManager.cpp

@@ -20,7 +20,6 @@
 #include "servant/AppCache.h"
 #include "servant/Application.h"
 #include "servant/CommunicatorEpoll.h"
-//#include "servant/StatReport.h"
 
 namespace tars
 {
@@ -36,7 +35,7 @@ void QueryPushFImp::replacePrx(QueryFPrx queryFPrx)
 
 	for(auto it : _queryBase)
 	{
-		_queryFPrx->tars_hash((uint64_t)_queryFPrx.get())->async_registerQuery(NULL, it.first, ClientConfig::ModuleName);
+		_queryFPrx->tars_hash((uint64_t)_queryFPrx.get())->async_registerQuery(NULL, it.first, _queryFPrx->tars_communicator()->clientConfig().ModuleName);
 	}
 }
 
@@ -48,7 +47,7 @@ void QueryPushFImp::registerQuery(const string &obj, QueryEpBase *pQueryBase)
 		_queryBase[obj].insert(pQueryBase);
 	}
 
-	_queryFPrx->tars_hash((uint64_t)_queryFPrx.get())->async_registerQuery(NULL, obj, ClientConfig::ModuleName);
+	_queryFPrx->tars_hash((uint64_t)_queryFPrx.get())->async_registerQuery(NULL, obj, _queryFPrx->tars_communicator()->clientConfig().ModuleName);
 }
 
 void QueryPushFImp::onConnect(const TC_Endpoint& ep)
@@ -56,7 +55,7 @@ void QueryPushFImp::onConnect(const TC_Endpoint& ep)
 	std::lock_guard<std::mutex> lock(_mutex);
 	for(auto it : _queryBase)
 	{
-		_queryFPrx->tars_hash((uint64_t)_queryFPrx.get())->async_registerQuery(NULL, it.first, ClientConfig::ModuleName);
+		_queryFPrx->tars_hash((uint64_t)_queryFPrx.get())->async_registerQuery(NULL, it.first, _queryFPrx->tars_communicator()->clientConfig().ModuleName);
 	}
 }
 
@@ -289,9 +288,9 @@ void QueryEpBase::setObjName(const string & sObjName)
 		string sLocatorKey = _locator;
 
         //如果启用set,则获取按set分组的缓存
-        if(ClientConfig::SetOpen)
+        if(_communicator->clientConfig().SetOpen)
         {
-            sLocatorKey += "_" + ClientConfig::SetDivision;
+            sLocatorKey += "_" + _communicator->clientConfig().SetDivision;
         }
 
         string objName = _objName + string(_invokeSetId.empty() ? "" : ":") + _invokeSetId;
@@ -299,8 +298,8 @@ void QueryEpBase::setObjName(const string & sObjName)
         //[间接连接]第一次使用cache,如果是接口级请求则不从缓存读取
         if(!_interfaceReq)
         {
-            sEndpoints = AppCache::getInstance()->get(objName,sLocatorKey);
-            sInactiveEndpoints = AppCache::getInstance()->get("inactive_"+objName,sLocatorKey);
+            sEndpoints = _communicator->getAppCache()->get(objName,sLocatorKey);
+            sInactiveEndpoints = _communicator->getAppCache()->get("inactive_"+objName,sLocatorKey);
         }
     }
 
@@ -467,10 +466,10 @@ void QueryEpBase::refreshReg(GetEndpointType type, const string & sName)
                     case E_DEFAULT:
                     default:
                         {
-                            if(ClientConfig::SetOpen || !_invokeSetId.empty())
+                            if(_communicator->clientConfig().SetOpen || !_invokeSetId.empty())
                             {
                                 //指定set调用时,指定set的优先级最高
-                                string setId = _invokeSetId.empty()?ClientConfig::SetDivision:_invokeSetId;
+                                string setId = _invokeSetId.empty()?_communicator->clientConfig().SetDivision : _invokeSetId;
                                 iRet = _queryFPrx->tars_hash((uint64_t)_queryFPrx.get())->findObjectByIdInSameSet(_objName,setId,activeEp,inactiveEp, ServerConfig::Context);
                             }
                             else
@@ -504,10 +503,10 @@ void QueryEpBase::refreshReg(GetEndpointType type, const string & sName)
                     case E_DEFAULT:
                     default:
                         {
-                            if(ClientConfig::SetOpen || !_invokeSetId.empty())
+                            if(_communicator->clientConfig().SetOpen || !_invokeSetId.empty())
                             {
                                 //指定set调用时,指定set的优先级最高
-                                string setId = _invokeSetId.empty()?ClientConfig::SetDivision:_invokeSetId;
+                                string setId = _invokeSetId.empty()?_communicator->clientConfig().SetDivision:_invokeSetId;
                                 _queryFPrx->tars_hash((uint64_t)_queryFPrx.get())->async_findObjectByIdInSameSet(this,_objName,setId, ServerConfig::Context);
                             }
                             else
@@ -713,18 +712,18 @@ void QueryEpBase::setEndPointToCache(bool bInactive)
 
     //如果启用set,则按set分组保存
     string sLocatorKey = _locator;
-    if(ClientConfig::SetOpen)
+    if(_communicator->clientConfig().SetOpen)
     {
-        sLocatorKey += "_" + ClientConfig::SetDivision;
+        sLocatorKey += "_" + _communicator->clientConfig().SetDivision;
     }
     string objName = _objName + string(_invokeSetId.empty()?"":":") + _invokeSetId;
     if(bInactive)
     {
-        AppCache::getInstance()->set("inactive_"+objName,sEndpoints,sLocatorKey);
+		_communicator->getAppCache()->set("inactive_"+objName,sEndpoints,sLocatorKey);
     }
     else
     {
-        AppCache::getInstance()->set(objName,sEndpoints,sLocatorKey);
+		_communicator->getAppCache()->set(objName,sEndpoints,sLocatorKey);
     }
 
     TLOGTARS("[setEndPointToCache,obj:" << _objName << ",invokeSetId:" << _invokeSetId << ",endpoint:" << sEndpoints << "]" << endl);

+ 5 - 0
servant/libservant/Message.cpp

@@ -28,6 +28,11 @@ void ReqMessage::init(CallType eCallType, ServantProxy *prx)
 	iCoroId        = 0;
 }
 
+const string &ReqMessage::moduleName()
+{
+	return proxy->tars_communicator()->clientConfig().ModuleName;
+}
+
 ReqMessage::~ReqMessage()
 {
 	if(deconstructor)

+ 2 - 2
servant/libservant/ObjectProxy.cpp

@@ -47,10 +47,10 @@ ObjectProxy::ObjectProxy(CommunicatorEpoll *pCommunicatorEpoll, ServantProxy *se
     {
         _name = sObjectProxyName;
         //启用set或者指定set调用
-        if(ClientConfig::SetOpen || !_invokeSetId.empty())
+        if(_communicatorEpoll->getCommunicator()->clientConfig().SetOpen || !_invokeSetId.empty())
         {
             //指定set调用时,指定set的优先级最高
-            _invokeSetId  = _invokeSetId.empty()?ClientConfig::SetDivision:_invokeSetId;
+            _invokeSetId  = _invokeSetId.empty()?_communicatorEpoll->getCommunicator()->clientConfig().SetDivision:_invokeSetId;
             _isInvokeBySet = true;
         }
     }

+ 70 - 117
servant/libservant/ServantHandle.cpp

@@ -41,9 +41,6 @@ ServantHandle::ServantHandle(Application *application)
 
 ServantHandle::~ServantHandle()
 {
-//    auto it = _servants.begin();
-//
-//    while(it != _servants.end())
     {
         try
         {
@@ -60,7 +57,6 @@ ServantHandle::~ServantHandle()
         {
             TLOGERROR("[ServantHandle::destroy unknown exception error]" << endl);
         }
-//        ++it;
     }
 }
 
@@ -68,59 +64,51 @@ void ServantHandle::handleAsyncResponse()
 {
     ReqMessagePtr resp;
 
-//    auto it = _servants.begin();
-//
-//    while (it != _servants.end())
-//    {
-        while (_servant->getResponseQueue().pop_front(resp))
-        {
-            try
-            {
-                if (resp->response->iRet == TARSSERVERSUCCESS)
-                {
-					_servant->doResponse(resp);
-                }
-                else if (resp->pObjectProxy == NULL)
-                {
-					_servant->doResponseNoRequest(resp);
-                }
-                else
-                {
-					_servant->doResponseException(resp);
-                }
-            }
-            catch (exception& e)
-            {
-                TLOGERROR("[ServantHandle::doResponse ex:" << e.what() << "]" << endl);
-            }
-            catch (...)
-            {
-                TLOGERROR("[ServantHandle::doResponse error]" << endl);
-            }
-        }
+	while (_servant->getResponseQueue().pop_front(resp))
+	{
+		try
+		{
+			if (resp->response->iRet == TARSSERVERSUCCESS)
+			{
+				_servant->doResponse(resp);
+			}
+			else if (resp->pObjectProxy == NULL)
+			{
+				_servant->doResponseNoRequest(resp);
+			}
+			else
+			{
+				_servant->doResponseException(resp);
+			}
+		}
+		catch (exception& e)
+		{
+			TLOGERROR("[ServantHandle::doResponse ex:" << e.what() << "]" << endl);
+		}
+		catch (...)
+		{
+			TLOGERROR("[ServantHandle::doResponse error]" << endl);
+		}
+	}
 
-        //业务处理附加的自有消息
-        try
-        {
-			_servant->doCustomMessage(false);
-			_servant->doCustomMessage();
-        }
-        catch (exception& e)
-        {
-            TLOGERROR("[ServantHandle::doCustemMessage ex:" << e.what() << "]" << endl);
-        }
-        catch (...)
-        {
-            TLOGERROR("[ServantHandle::doCustemMessage ex.]" << endl);
-        }
-//
-//        ++it;
-//    }
+	//业务处理附加的自有消息
+	try
+	{
+		_servant->doCustomMessage(false);
+		_servant->doCustomMessage();
+	}
+	catch (exception& e)
+	{
+		TLOGERROR("[ServantHandle::doCustemMessage ex:" << e.what() << "]" << endl);
+	}
+	catch (...)
+	{
+		TLOGERROR("[ServantHandle::doCustemMessage ex.]" << endl);
+	}
 }
 
 void ServantHandle::handleCustomMessage(bool bExpectIdle)
 {
-//    for (auto it = _servants.begin(); it != _servants.end(); it++)
     {
         //业务处理附加的自有消息
         try
@@ -141,15 +129,11 @@ void ServantHandle::handleCustomMessage(bool bExpectIdle)
 
 bool ServantHandle::allFilterIsEmpty()
 {
-//	auto it = _servants.begin();
-//
-//	while (it != _servants.end())
 	{
 		if (!_servant->getResponseQueue().empty())
 		{
 			return false;
 		}
-//		++it;
 	}
 	return true;
 }
@@ -165,7 +149,7 @@ void ServantHandle::initialize()
 
 	if (!_servant)
 	{
-		if(ServerConfig::CheckBindAdapter)
+		if(_application->applicationConfig().checkBindAdapter)
 		{
 			TLOGERROR("[ServantHandle initialize createServant ret null, for adapter `" + _bindAdapter->getName() + "`]"
 					<< endl);
@@ -184,52 +168,35 @@ void ServantHandle::initialize()
 			return;
 		}
 	}
-//
-//    auto it = _servants.begin();
-//
-//    if(it == _servants.end())
-//    {
-//        TLOGERROR("[initialize error: no servant exists]" << endl);
-//
-//        RemoteNotify::getInstance()->report("initialize error: no servant exists.");
-//
-//        TC_Common::msleep(100);
-//
-//        exit(-1);
-//    }
-//
-//    while(it != _servants.end())
-//    {
-        try
-        {
-			_servant->setHandle(this);
 
-			_servant->initialize();
+	try
+	{
+		_servant->setHandle(this);
+
+		_servant->initialize();
 
-            TLOGTARS("[" << _servant->getName() << " initialize]" << endl);
-        }
-        catch(exception &ex)
-        {
-            TLOGERROR("[initialize error:" << ex.what() << "]" << endl);
+		TLOGTARS("[" << _servant->getName() << " initialize]" << endl);
+	}
+	catch(exception &ex)
+	{
+		TLOGERROR("[initialize error:" << ex.what() << "]" << endl);
 
-            RemoteNotify::getInstance()->report("initialize error:" + string(ex.what()));
+		RemoteNotify::getInstance()->report("initialize error:" + string(ex.what()));
 
-	        TC_Common::msleep(100);
+		TC_Common::msleep(100);
 
-	        exit(-1);
-        }
-        catch(...)
-        {
-            TLOGERROR("[initialize unknown exception error]" << endl);
+		exit(-1);
+	}
+	catch(...)
+	{
+		TLOGERROR("[initialize unknown exception error]" << endl);
 
-            RemoteNotify::getInstance()->report("initialize unknown exception error");
+		RemoteNotify::getInstance()->report("initialize unknown exception error");
 
-	        TC_Common::msleep(100);
+		TC_Common::msleep(100);
 
-			exit(-1);
-		}
-//		++it;
-//	}
+		exit(-1);
+	}
 }
 
 void ServantHandle::heartbeat()
@@ -315,15 +282,6 @@ void ServantHandle::handleClose(const shared_ptr<TC_EpollServer::RecvContext> &d
     TLOGTARS("[ServantHandle::handleClose,adapter:" << data->adapter()->getName() << ",peer:" << data->ip() << ":" << data->port() << "]"<< endl);
 
 	CurrentPtr current = createCloseCurrent(data);
-//
-//	auto sit = _servants.find(current->getServantName());
-//
-//	if (sit == _servants.end())
-//	{
-//		TLOGERROR("[TARS]ServantHandle::handleClose,adapter:" << data->adapter()->getName() << ",peer:" << data->ip() << ":" << data->port() << ", " << current->getServantName() << " not found" << endl);
-//
-//		return;
-//	}
 
 	try
 	{
@@ -579,15 +537,16 @@ bool ServantHandle::processCookie(const CurrentPtr &current, map<string, string>
 bool ServantHandle::checkValidSetInvoke(const CurrentPtr &current)
 {
 	/*是否允许检查合法性*/
-	if (ServerConfig::IsCheckSet == 0)
+	if (_application->applicationConfig().isCheckSet == 0)
 	{
 		//不检查
 		return true;
 	}
 
+	auto clientConfig = _application->getThisCommunicator()->clientConfig();
     bool isSetInvoke = IS_MSG_TYPE(current->getMessageType(), tars::TARSMESSAGETYPESETNAME);
     //客户端按set规则调用且服务端启用set
-    if (isSetInvoke && ClientConfig::SetOpen)
+    if (isSetInvoke && clientConfig.SetOpen)
     {
         /**
          * 合法性规则:
@@ -605,20 +564,20 @@ bool ServantHandle::checkValidSetInvoke(const CurrentPtr &current)
 
 			sSetName = setIt->second;
 
-            if (ClientConfig::SetDivision == sSetName)
+            if (clientConfig.SetDivision == sSetName)
             {
                 return true;
             }
             else
             {
                 //属于同一地区是也属于合法调用
-                string setArea1 = ClientConfig::SetDivision.substr(0,ClientConfig::SetDivision.find_last_of("."));
+                string setArea1 = clientConfig.SetDivision.substr(0, clientConfig.SetDivision.find_last_of("."));
                 string setArea2 = sSetName.substr(0,sSetName.find_last_of("."));
                 if (setArea1 == setArea2)
                 {
                     return true;
                 }
-                else if (ClientConfig::SetDivision.substr(0,ClientConfig::SetDivision.find_first_of(".")) !=
+                else if (clientConfig.SetDivision.substr(0, clientConfig.SetDivision.find_first_of(".")) !=
                          sSetName.substr(0,sSetName.find_first_of(".")))
                 {
                     //属于不同的set之间调用也属于合法
@@ -631,7 +590,7 @@ bool ServantHandle::checkValidSetInvoke(const CurrentPtr &current)
                             << current->getMessageType() << "|"
                             << current->getServantName() << "|"
                             << current->getFuncName() << "|client:"
-                            << ClientConfig::SetDivision << "|server:"
+                            << clientConfig.SetDivision << "|server:"
                             << sSetName << "]" << endl);
                     current->sendResponse(TARSINVOKEBYINVALIDESET);
                     return false;
@@ -645,7 +604,7 @@ bool ServantHandle::checkValidSetInvoke(const CurrentPtr &current)
                             << current->getMessageType() << "|"
                             << current->getServantName() << "|"
                             << current->getFuncName() << "|client:"
-                            << ClientConfig::SetDivision << "|server:"
+                            << clientConfig.SetDivision << "|server:"
                             << sSetName << "]" << endl);
             current->sendResponse(TARSINVOKEBYINVALIDESET);
             return false;
@@ -694,8 +653,6 @@ void ServantHandle::handleTarsProtocol(const CurrentPtr &current)
 	ResponsePacket response;
 	try
 	{
-//		TLOGERROR("[ServantHandle::handleTarsProtocol here] " << _servant->getName() << ", " << current->getServantName() << endl);
-
 		if (_servant->getName() != current->getServantName())
 		{
 			response.iRet = _servant->doNoServant(current, response.sBuffer);
@@ -761,10 +718,6 @@ void ServantHandle::handleNoTarsProtocol(const TarsCurrentPtr &current)
         << current->getIp() << "|"
         << current->getPort() << "|"
         << current->getServantName() << "]" << endl);
-//
-//	auto sit = _servants.find(current->getServantName());
-//
-//	assert(sit != _servants.end());
 
 	vector<char> buffer;
 

+ 3 - 3
servant/libservant/StatReport.cpp

@@ -246,11 +246,11 @@ void StatReport::report(const string& strModuleName,
     {
         if (!_setName.empty())
         {
-            head.masterName = _moduleName + "." + _setName + _setArea + _setID + "@" + ClientConfig::TarsVersion;
+            head.masterName = _moduleName + "." + _setName + _setArea + _setID + "@" + this->_communicator->clientConfig().TarsVersion;
         }
         else
         {
-            head.masterName = _moduleName + "@" + ClientConfig::TarsVersion;
+            head.masterName = _moduleName + "@" + this->_communicator->clientConfig().TarsVersion;
         }
 
         if (!setdivision.empty()) //被调没有启用set分组,slavename保持原样
@@ -338,7 +338,7 @@ void StatReport::report(const string& strMasterName,
     StatMicMsgHead head;
     StatMicMsgBody body;
 
-    head.masterName     = trimAndLimitStr(strMasterName + "@" + ClientConfig::TarsVersion, MAX_MASTER_NAME_LEN);
+    head.masterName     = trimAndLimitStr(strMasterName + "@" + this->_communicator->clientConfig().TarsVersion, MAX_MASTER_NAME_LEN);
     head.masterIp       = trimAndLimitStr(strMasterIp,      MAX_MASTER_IP_LEN);
     head.slaveName      = trimAndLimitStr(strSlaveName,     MAX_MASTER_NAME_LEN);
     head.slaveIp        = trimAndLimitStr(strSlaveIp,       MAX_MASTER_IP_LEN);

+ 8 - 2
servant/servant/AppCache.h

@@ -34,14 +34,15 @@ using namespace std;
 
 namespace tars
 {
+class Communicator;
 //////////////////////////////////////////////////////////////////////
 /**
  * 缓存
  */
-class SVT_DLL_API AppCache : public TC_Singleton<AppCache>, public TC_ThreadMutex
+class SVT_DLL_API AppCache : public TC_ThreadMutex
 {    
 public:
-    AppCache()
+    AppCache(Communicator *communicator)
     : _lastSynTime(0)
     , _synInterval(1000)
     {
@@ -86,6 +87,11 @@ public:
     int set(const string &sName,const string &sValue,const string sDomain = ""/*=APPCACHE_ROOT_PATH*/);
 
 private:
+
+	/**
+	 *
+	 */
+	Communicator *_communicator = NULL;
     /*
      * 缓存文件
      */

+ 121 - 53
servant/servant/Application.h

@@ -35,6 +35,7 @@
 #include "servant/RemoteConfig.h"
 #include "servant/RemoteNotify.h"
 #include "servant/NotifyObserver.h"
+#include "servant/AppCache.h"
 #include "util/tc_openssl.h"
 
 namespace tars
@@ -103,41 +104,45 @@ namespace tars
 //////////////////////////////////////////////////////////////////////
 /**
  * 服务基本信息
+ * 建议不再使用这个类, 使用Application中的成员变量(Application::ApplicationConfig)
+ * 如果一个进程中存在多个服务的时候, 会有bug(当然这种情况一般不会出现)
+ * 保留ServerConfig的原因是为了兼容旧版本
  */
 struct SVT_DLL_API ServerConfig
 {
-    static std::string TarsPath;			//tars路径: /usr/local/app/tars
-    static std::string Application;         //应用名称
-    static std::string ServerName;          //服务名称,一个服务名称含一个或多个服务标识
-    static std::string BasePath;            //应用程序路径,用于保存远程系统配置的本地目录
-    static std::string DataPath;            //应用程序数据路径用于保存普通数据文件
-    static std::string LocalIp;             //本机IP
-    static std::string LogPath;             //log路径
-    static int         LogSize;             //log大小(字节)
-    static int         LogNum;              //log个数()
-    static std::string LogLevel;            //log日志级别
-    static std::string Local;               //本地套接字
-    static std::string Node;                //本机node地址
-    static std::string Log;                 //日志中心地址
-    static std::string Config;              //配置中心地址
-    static std::string Notify;              //信息通知中心
-    static std::string ConfigFile;          //框架配置文件路径
-    static bool        CloseCout;			//是否关闭标准输出
-    static int         ReportFlow;          //是否服务端上报所有接口stat流量 0不上报 1上报(用于非tars协议服务流量统计)
-    static int         IsCheckSet;          //是否对按照set规则调用进行合法性检查 0,不检查,1检查
-    static int         OpenCoroutine;       //是否启用协程处理方式(0~3)
-    static size_t      CoroutineMemSize;    //协程占用内存空间的最大大小
-    static uint32_t    CoroutineStackSize;  //每个协程的栈大小(默认128k)
-	static int         NetThread;           //server net thread
-	static bool        ManualListen;        //是否启用手工端口监听
-	static int         BackPacketLimit;     //回包积压检查
-	static int         BackPacketMin;       //回包速度检查
-	static bool 	   CheckBindAdapter;	//检查配置中bindAdapter
-
+	////////////////////////////////////////////////////////////////////////////////////
+	//兼容老版本而存在
+	static std::string TarsPath;				//tars路径: /usr/local/app/tars
+	static std::string Application;         	//应用名称
+	static std::string ServerName;          	//服务名称,一个服务名称含一个或多个服务标识
+	static std::string BasePath;            	//应用程序路径,用于保存远程系统配置的本地目录
+	static std::string DataPath;            	//应用程序数据路径用于保存普通数据文件
+	static std::string LocalIp;             	//本机IP
+	static std::string LogPath;             	//log路径
+	static int         LogSize;             	//循环log大小(字节)
+	static int         LogNum;              	//循环log个数()
+	static std::string LogLevel;            	//循环log日志级别
+	static std::string Local;               	//本地绑定的管理地址
+	static std::string Node;                	//本机node地址
+	static std::string Log;                 	//日志中心地址
+	static std::string Config;              	//配置中心地址
+	static std::string Notify;              	//信息通知中心
+	static std::string ConfigFile;          	//框架配置文件路径
+	static bool        CloseCout;				//是否关闭标准输出
+	static int         ReportFlow;         //是否服务端上报所有接口stat流量 0不上报 1上报(用于非tars协议服务流量统计)
+	static int         IsCheckSet;         //是否对按照set规则调用进行合法性检查 0,不检查,1检查
+	static int         OpenCoroutine;      //是否启用协程处理方式(0~3)
+	static size_t      CoroutineMemSize;    	//协程占用内存空间的最大大小
+	static uint32_t    CoroutineStackSize;  	//每个协程的栈大小(默认128k)
+	static int         NetThread;          	//server net thread
+	static bool        ManualListen;   //是否启用手工端口监听
+	static int         BackPacketLimit;    //回包积压检查
+	static int         BackPacketMin;  //回包速度检查
+	static bool 	   CheckBindAdapter;//检查配置中bindAdapter
 	static std::string CA;
 	static std::string Cert;
 	static std::string Key;
-	static bool VerifyClient;
+	static bool 	   VerifyClient;
 	static std::string Ciphers;
 
 	static map<string, string> Context;     //框架内部用, 传递节点名称(以域名形式部署时)
@@ -152,6 +157,49 @@ class PropertyReport;
 class Application: public BaseNotify
 {
 public:
+	/**
+	 * 每个application有自己的!
+	 */
+	struct ApplicationConfig
+	{
+		std::string tarsPath;				//tars路径: /usr/local/app/tars
+		std::string application;         	//应用名称
+		std::string serverName;          	//服务名称,一个服务名称含一个或多个服务标识
+		std::string basePath;            	//应用程序路径,用于保存远程系统配置的本地目录
+		std::string dataPath;            	//应用程序数据路径用于保存普通数据文件
+		std::string localIp;             	//本机IP
+		std::string logPath;             	//log路径
+		int         logSize;             	//循环log大小(字节)
+		int         logNum;              	//循环log个数()
+		std::string logLevel;            	//循环log日志级别
+		std::string local;               	//本地绑定的管理地址
+		std::string node;                	//本机node地址
+		std::string log;                 	//日志中心地址
+		std::string config;              	//配置中心地址
+		std::string notify;              	//信息通知中心
+		std::string configFile;          	//框架配置文件路径
+		bool        closeCout;				//是否关闭标准输出
+		int         reportFlow = 1;         //是否服务端上报所有接口stat流量 0不上报 1上报(用于非tars协议服务流量统计)
+		int         isCheckSet = 1;         //是否对按照set规则调用进行合法性检查 0,不检查,1检查
+		int         openCoroutine = 0;      //是否启用协程处理方式(0~3)
+		size_t      coroutineMemSize;    	//协程占用内存空间的最大大小
+		uint32_t    coroutineStackSize;  	//每个协程的栈大小(默认128k)
+		int         netThread;          	//server net thread
+		bool        manualListen = false;   //是否启用手工端口监听
+		int         backPacketLimit = 0;    //回包积压检查
+		int         backPacketMin =  1024;  //回包速度检查
+		bool 	    checkBindAdapter = true;//检查配置中bindAdapter
+
+		std::string ca;
+		std::string cert;
+		std::string key;
+		bool 		verifyClient = false;
+		std::string ciphers;
+
+		//copy到静态变量
+		void copyToStatic();
+	};
+
     /**
      * 应用构造
      */
@@ -162,7 +210,7 @@ public:
      */
     virtual ~Application();
 
-    /**
+	/**
      * 初始化 --config=xxxx
      * @param argv
      */
@@ -190,28 +238,49 @@ public:
      */
     void waitForReady();
 
-public:
     /**
      * 获取配置文件
      *
      * @return TC_Config&
      */
     TC_Config &getConfig() { return _conf; }
+
+	/**
+	 *
+	 * @return
+	 */
 	const TC_Config &getConfig() const { return _conf; }
 
 	/**
-	 * 获取通信器
+	 * 服务基本配置信息
+	 * @return
+	 */
+	const ApplicationConfig &applicationConfig() const { return _serverConfig ;}
+
+	/**
+	 * 获取通信器(静态全局)
 	 *
 	 * @return CommunicatorPtr&
 	 */
     static CommunicatorPtr& getCommunicator();
 
-    /**
-     * 获取服务Server对象
-     *
-     * @return TC_EpollServerPtr&
-     */
+	/**
+	 * 每个Server自己的通信器(如果只有一个Server, 那么通信器也是全局的)
+	 * @return
+	 */
+	CommunicatorPtr getThisCommunicator();
+
+	/**
+	 * 获取服务Server对象
+	 *
+	 * @return TC_EpollServerPtr&
+	 */
     TC_EpollServerPtr &getEpollServer() { return _epollServer; }
+
+	/**
+	 * epoll server
+	 * @return
+	 */
 	const TC_EpollServerPtr &getEpollServer() const { return _epollServer; }
 
 	/**
@@ -417,7 +486,6 @@ protected:
      */
     bool cmdSetDyeing(const string &command, const string &params, string &result);
 
-
     /**
      * 设置是否关闭stdcout/stderr/stdin 服务重启能才生效
      * @param command
@@ -453,17 +521,6 @@ protected:
      */
     void onAccept(TC_EpollServer::Connection* cPtr);
 
-    // /**
-    //  *
-    //  *
-    //  * @param command
-    //  * @param params
-    //  * @param result
-    //  *
-    //  * @return bool
-    //  */
-    // void addServantOnClose(const string& servant, const TC_EpollServer::close_functor& f);
-
 protected:
     /**
      * 读取基本信息
@@ -542,6 +599,11 @@ protected:
      */
     string setDivision(void);
 
+	/**
+	 * 通知静态和非静态变量的配置信息
+	 * @param serverConfig
+	 */
+	void syncServerConfig(const ApplicationConfig &serverConfig);
 protected:
     /**
      * config
@@ -551,17 +613,23 @@ protected:
     /**
      * epoll server
      */
-    TC_EpollServerPtr   _epollServer;
+    TC_EpollServerPtr   	_epollServer;
 
 	/**
-	 * ServerConfig
+	 * ApplicationConfig
 	 */
-	ServerConfig		_serverConfig;
+	struct ApplicationConfig	_serverConfig;
 
     /**
      * communicator
      */
-    static CommunicatorPtr     _communicator;
+    static CommunicatorPtr  _communicator;
+
+	/**
+	 * communicator
+	 */
+	CommunicatorPtr     _thisCommunicator;
+
 
     /**
      * accept

+ 55 - 27
servant/servant/Communicator.h

@@ -23,11 +23,10 @@
 #include "servant/Global.h"
 #include "servant/ServantProxy.h"
 #include "servant/ServantProxyFactory.h"
-//#include "servant/ObjectProxyFactory.h"
 #include "servant/AsyncProcThread.h"
-// #include "servant/CommunicatorEpoll.h"
 #include "servant/StatReport.h"
 #include "servant/RemoteLogger.h"
+#include "servant/AppCache.h"
 
 #include "util/tc_openssl.h"
 
@@ -115,6 +114,7 @@ namespace tars
 
 class CommunicatorEpoll;
 class TC_OpenSSL;
+class AppCache;
 
 ////////////////////////////////////////////////////////////////////////
 /**
@@ -122,31 +122,35 @@ class TC_OpenSSL;
  */
 struct ClientConfig
 {
-    /**
-     * 客户端IP地址
-     */
-    static string          LocalIp;
-    /**
-     * 客户端模块名称
-     */
-    static string          ModuleName;
-    /**
-     * 客户端所有的IP地址
-     */
-    static set<string>     SetLocalIp;
-   /**
-   *客户端是否打开set分组
-   */
-   static bool             SetOpen;
-   /**
-   *客户端set分组
-   */
-   static string           SetDivision;
+	/**
+	 * 客户端IP地址
+	 */
+	string LocalIp = "127.0.0.1";
 
-   /**
-    * 客户端的版本号
-    */
-   static string           TarsVersion;
+	/**
+	 * 客户端模块名称
+	 */
+	string ModuleName = "unknown";
+
+	/**
+	 * 客户端所有的IP地址
+	 */
+	set<string> SetLocalIp;
+
+	/**
+	*客户端是否打开set分组
+	*/
+	bool SetOpen;
+
+	/**
+	*客户端set分组
+	*/
+	string SetDivision;
+
+	/**
+	 * 客户端的版本号
+	 */
+	string TarsVersion = TARS_VERSION;
 };
 
 ////////////////////////////////////////////////////////////////////////
@@ -342,6 +346,11 @@ public:
 	 */
 	bool isTerminating();
 
+	/**
+	 *
+	 * @return
+	 */
+	const ClientConfig &clientConfig() { return _clientConfig; }
 protected:
     /**
      * 初始化
@@ -439,6 +448,12 @@ protected:
 	 */
 	void eraseSchedCommunicatorEpoll(size_t netThreadSeq);
 
+	/**
+	 * 存储ip list配置
+	 * @return
+	 */
+	AppCache *getAppCache() { return &_appCache; }
+
 	/**
      * 框架内部需要直接访问通信器的类
      */
@@ -458,6 +473,10 @@ protected:
 
 	friend class ServantProxyThreadData;
 
+	friend class Application;
+
+	friend class QueryEpBase;
+
 protected:
     /**
      * 是否初始化
@@ -469,6 +488,16 @@ protected:
      */
     bool  _terminating;
 
+	/**
+	 *
+	 */
+	ClientConfig	_clientConfig;
+
+	/**
+	 *
+	 */
+	AppCache			_appCache;
+
     /**
      * 客户端的属性配置
      */
@@ -497,7 +526,6 @@ protected:
     /**
      * 操作通信器的锁
      */
-//    TC_SpinLock			_schedMutex;
 	TC_ThreadMutex 			_schedMutex;
 
 	/**

+ 18 - 4
servant/servant/CommunicatorFactory.h

@@ -40,10 +40,24 @@ public:
      */
     ~CommunicatorFactory(){};
 
+	/**
+	 * 是否已经存在通信器
+	 * @param name
+	 * @return
+	 */
+	bool hasCommunicator(const string& name = "default")
+	{
+		TC_LockT<TC_ThreadRecMutex> lock(*this);
+
+		auto it = _comms.find(name);
+
+		return it != _comms.end();
+	}
+
     /**
      * 获取CommunicatorPtr对象
      * @param name
-     * @return ServantPrx
+     * @return CommunicatorPtr
      */
     CommunicatorPtr getCommunicator(const string& name = "default")
     {
@@ -61,10 +75,10 @@ public:
     }
     
      /**
-     * 获取CommunicatorPtr对象 
+     * 获取CommunicatorPtr对象, 没有则创建
      * @param conf 
-     * @param name
-     * @return ServantPrx
+     * @param name: 通信器名称
+     * @return CommunicatorPtr
      */
     CommunicatorPtr getCommunicator(TC_Config& conf, const string& name = "default")
     {

+ 6 - 0
servant/servant/Current.h

@@ -284,6 +284,12 @@ public:
 	 * @return
 	 */
 	bool connectionExists() const;
+
+	/**
+	 *
+	 * @return
+	 */
+	const string &moduleName() const;
 protected:
 
     friend class ServantHandle;

+ 7 - 1
servant/servant/Message.h

@@ -106,7 +106,7 @@ struct ThreadPrivateData
      */
     bool           _hash        = false;                            //是否普通取模hash
     bool           _conHash     = false;                          //是否一致性hash
-    uint32_t        _hashCode    = 0;                        //hash值
+    uint32_t       _hashCode    = 0;                        //hash值
 
     /**
      * 染色信息
@@ -185,6 +185,12 @@ struct ReqMessage : public TC_HandleBase
      */
     void init(CallType eCallType, ServantProxy *proxy);
 
+	/**
+	 * 发送的模块名称
+	 * @return
+	 */
+	const string &moduleName();
+
     ReqStatus                   eStatus;        //调用的状态
     CallType                    eType;          //调用类型
     bool                        bFromRpc        = false;       //是否是第三方协议的rcp_call,缺省为false

+ 7 - 7
tools/tars2cpp/tars2cpp.cpp

@@ -1410,7 +1410,7 @@ string Tars2Cpp::generateDispatchAsync(const OperationPtr& pPtr, const string& c
         DEL_TAB;
         s << TAB << "}" << endl;
 
-        s << TAB << "TARS_TRACE(_pSptd_->getTraceKey(ServantProxyThreadData::TraceContext::EST_CR), TRACE_ANNOTATION_CR, \"\", ServerConfig::Application + \".\" + ServerConfig::ServerName, \"" << pPtr->getId() << "\", 0, _trace_param_, \"\");" << endl;
+        s << TAB << "TARS_TRACE(_pSptd_->getTraceKey(ServantProxyThreadData::TraceContext::EST_CR), TRACE_ANNOTATION_CR, \"\", _msg_->moduleName(), \"" << pPtr->getId() << "\", 0, _trace_param_, \"\");" << endl;
         DEL_TAB;
         s << TAB << "}" << endl;
         s << endl;
@@ -1784,7 +1784,7 @@ string Tars2Cpp::generateServantDispatch(const OperationPtr& pPtr, const string&
         DEL_TAB;
         s << TAB << "}" << endl;
 
-        s << TAB << "TARS_TRACE(_pSptd_->getTraceKey(ServantProxyThreadData::TraceContext::EST_SR), TRACE_ANNOTATION_SR, \"\", ServerConfig::Application + \".\" + ServerConfig::ServerName, \"" << pPtr->getId() << "\", 0, _trace_param_, \"\");" << endl;
+        s << TAB << "TARS_TRACE(_pSptd_->getTraceKey(ServantProxyThreadData::TraceContext::EST_SR), TRACE_ANNOTATION_SR, \"\", _current->moduleName(), \"" << pPtr->getId() << "\", 0, _trace_param_, \"\");" << endl;
         DEL_TAB;
         s << TAB << "}" << endl;
         s << endl;
@@ -1962,7 +1962,7 @@ string Tars2Cpp::generateServantDispatch(const OperationPtr& pPtr, const string&
         s << TAB << "_trace_param_ = " << G_TRACE_PARAM_OVER_MAX_LEN << ";" << endl;
         DEL_TAB;
         s << TAB << "}" << endl;
-        s << TAB << "TARS_TRACE(_pSptd_->getTraceKey(ServantProxyThreadData::TraceContext::EST_SS), TRACE_ANNOTATION_SS, \"\", ServerConfig::Application + \".\" + ServerConfig::ServerName, \"" << pPtr->getId() << "\", 0, _trace_param_, \"\");" << endl;
+        s << TAB << "TARS_TRACE(_pSptd_->getTraceKey(ServantProxyThreadData::TraceContext::EST_SS), TRACE_ANNOTATION_SS, \"\", _current->moduleName(), \"" << pPtr->getId() << "\", 0, _trace_param_, \"\");" << endl;
         DEL_TAB;
         s << TAB << "}" << endl;
         s << endl;
@@ -2132,7 +2132,7 @@ string Tars2Cpp::generateHAsync(const OperationPtr& pPtr, const string& cn) cons
         s << TAB << "_trace_param_ = " << G_TRACE_PARAM_OVER_MAX_LEN << ";" << endl;
         DEL_TAB;
         s << TAB << "}" << endl;
-        s << TAB << "TARS_TRACE(_pSptd_->getTraceKey(ServantProxyThreadData::TraceContext::EST_CS), TRACE_ANNOTATION_CS, ServerConfig::Application + \".\" + ServerConfig::ServerName, tars_name(), \"" << pPtr->getId() << "\", 0, _trace_param_, \"\");" << endl;
+        s << TAB << "TARS_TRACE(_pSptd_->getTraceKey(ServantProxyThreadData::TraceContext::EST_CS), TRACE_ANNOTATION_CS, this->tars_communicator()->clientConfig().ModuleName, tars_name(), \"" << pPtr->getId() << "\", 0, _trace_param_, \"\");" << endl;
         DEL_TAB;
         s << TAB << "}" << endl;
     }
@@ -2315,7 +2315,7 @@ string Tars2Cpp::generateH(const OperationPtr& pPtr, bool bVirtual, const string
             s << TAB << "_trace_param_ = " << G_TRACE_PARAM_OVER_MAX_LEN << ";" << endl;
             DEL_TAB;
             s << TAB << "}" << endl;
-            s << TAB << "TARS_TRACE(_pSptd_->getTraceKey(ServantProxyThreadData::TraceContext::EST_CS), TRACE_ANNOTATION_CS, ServerConfig::Application + \".\" + ServerConfig::ServerName, tars_name(), \"" << pPtr->getId() << "\", 0, _trace_param_, \"\");" << endl;
+            s << TAB << "TARS_TRACE(_pSptd_->getTraceKey(ServantProxyThreadData::TraceContext::EST_CS), TRACE_ANNOTATION_CS, this->tars_communicator()->clientConfig().ModuleName, tars_name(), \"" << pPtr->getId() << "\", 0, _trace_param_, \"\");" << endl;
             DEL_TAB;
             s << TAB << "}" << endl;
             s << endl;
@@ -2394,7 +2394,7 @@ string Tars2Cpp::generateH(const OperationPtr& pPtr, bool bVirtual, const string
                 s << TAB << "_trace_param_ = " << G_TRACE_PARAM_OVER_MAX_LEN << ";" << endl;
                 DEL_TAB;
                 s << TAB << "}" << endl;
-                s << TAB << "TARS_TRACE(_pSptd_->getTraceKey(ServantProxyThreadData::TraceContext::EST_CR), TRACE_ANNOTATION_CR, ServerConfig::Application + \".\" + ServerConfig::ServerName, tars_name(), \"" << pPtr->getId() << "\", 0, _trace_param_, \"\");" << endl;
+                s << TAB << "TARS_TRACE(_pSptd_->getTraceKey(ServantProxyThreadData::TraceContext::EST_CR), TRACE_ANNOTATION_CR, this->tars_communicator()->clientConfig().ModuleName, tars_name(), \"" << pPtr->getId() << "\", 0, _trace_param_, \"\");" << endl;
                 DEL_TAB;
                 s << TAB << "}" << endl;
                 s << endl;
@@ -2583,7 +2583,7 @@ string Tars2Cpp::generateH(const OperationPtr& pPtr, bool bVirtual, const string
             s << TAB << "_trace_param_ = " << G_TRACE_PARAM_OVER_MAX_LEN << ";" << endl;
             DEL_TAB;
             s << TAB << "}" << endl;
-            s << TAB << "TARS_TRACE(_current_->getTraceKey(), TRACE_ANNOTATION_SS, \"\", ServerConfig::Application + \".\" + ServerConfig::ServerName, \"" << pPtr->getId() << "\", 0, _trace_param_, \"\");" << endl;
+            s << TAB << "TARS_TRACE(_current_->getTraceKey(), TRACE_ANNOTATION_SS, \"\", _current_->getServantHandle()->getApplication()->getThisCommunicator()->clientConfig().ModuleName, \"" << pPtr->getId() << "\", 0, _trace_param_, \"\");" << endl;
             DEL_TAB;
             s << TAB << "}" << endl;
             s << endl;

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 177 - 166
tools/tarsgrammar/tars.tab.cpp


+ 18 - 18
tools/tarsparse/tars.lex.cpp

@@ -510,7 +510,7 @@ int yy_flex_debug = 0;
 #define YY_MORE_ADJ 0
 #define YY_RESTORE_YY_MORE_OFFSET
 char *yytext;
-#line 1 "/media/psf/centos/Tars/framework/tarscpp/tools/tarsgrammar/tars.l"
+#line 1 "/tars/framework/tarscpp/tools/tarsgrammar/tars.l"
 /**
  * Tencent is pleased to support the open source community by making Tars available.
  *
@@ -526,7 +526,7 @@ char *yytext;
  * CONDITIONS OF ANY KIND, either express or implied. See the License for the 
  * specific language governing permissions and limitations under the License.
  */
-#line 20 "/media/psf/centos/Tars/framework/tarscpp/tools/tarsgrammar/tars.l"
+#line 20 "/tars/framework/tarscpp/tools/tarsgrammar/tars.l"
 #include <map>
 #include <string>
 #include <sstream>
@@ -775,7 +775,7 @@ YY_DECL
 		}
 
 	{
-#line 67 "/media/psf/centos/Tars/framework/tarscpp/tools/tarsgrammar/tars.l"
+#line 67 "/tars/framework/tarscpp/tools/tarsgrammar/tars.l"
 
 
 #line 782 "tars.lex.cpp"
@@ -847,12 +847,12 @@ do_action:	/* This label is used only to access EOF actions. */
 
 case 1:
 YY_RULE_SETUP
-#line 69 "/media/psf/centos/Tars/framework/tarscpp/tools/tarsgrammar/tars.l"
+#line 69 "/tars/framework/tarscpp/tools/tarsgrammar/tars.l"
 { BEGIN(INCL); }
 	YY_BREAK
 case 2:
 YY_RULE_SETUP
-#line 71 "/media/psf/centos/Tars/framework/tarscpp/tools/tarsgrammar/tars.l"
+#line 71 "/tars/framework/tarscpp/tools/tarsgrammar/tars.l"
 {
     if ( include_file_stack_ptr >= MAX_INCLUDE_DEPTH )
     {
@@ -885,7 +885,7 @@ YY_RULE_SETUP
 	YY_BREAK
 case YY_STATE_EOF(INITIAL):
 case YY_STATE_EOF(INCL):
-#line 101 "/media/psf/centos/Tars/framework/tarscpp/tools/tarsgrammar/tars.l"
+#line 101 "/tars/framework/tarscpp/tools/tarsgrammar/tars.l"
 {
     --include_file_stack_ptr;
     if ( include_file_stack_ptr < 0 )
@@ -904,14 +904,14 @@ case YY_STATE_EOF(INCL):
 	YY_BREAK
 case 3:
 YY_RULE_SETUP
-#line 117 "/media/psf/centos/Tars/framework/tarscpp/tools/tarsgrammar/tars.l"
+#line 117 "/tars/framework/tarscpp/tools/tarsgrammar/tars.l"
 {
     return TARS_SCOPE_DELIMITER;
 }
 	YY_BREAK
 case 4:
 YY_RULE_SETUP
-#line 121 "/media/psf/centos/Tars/framework/tarscpp/tools/tarsgrammar/tars.l"
+#line 121 "/tars/framework/tarscpp/tools/tarsgrammar/tars.l"
 {
     // C++ comment
     bool e = false;
@@ -932,7 +932,7 @@ YY_RULE_SETUP
 	YY_BREAK
 case 5:
 YY_RULE_SETUP
-#line 139 "/media/psf/centos/Tars/framework/tarscpp/tools/tarsgrammar/tars.l"
+#line 139 "/tars/framework/tarscpp/tools/tarsgrammar/tars.l"
 {
     // C comment
     bool e = false;
@@ -983,7 +983,7 @@ YY_RULE_SETUP
 	YY_BREAK
 case 6:
 YY_RULE_SETUP
-#line 187 "/media/psf/centos/Tars/framework/tarscpp/tools/tarsgrammar/tars.l"
+#line 187 "/tars/framework/tarscpp/tools/tarsgrammar/tars.l"
 {
     StringGrammarPtr ident  = new StringGrammar;
     ident->v            = yytext;
@@ -994,7 +994,7 @@ YY_RULE_SETUP
 case 7:
 /* rule 7 can match eol */
 YY_RULE_SETUP
-#line 194 "/media/psf/centos/Tars/framework/tarscpp/tools/tarsgrammar/tars.l"
+#line 194 "/tars/framework/tarscpp/tools/tarsgrammar/tars.l"
 {
     StringGrammarPtr ident  = new StringGrammar;
     ident->v            = yytext;
@@ -1007,7 +1007,7 @@ YY_RULE_SETUP
 	YY_BREAK
 case 8:
 YY_RULE_SETUP
-#line 204 "/media/psf/centos/Tars/framework/tarscpp/tools/tarsgrammar/tars.l"
+#line 204 "/tars/framework/tarscpp/tools/tarsgrammar/tars.l"
 {
     StringGrammarPtr str = new StringGrammar;
     bool e = false;
@@ -1122,7 +1122,7 @@ YY_RULE_SETUP
 	YY_BREAK
 case 9:
 YY_RULE_SETUP
-#line 316 "/media/psf/centos/Tars/framework/tarscpp/tools/tarsgrammar/tars.l"
+#line 316 "/tars/framework/tarscpp/tools/tarsgrammar/tars.l"
 {
     errno = 0;
     IntergerGrammarPtr ptr = new IntergerGrammar;
@@ -1147,7 +1147,7 @@ YY_RULE_SETUP
 	YY_BREAK
 case 10:
 YY_RULE_SETUP
-#line 338 "/media/psf/centos/Tars/framework/tarscpp/tools/tarsgrammar/tars.l"
+#line 338 "/tars/framework/tarscpp/tools/tarsgrammar/tars.l"
 {
     errno = 0;
     FloatGrammarPtr ptr = new FloatGrammar;
@@ -1182,7 +1182,7 @@ YY_RULE_SETUP
 case 11:
 /* rule 11 can match eol */
 YY_RULE_SETUP
-#line 369 "/media/psf/centos/Tars/framework/tarscpp/tools/tarsgrammar/tars.l"
+#line 369 "/tars/framework/tarscpp/tools/tarsgrammar/tars.l"
 {
     if(yytext[0] == '\n')
     {
@@ -1192,7 +1192,7 @@ YY_RULE_SETUP
 	YY_BREAK
 case 12:
 YY_RULE_SETUP
-#line 376 "/media/psf/centos/Tars/framework/tarscpp/tools/tarsgrammar/tars.l"
+#line 376 "/tars/framework/tarscpp/tools/tarsgrammar/tars.l"
 {
     if(yytext[0] < 32 || yytext[0] > 126)
     {
@@ -1211,7 +1211,7 @@ YY_RULE_SETUP
 	YY_BREAK
 case 13:
 YY_RULE_SETUP
-#line 392 "/media/psf/centos/Tars/framework/tarscpp/tools/tarsgrammar/tars.l"
+#line 392 "/tars/framework/tarscpp/tools/tarsgrammar/tars.l"
 ECHO;
 	YY_BREAK
 #line 1218 "tars.lex.cpp"
@@ -2229,7 +2229,7 @@ void yyfree (void * ptr )
 
 #define YYTABLES_NAME "yytables"
 
-#line 392 "/media/psf/centos/Tars/framework/tarscpp/tools/tarsgrammar/tars.l"
+#line 392 "/tars/framework/tarscpp/tools/tarsgrammar/tars.l"
 
 
 

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 177 - 166
tools/tarsparse/tars.tab.cpp


+ 2 - 4
tools/tarsparse/tars.tab.hpp

@@ -1,4 +1,4 @@
-/* A Bison parser, made by GNU Bison 3.8.2.  */
+/* A Bison parser, made by GNU Bison 3.7.5.  */
 
 /* Bison interface for Yacc-like parsers in C
 
@@ -16,7 +16,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 /* As a special exception, you may create a larger work that contains
    part or all of the Bison parser skeleton and distribute that work
@@ -99,8 +99,6 @@ typedef int YYSTYPE;
 
 extern YYSTYPE yylval;
 
-
 int yyparse (void);
 
-
 #endif /* !YY_YY_TARS_TAB_HPP_INCLUDED  */

Daži faili netika attēloti, jo izmaiņu fails ir pārāk liels