From c7d15150237c946fbb4f5547dab0018a5f573d88 Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期二, 27 六月 2023 15:34:38 +0800
Subject: [PATCH] 增加redis通道

---
 src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/NotifyRequestProcessor.java |   34 ++++++++++++++++++++++++++++------
 1 files changed, 28 insertions(+), 6 deletions(-)

diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/NotifyRequestProcessor.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/NotifyRequestProcessor.java
index a0038ca..f75c8ba 100644
--- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/NotifyRequestProcessor.java
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/NotifyRequestProcessor.java
@@ -1,6 +1,7 @@
 package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl;
 
 import com.alibaba.fastjson2.JSONObject;
+import com.genersoft.iot.vmp.conf.CivilCodeFileConf;
 import com.genersoft.iot.vmp.conf.SipConfig;
 import com.genersoft.iot.vmp.conf.UserSetting;
 import com.genersoft.iot.vmp.gb28181.bean.*;
@@ -76,11 +77,19 @@
 	@Autowired
 	private IDeviceChannelService deviceChannelService;
 
+	@Autowired
+	private NotifyRequestForCatalogProcessor notifyRequestForCatalogProcessor;
+
+	@Autowired
+	private CivilCodeFileConf civilCodeFileConf;
+
 	private ConcurrentLinkedQueue<HandlerCatchData> taskQueue = new ConcurrentLinkedQueue<>();
 
 	@Qualifier("taskExecutor")
 	@Autowired
 	private ThreadPoolTaskExecutor taskExecutor;
+
+	private int maxQueueCount = 30000;
 
 	@Override
 	public void afterPropertiesSet() throws Exception {
@@ -91,17 +100,29 @@
 	@Override
 	public void process(RequestEvent evt) {
 		try {
-			responseAck((SIPRequest) evt.getRequest(), Response.OK, null, null);
+
+			if (taskQueue.size() >= userSetting.getMaxNotifyCountQueue()) {
+				responseAck((SIPRequest) evt.getRequest(), Response.BUSY_HERE, null, null);
+				logger.error("[notify] 寰呭鐞嗘秷鎭槦鍒楀凡婊� {}锛岃繑鍥�486 BUSY_HERE锛屾秷鎭笉鍋氬鐞�", userSetting.getMaxNotifyCountQueue());
+				return;
+			}else {
+				responseAck((SIPRequest) evt.getRequest(), Response.OK, null, null);
+			}
+
 		}catch (SipException | InvalidArgumentException | ParseException e) {
 			logger.error("鏈鐞嗙殑寮傚父 ", e);
 		}
 		boolean runed = !taskQueue.isEmpty();
+		logger.info("[notify] 寰呭鐞嗘秷鎭暟閲忥細 {}", taskQueue.size());
 		taskQueue.offer(new HandlerCatchData(evt, null, null));
 		if (!runed) {
 			taskExecutor.execute(()-> {
 				while (!taskQueue.isEmpty()) {
 					try {
 						HandlerCatchData take = taskQueue.poll();
+						if (take == null) {
+							continue;
+						}
 						Element rootElement = getRootElement(take.getEvt());
 						if (rootElement == null) {
 							logger.error("澶勭悊NOTIFY娑堟伅鏃舵湭鑾峰彇鍒版秷鎭綋,{}", take.getEvt().getRequest());
@@ -111,7 +132,8 @@
 
 						if (CmdType.CATALOG.equals(cmd)) {
 							logger.info("鎺ユ敹鍒癈atalog閫氱煡");
-							processNotifyCatalogList(take.getEvt());
+//							processNotifyCatalogList(take.getEvt());
+							notifyRequestForCatalogProcessor.process(take.getEvt());
 						} else if (CmdType.ALARM.equals(cmd)) {
 							logger.info("鎺ユ敹鍒癆larm閫氱煡");
 							processNotifyAlarm(take.getEvt());
@@ -131,7 +153,7 @@
 
 	/**
 	 * 澶勭悊MobilePosition绉诲姩浣嶇疆Notify
-	 * 
+	 *
 	 * @param evt
 	 */
 	private void processNotifyMobilePosition(RequestEvent evt) {
@@ -235,7 +257,7 @@
 
 	/***
 	 * 澶勭悊alarm璁惧鎶ヨNotify
-	 * 
+	 *
 	 * @param evt
 	 */
 	private void processNotifyAlarm(RequestEvent evt) {
@@ -345,7 +367,7 @@
 
 	/***
 	 * 澶勭悊catalog璁惧鐩綍鍒楄〃Notify
-	 * 
+	 *
 	 * @param evt
 	 */
 	private void processNotifyCatalogList(RequestEvent evt) {
@@ -385,7 +407,7 @@
 					}else {
 						event = eventElement.getText().toUpperCase();
 					}
-					DeviceChannel channel = XmlUtil.channelContentHander(itemDevice, device, event);
+					DeviceChannel channel = XmlUtil.channelContentHandler(itemDevice, device, event, civilCodeFileConf);
 					channel.setDeviceId(device.getDeviceId());
 					logger.info("[鏀跺埌鐩綍璁㈤槄]锛歿}/{}", device.getDeviceId(), channel.getChannelId());
 					switch (event) {

--
Gitblit v1.8.0