From d4f6ec39b7e0421757a6b9d1a68b1c4610ea2e8c Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期四, 14 三月 2024 14:54:20 +0800
Subject: [PATCH] 优化CivilCode缓存

---
 src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/CatalogResponseMessageHandler.java |   17 ++++++++---------
 1 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/CatalogResponseMessageHandler.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/CatalogResponseMessageHandler.java
index 8648dc4..c16d7f5 100755
--- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/CatalogResponseMessageHandler.java
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/CatalogResponseMessageHandler.java
@@ -1,6 +1,5 @@
 package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.cmd;
 
-import com.genersoft.iot.vmp.conf.CivilCodeFileConf;
 import com.genersoft.iot.vmp.conf.SipConfig;
 import com.genersoft.iot.vmp.gb28181.bean.*;
 import com.genersoft.iot.vmp.gb28181.session.CatalogDataCatch;
@@ -30,6 +29,7 @@
 import java.util.Iterator;
 import java.util.List;
 import java.util.concurrent.ConcurrentLinkedQueue;
+import java.util.concurrent.atomic.AtomicBoolean;
 
 /**
  * 鐩綍鏌ヨ鐨勫洖澶�
@@ -38,6 +38,7 @@
 public class CatalogResponseMessageHandler extends SIPRequestProcessorParent implements InitializingBean, IMessageHandler {
 
     private Logger logger = LoggerFactory.getLogger(CatalogResponseMessageHandler.class);
+
     private final String cmdType = "Catalog";
 
     @Autowired
@@ -56,10 +57,8 @@
     private ThreadPoolTaskExecutor taskExecutor;
 
     @Autowired
-    private CivilCodeFileConf civilCodeFileConf;
-
-    @Autowired
     private SipConfig sipConfig;
+    private AtomicBoolean processing = new AtomicBoolean(false);
 
     @Override
     public void afterPropertiesSet() throws Exception {
@@ -68,7 +67,6 @@
 
     @Override
     public void handForDevice(RequestEvent evt, Device device, Element element) {
-        boolean isEmpty = taskQueue.isEmpty();
         taskQueue.offer(new HandlerCatchData(evt, device, element));
         // 鍥炲200 OK
         try {
@@ -76,8 +74,8 @@
         } catch (SipException | InvalidArgumentException | ParseException e) {
             logger.error("[鍛戒护鍙戦�佸け璐 鐩綍鏌ヨ鍥炲: {}", e.getMessage());
         }
-        // 濡傛灉涓嶄负绌哄垯璇存槑宸茬粡寮�鍚秷鎭鐞�
-        if (isEmpty) {
+        // 宸茬粡寮�鍚秷鎭鐞嗗垯璺宠繃
+        if (processing.compareAndSet(false, true)) {
             taskExecutor.execute(() -> {
                 while (!taskQueue.isEmpty()) {
                     // 鍏ㄥ眬寮傚父鎹曡幏锛屼繚璇佷笅涓�鏉″彲浠ュ緱鍒板鐞�
@@ -116,7 +114,7 @@
                                     if (channelDeviceElement == null) {
                                         continue;
                                     }
-                                    DeviceChannel channel = XmlUtil.channelContentHandler(itemDevice, device, null, civilCodeFileConf);
+                                    DeviceChannel channel = XmlUtil.channelContentHandler(itemDevice, device, null);
                                     if (channel == null) {
                                         logger.info("[鏀跺埌鐩綍璁㈤槄]锛氫絾鏄В鏋愬け璐� {}", new String(evt.getRequest().getRawContent()));
                                         continue;
@@ -146,11 +144,12 @@
                             }
 
                         }
-                    }catch (Exception e) {
+                    } catch (Exception e) {
                         logger.warn("[鏀跺埌閫氶亾] 鍙戠幇鏈鐞嗙殑寮傚父, \r\n{}", evt.getRequest());
                         logger.error("[鏀跺埌閫氶亾] 寮傚父鍐呭锛� ", e);
                     }
                 }
+                processing.set(false);
             });
         }
 

--
Gitblit v1.8.0