Browse Source

Z991239-5690 #comment feat: 告警实体集中配置清理优化

Signed-Off-By: commit-hook
刘文涛80174520 1 year ago
parent
commit
8c1f52f0d6
1 changed files with 26 additions and 187 deletions
  1. 26 187
      Module/mod_alarm/AlarmFSM.cpp

+ 26 - 187
Module/mod_alarm/AlarmFSM.cpp

@@ -214,7 +214,7 @@ AlarmFSM::AlarmFSM() : m_pConnection(NULL),m_b_alarmstate(FALSE)
 	m_iSucc=0;//累计发送成功总次数
 
 	m_CenterModel=2;
-	m_maxResendTime=60;
+	m_maxResendTime=120;
 	m_eachSum=0;
 	m_initAlarm=false;
 
@@ -269,9 +269,16 @@ ErrorCodeEnum AlarmFSM::OnInit()
 		m_CenterModel = 2;
 		DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setAPI("OnInit")("init use default value CenterModel=2");
 
-		Error = spConfig->ReadConfigValueInt("Alarm", "maxResendTime", m_maxResendTime);
+		int maxResendTime = 120;
+		Error = spConfig->ReadConfigValueInt("Alarm", "maxResendTime", maxResendTime);
 		if(Error==Error_Succeed){
-			DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("OnInit")("init read CenterSetting.ini maxResendTime=%d",m_maxResendTime);
+			if (maxResendTime > 0) {
+				m_maxResendTime = maxResendTime;
+			}
+			else {
+				m_maxResendTime = 120;
+			}
+			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("OnInit")("init read CenterSetting.ini maxResendTime=%d", m_maxResendTime);
 		}else{
 			DbgWithLink(LOG_LEVEL_WARN,LOG_TYPE_SYSTEM).setAPI("OnInit")("init read CenterSetting.ini maxResendTime failed");
 		}
@@ -309,10 +316,6 @@ ErrorCodeEnum AlarmFSM::OnInit()
 		m_nDealWarningTime = 10;
 	}
 
-	if(m_maxResendTime <= 0){
-		m_maxResendTime ==60;
-	}
-
 	if(m_branchNo.IsNullOrEmpty()){
 		m_branchNo = "000";//默认是000总行分行号
 	}
@@ -330,48 +333,13 @@ void AlarmFSM::s0_on_entry()
 {
 	if(!m_initAlarm){
 		m_initAlarm=true;
-		//添加集中配置参数读取和判断走分行还是总行
-		if(m_CenterModel==0){
-			LogWarn(Severity_Low,Error_Exception,WARN_ALARM_START_OLD_MODE,CSimpleStringA::Format("init alarm old model,model=%d",m_CenterModel));
-		}else{
-			LogWarn(Severity_Low,Error_Exception,WARN_ALARM_START_NEW_MODE,CSimpleStringA::Format("init alarm new model,model=%d",m_CenterModel));
-		}
-	}
-	if(m_CenterModel==0){
-		//旧模式
-		//改造为先判断是否不为空,再创建连接,减少空连接数
-		if(m_NewUploading_alarm.empty()){
-			//Dbg("no warn,wait 3s");
-			//DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("no warn,wait 3s");
-			ScheduleTimer(1, 3000);// try 3 seconds later
-		}else{
-			if (!m_pConnection) 
-			{
-				m_pConnection = new AlarmConnection(m_pEntity, this);
-				if (m_pConnection->ConnectFromCentralSetting()&& m_pConnection->IsConnectionOK())
-				{
-					//创建成功
-				}else{
-					//创建失败
-					//Dbg("connect server fail,config or Servers Error!");
-					DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("connect server fail,config or Servers Error!");
-					closeClientConn();//断开连接
-				}	
-			}
-			if (!m_pConnection) 
-			{
-				ScheduleTimer(1, 10000); // try 10 seconds later
-			}
-			else 
-			{
-				PostEventLIFO(new FSMEvent(USER_EVT_JMP_ALARMUP));//跳转S1状态
-			}
-		}
-	}else{
-		//新模式
-		PostEventLIFO(new FSMEvent(USER_EVT_JMP_NEW_ALARM));//跳转新模式发送
+		LogWarn(Severity_Low,Error_Exception,WARN_ALARM_START_NEW_MODE,CSimpleStringA::Format("init alarm new model,model=%d",m_CenterModel));
 	}
 
+	//新模式
+	PostEventLIFO(new FSMEvent(USER_EVT_JMP_NEW_ALARM));//跳转新模式发送
+
+
 }
 
 void AlarmFSM::s0_on_exit()
