Browse Source

#IQRV #comment [Chromium] relink部分检测无服务的实体, O(1)时间

陈良瑜80374463 3 years ago
parent
commit
2b5bb09bd7

+ 7 - 0
Module/mod_chromium/CStructureInterpreter.cpp

@@ -53,7 +53,9 @@ namespace Chromium {
 		std::string strClassName = pClass->Attribute("name");
 		std::map<int, CMedthodInterface> functionInterface;
 		this->loadFunctionInterface(functionInterface, pClass);
+		m_inServiceEntity.insert(strEntityName);
 		this->mMethodStructureMap.insert(std::pair<std::string, std::map<int, CMedthodInterface>>(strEntityName.append(strClassName), functionInterface));
+		
 	}
 
 
@@ -164,6 +166,11 @@ namespace Chromium {
 		return &(iter->second);
 	}
 
+	bool CStructureInterpreter::checkEntityInservice(std::string entityName)
+	{
+		return m_inServiceEntity.find(entityName) != m_inServiceEntity.end();
+	}
+
 	int CStructureInterpreter::convertStringToInt(std::string s) {
 		int val;
 		std::strstream ss;

+ 3 - 0
Module/mod_chromium/CStructureInterpreter.h

@@ -2,6 +2,7 @@
 #define CStructureInterpreter_h
 
 #include <map>
+#include <unordered_set>
 #include <vector>
 #include <string>
 #include "CMethodInterface.h"
@@ -13,6 +14,7 @@ namespace Chromium {
 		explicit CStructureInterpreter(const char* path);
 		CMedthodInterface* getFunctionInterface(char* entityName, char* className, int methodID);
 		std::vector<CMedthodInterface>* getAllMessageInterface(const char* entityName);
+		bool checkEntityInservice(std::string entityName);
 	private:
 		// methods 
 		void getAllFiles();
@@ -28,6 +30,7 @@ namespace Chromium {
 		std::map<std::string, std::vector<CMedthodInterface>> mMessageStructureMap;
 		std::string mPathOfXmls;
 		std::vector<std::string> mFiles;
+		std::unordered_set<std::string> m_inServiceEntity;
 	};
 }
 

+ 17 - 9
Module/mod_chromium/CWSCodec.cpp

@@ -56,6 +56,14 @@ namespace Chromium {
 		return &obj;
 	}
 
+	bool CWSCodec::checkEntityHasService(std::string entityName)
+	{
+		if (!mInterpreter)
+			return true;//默认有service
+
+		return mInterpreter->checkEntityInservice(entityName);
+	}
+
 	void CWSCodec::setEntityHandler(CSmartPointer<IEntityFunction> p) {
 		this->m_pFunc = p;
 	}
@@ -688,7 +696,7 @@ namespace Chromium {
 				CSimpleStringA bussinessId = "ChromiumAutoGen";
 				CSimpleStringA traceId = uuid4_generate(32).c_str();
 				CSimpleStringA spanId = uuid4_generate(16).c_str();
-				CSimpleStringA parentSpanId = "0000000000000000";
+				CSimpleStringA parentSpanId = "0";
 				WriteT(data, bussinessId, &wpos, &capacity);//为适配silverlight,默认写入就是unicode
 				WriteT(data, traceId, &wpos, &capacity);
 				WriteT(data, spanId, &wpos, &capacity);
@@ -808,7 +816,7 @@ namespace Chromium {
 			CSimpleStringA bussinessId = "ChromiumAutoGen";
 			CSimpleStringA traceId = uuid4_generate(32).c_str();
 			CSimpleStringA spanId = uuid4_generate(16).c_str();
-			CSimpleStringA parentSpanId = "0000000000000000";
+			CSimpleStringA parentSpanId = "0";
 			WriteT(data, bussinessId, wpos, capacity);//为适配silverlight,默认写入就是unicode
 			WriteT(data, traceId, wpos, capacity);
 			WriteT(data, spanId, wpos, capacity);
@@ -929,7 +937,7 @@ namespace Chromium {
 			CSimpleStringA bussinessId = "ChromiumAutoGen";
 			CSimpleStringA traceId = uuid4_generate(32).c_str();
 			CSimpleStringA spanId = uuid4_generate(16).c_str();
-			CSimpleStringA parentSpanId = "0000000000000000";
+			CSimpleStringA parentSpanId = "0";
 			WriteT(data, bussinessId, wpos, capacity);//为适配silverlight,默认写入就是unicode
 			WriteT(data, traceId, wpos, capacity);
 			WriteT(data, spanId, wpos, capacity);
@@ -1213,10 +1221,10 @@ namespace Chromium {
 			}
 			else if (it->mType == "array_int")
 			{
-				DbgEx("array int -> ");
+				//DbgEx("array int -> ");
 				int len = 0;
 				if (GetCJsonArraySize(js, it->mName.c_str(), len, errmsg)) {
-					DbgEx("array int -> true len = %d", len);
+					//DbgEx("array int -> true len = %d", len);
 					WriteT(data, len, wpos, capacity);
 					unsigned int d = 0;
 					for (int i = 0; i < len; ++i) {
@@ -1232,10 +1240,10 @@ namespace Chromium {
 			}
 			else if (it->mType == "array_uint")
 			{
-				DbgEx("array uint -> ");
+				//DbgEx("array uint -> ");
 				int len = 0;
 				if (GetCJsonArraySize(js, it->mName.c_str(), len, errmsg)) {
-					DbgEx("array int -> true len = %d", len);
+					//DbgEx("array int -> true len = %d", len);
 					WriteT(data, len, wpos, capacity);
 					unsigned int d = 0;
 					for (int i = 0; i < len; ++i) {
@@ -1251,10 +1259,10 @@ namespace Chromium {
 			}
 			else if (it->mType == "array_string")
 			{
-				DbgEx("array string -> ");
+				//DbgEx("array string -> ");
 				int len = 0;
 				if (GetCJsonArraySize(js, it->mName.c_str(), len, errmsg)) {
-					DbgEx("array string -> true len = %d", len);
+					//DbgEx("array string -> true len = %d", len);
 					WriteT(data, len, wpos, capacity);
 					CSimpleStringA d = "";
 					for (int i = 0; i < len; ++i) {

+ 2 - 0
Module/mod_chromium/CWSCodec.h

@@ -30,6 +30,8 @@ namespace Chromium {
 
 		std::string GetEntityName(std::string strJson);
 		std::string GetClassName(std::string strJson);
+
+		bool checkEntityHasService(std::string entityName);
 	private:
 		void DeserializeRequestAck(CMessage& msg, std::map<int, entity_def_struct>::iterator& it, int& rpos, cJSON* ret);
 		void DeserializeEvent(CMessage& msg, std::vector<CMedthodInterface>* list, int& rpos, cJSON* ret);

+ 24 - 36
Module/mod_chromium/CWebsocketServer.cpp

@@ -130,9 +130,8 @@ namespace Chromium {
 			m_esm->updateBeginSessionTime(entityName);
 			WriteToFramework(sessionBuf);
 		}
-		else {
+		else
 			DbgEx("Already begin session in 5s, %s", entityName.c_str());
-		}
 	}
 
 	void CWebsocketServer::WriteToFramework(CMessage* msg)
@@ -281,9 +280,8 @@ namespace Chromium {
 			}
 			return;
 		}
-		else if (ret.first == BeginSession) {
+		else if (ret.first == BeginSession)
 			storeEntityWithCLass(m_serializer->GetEntityName(payload), m_serializer->GetClassName(payload));
-		}
 
 		// Try to manage entity session
 		RequestProcessType processType = this->m_esm->RequestProcess(p, m_serializer->GetEntityName(payload), (long)hdl.lock().get());
@@ -294,7 +292,7 @@ namespace Chromium {
 			DbgEx("do PROCESS_NOTHING");
 			return;
 		case Chromium::PROCESS_SEND:
-			DbgEx("do PROCESS_SEND");
+			//DbgEx("do PROCESS_SEND");
 			if (nullptr != p)
 				WriteToFramework(p);
 			break;
@@ -340,12 +338,15 @@ namespace Chromium {
 		if (t_hdlArr.end() == t_hdlArr.find(hdlPos))
 			t_hdlArr[hdlPos] = pos++;
 
+
 		auto msgHandleFun = [&]() {
+			//DbgEx("CWebsocketServer -> message_handler");
 			std::string payload = msg->get_payload();
 			// proto convert here
 #if (defined _WIN32 || defined _WIN64)
 			payload = utf8_to_string(payload);//windows web utf8, terminal gbk
 #endif
+
 			std::shared_ptr<cJSON> pJson(cJSON_Parse(payload.c_str()), [](cJSON* p) {
 				if (nullptr != p)
 					cJSON_Delete(p);
@@ -451,46 +452,22 @@ namespace Chromium {
 
 		auto checkEntityIsNoStart = [&](std::string entityName) -> bool
 		{
-			/*
-			enum EntityStateEnum
-			{
-				EntityState_NoStart = 0,		//no start before
-				EntityState_Starting,			//Entity is doing initial
-				EntityState_Idle,				//after started succeed,and have no work
-				EntityState_Busy,				//Doing Request-Answer,timing,and Pausing or coninuing work
-				EntityState_Pause,			//Pause state
-				EntityState_UnLoading,		//doing cleanning after trigger close
-				EntityState_Lost,				//Entity block not respond or exception
-				EntityState_Close,				//After close,start before
-				EntityState_Killed,				//The entity terminated as block state
-			};
-
-			*/
 			CSmartPointer<IEntityFunction> spFunc = m_pEntity->GetFunction();
 			LOG_ASSERT(spFunc != NULL);
 			CEntityStaticInfo StaticInfo;
 			CEntityRunInfo RunInfo;
-			bool result(false);
 
 			do {
+				if (Error_Succeed != spFunc->GetEntityStaticInfo(entityName.c_str(), StaticInfo))
+					break;
 
-				ErrorCodeEnum ec = spFunc->GetEntityStaticInfo(entityName.c_str(), StaticInfo);
-				if (ec != Error_Succeed) {
-					result = (ec == Error_NotExist);
-                    break;
-				}
-
-				ec = spFunc->GetEntityRunInfo(entityName.c_str(), RunInfo);
-                if (ec != Error_Succeed) {
-                    result = (ec == Error_NotExist);
-                    break;
-                }
-
-				result = (RunInfo.eState == EntityState_NoStart);
+				if (Error_Succeed != spFunc->GetEntityRunInfo(entityName.c_str(), RunInfo))
+					break;
 
+				return RunInfo.eState == EntityState_NoStart;
 			} while (false);
 
-			return result;
+			return true;
 		};
 
 
@@ -503,6 +480,7 @@ namespace Chromium {
 				boost::lock_guard<boost::mutex> lock(m_dealMsgLock);
 				std::string breakEntityStr = "";
 				std::string noStartEntity = "";
+				std::string noServerEntity = "";
 #if (defined _WIN32 || defined _WIN64)
 				for each (auto it in unlinkArr)
 #else
@@ -517,6 +495,16 @@ namespace Chromium {
 							noStartEntity.append("|").append(it);
 						continue;
 					}
+
+					if (!CWSCodec::getInstance()->checkEntityHasService(it))
+					{
+						if (noServerEntity.empty())
+							noServerEntity.append(it);
+						else
+							noServerEntity.append("|").append(it);
+						continue;
+					}
+					
 						
 
 					auto ret = getEntityClass(it);
@@ -532,7 +520,7 @@ namespace Chromium {
 						DbgEx("unable find class of entity %s", it.c_str());
 				}
 				if (!breakEntityStr.empty())
-					DbgEx("try to relink entity : %s, noStartEntity: %s", breakEntityStr.c_str(), noStartEntity.c_str());
+					DbgEx("try to relink entity : %s, noStartEntity: %s, noServerEntity: %s", breakEntityStr.c_str(), noStartEntity.c_str(), noServerEntity.c_str());
 			}
 			catch (...)
 			{