@@ -385,10 +353,8 @@ unsigned int AlarmFSM::s0_on_event( FSMEvent* event )
 	if (event->iEvt == EVT_TIMER) 
 	{
 		if(event->param1 == 1){
-			//改造为先判断是否不为空,再创建连接,减少空连接数
 			if(m_NewUploading_alarm.empty()){
-				//Dbg("no warn,wait 3s");
-				//DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("no warn,wait 3s");
+
 				ScheduleTimer(1, 3000);// try 3 seconds later
 			}else{
 				if (!m_pConnection) 
@@ -413,11 +379,6 @@ unsigned int AlarmFSM::s0_on_event( FSMEvent* event )
 				}
 			}
 		}else if(event->param1 == 2){
-			//新模式
-			//if(m_NewUploading_alarm.empty()&&m_unSendAlarm.IsNullOrEmpty()){
-			//	//DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("no warn,wait 3s");
-			//	ScheduleTimer(2, 3000);// try 3 seconds later
-			//}else{
 				//开始启动调用发送线程
 				Task::SendAlarmTask* alarmTask = new Task::SendAlarmTask(this);
 				ErrorCodeEnum rc = m_pEntity->GetFunction()->PostThreadPoolTask(alarmTask);
@@ -425,111 +386,25 @@ unsigned int AlarmFSM::s0_on_event( FSMEvent* event )
 					DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("s0 create SendAlarmTask is fail,%d",(int)rc);
 					ScheduleTimer(2, 10*1000);//等待一段时间
 				}
-			//}
+
 		}
 	}else if (event->iEvt == USER_EVT_JMP_NEW_ALARM){
-		//if(m_NewUploading_alarm.empty()&&m_unSendAlarm.IsNullOrEmpty()){
-		//	//DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("no warn,wait 3s");
-		//	ScheduleTimer(2, 3000);// try 3 seconds later
-		//}else{
-			//开始启动调用发送线程
-			Task::SendAlarmTask* alarmTask = new Task::SendAlarmTask(this);
-			ErrorCodeEnum rc = m_pEntity->GetFunction()->PostThreadPoolTask(alarmTask);
-			if(rc!=Error_Succeed){
-				DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("s0 create SendAlarmTask is fail,%d",(int)rc);
-				ScheduleTimer(2, 10*1000);//等待一段时间
-			}
-		//}
+
+		//开始启动调用发送线程
+		Task::SendAlarmTask* alarmTask = new Task::SendAlarmTask(this);
+		ErrorCodeEnum rc = m_pEntity->GetFunction()->PostThreadPoolTask(alarmTask);
+		if(rc!=Error_Succeed){
+			DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("s0 create SendAlarmTask is fail,%d",(int)rc);
+			ScheduleTimer(2, 10*1000);//等待一段时间
+		}
 	}
-	//else if (event->iEvt == USER_EVT_SEND_ALARM){
-	//	SendAlarmEvent* pEvent = (SendAlarmEvent*)event;
-	//	if(pEvent->isSucc){
-	//		//成功
-	//		DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("send alarm statistic m_iRec=%d , m_iThrow=%d , UnSend=%d , m_iSucc=%d , m_iFail=%d",m_iRec,m_iThrow,m_NewUploading_alarm.size(),m_iSucc,m_iFail);
-	//		if(!m_NewUploading_alarm.empty()){
-	//			ScheduleTimer(2,2000);
-	//		}else{
-	//			ScheduleTimer(2,3000);
-	//		}
-	//	}else{
-	//		//失败
-	//		//超过未发送成功的告警时间间隔,丢弃告警信息
-	//		CSmallDateTime endTime = CSmallDateTime::GetNow();
-	//		if(((DWORD)endTime-(DWORD)m_sendBeginTime)>m_maxResendTime){
-	//			m_unSendAlarm="";//置为空
-	//			m_iFail = m_iFail+ m_eachSum ;//发送失败
-	//			LogWarn(Severity_Low,Error_Exception,WARN_ALARM_SEND_FAIL,CSimpleStringA::Format("throw away alarm num= %d,m_iFail=%d",m_eachSum,m_iFail));
-	//			m_eachSum =0;//清空批次数量
-	//			m_sendBeginTime = CSmallDateTime::GetNow();
-	//			DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("send alarm statistic m_iRec=%d , m_iThrow=%d , UnSend=%d , m_iSucc=%d , m_iFail=%d",m_iRec,m_iThrow,m_NewUploading_alarm.size(),m_iSucc,m_iFail);
-	//		}
-	//		ScheduleTimer(2,10000);
-	//	}
-	//}
+
 	return 0;
 }
 
 
 void AlarmFSM::s1_on_entry()
 {
-	//connect
-	//if (!m_pConnection) 
-	//{
-	//	m_pConnection = new AlarmConnection(m_pEntity, this);
-	//	if (!m_pConnection->ConnectFromCentralSetting())
-	//	{
-	//		Dbg("connect server fail,config or Servers Error!");
-	//		PostEventLIFO(new FSMEvent(USER_EVT_DISCONNECT));
-	//		return;
-	//	}	
-	//}
-
-	//if (m_pConnection->IsConnectionOK()) //upload
-	//{
-	//	EnterCriticalSection(&cs);
-	//	alarm_t*alarm = list_first_entry(&m_uploading_alarm,alarm_t,entry);
-	//	if (alarm == NULL)
-	//	{
-	//		Dbg("get alarm error");		
-	//		PostEventLIFO(new FSMEvent(USER_EVT_JMP_RELEASE));
-	//	}
-
-	//	m_pConnection->SendAlarm(alarm);
-
-	//	//add by zl 20180306, 添加到历史告警列表
-	//	add_UploadedAlarm(alarm);	
-
-	//	list_del(&alarm->entry);
-	//	//delete alarm->Description;
-	//	//delete alarm->EntityName;
-	//	//delete alarm->SN;
-	//	//delete alarm;
-	//	//因使用malloc创建内存,用free释放
-	//	free(alarm->Description);
-	//	alarm->Description=NULL;
-
-	//	free(alarm->EntityName);
-	//	alarm->EntityName=NULL;
-
-	//	free(alarm->SN);
-	//	alarm->SN=NULL;
-
-	//	delete alarm;
-	//	alarm=NULL;
-
-	//	Dbg("send alarm success");
-	//	PostEventLIFO(new FSMEvent(USER_EVT_JMP_RELEASE));
-	//	LeaveCriticalSection(&cs);
-	//} 
-	//else
-	//{
-	//	//链接失效,需要先释放并清空链接,否一直不会重连
-	//	m_pConnection->Close();
-	//	m_pConnection->DecRefCount();
-	//	m_pConnection = NULL;
-
-	//	PostEventLIFO(new FSMEvent(USER_EVT_JMP_RELEASE));	 
-	//}
 
 	if(m_NewUploading_alarm.empty()){
 		PostEventLIFO(new FSMEvent(USER_EVT_DISCONNECT_FAIL));//为空时,跳回S0状态
@@ -554,34 +429,6 @@ void AlarmFSM::s1_on_exit()
 
 unsigned int AlarmFSM::s1_on_event(FSMEvent* event)
 {
-	//if (event->iEvt == USER_EVT_DISCONNECT) 
-	//{
-	//	Dbg("rx disconnect evt at alarmupload s1");
-	//	if (m_pConnection) 
-	//	{
-	//		m_pConnection->Close();
-	//		m_pConnection->DecRefCount();
-	//		m_pConnection = NULL;
-	//		ScheduleTimer(2, 5000);
-	//	}
-	//}
-	//else if (event->iEvt == EVT_TIMER)
-	//{
-	//	if (!m_pConnection) 
-	//	{
-	//		m_pConnection = new AlarmConnection(m_pEntity, this);
-	//		if (!m_pConnection->ConnectFromCentralSetting())
-	//		{
-	//			Dbg("connect server fail,config or Servers Error!");
-	//			PostEventLIFO(new FSMEvent(USER_EVT_DISCONNECT));
-	//		}	
-	//	} 
-	//}
-	//else if (event->iEvt == EVT_TIMER)
-	//{
-	//	//继续发送
-
-	//}
 	if (event->iEvt == USER_EVT_DISCONNECT_FAIL) 
 	{
 		//Dbg("disconnect 10s at alarmupload s1");
@@ -680,14 +527,6 @@ unsigned int AlarmFSM::s2_on_event(FSMEvent* event)
 
 void AlarmFSM::s3_on_entry()
 {
-	//modify by zl 20180314,发送完,马上断开链接可能会导致服务端无法接受到请求,改用长链接
-	/*if (m_pConnection) 
-	{
-		m_pConnection->Close();
-		m_pConnection->DecRefCount();
-		m_pConnection = NULL;
-		LogEvent(Severity_Low,EVENT_MOD_ALARM_INITIATIVE_DISCONNECT,"Connecting Closed");
-	}*/
 
 	PostEventFIFO(new FSMEvent(USER_EVT_DISCONNECT));