From 93d69d54768a5536635a9228bcd437b01d86babf Mon Sep 17 00:00:00 2001
From: 648540858 <456panlinlin>
Date: 星期一, 18 四月 2022 16:16:49 +0800
Subject: [PATCH] 添加国标级联目录分组分组加快通道传输速度

---
 src/main/java/com/genersoft/iot/vmp/gb28181/task/impl/CatalogSubscribeTask.java |   28 +++++++++++++++++++++++++++-
 1 files changed, 27 insertions(+), 1 deletions(-)

diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/task/impl/CatalogSubscribeTask.java b/src/main/java/com/genersoft/iot/vmp/gb28181/task/impl/CatalogSubscribeTask.java
index 51356d5..59b927f 100644
--- a/src/main/java/com/genersoft/iot/vmp/gb28181/task/impl/CatalogSubscribeTask.java
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/task/impl/CatalogSubscribeTask.java
@@ -5,10 +5,13 @@
 import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommander;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.scheduling.annotation.Async;
 
 import javax.sip.Dialog;
 import javax.sip.DialogState;
 import javax.sip.ResponseEvent;
+import java.util.Timer;
+import java.util.TimerTask;
 
 /**
  * 鐩綍璁㈤槄浠诲姟
@@ -19,6 +22,8 @@
     private final ISIPCommander sipCommander;
     private Dialog dialog;
 
+    private Timer timer ;
+
     public CatalogSubscribeTask(Device device, ISIPCommander sipCommander) {
         this.device = device;
         this.sipCommander = sipCommander;
@@ -26,6 +31,10 @@
 
     @Override
     public void run() {
+        if (timer != null ) {
+            timer.cancel();
+            timer = null;
+        }
         sipCommander.catalogSubscribe(device, dialog, eventResult -> {
             if (eventResult.dialog != null || eventResult.dialog.getState().equals(DialogState.CONFIRMED)) {
                 dialog = eventResult.dialog;
@@ -42,6 +51,13 @@
             dialog = null;
             // 澶辫触
             logger.warn("[鐩綍璁㈤槄]澶辫触锛屼俊浠ゅ彂閫佸け璐ワ細 {}-{} ", device.getDeviceId(), eventResult.msg);
+            timer = new Timer();
+            timer.schedule(new TimerTask() {
+                @Override
+                public void run() {
+                    CatalogSubscribeTask.this.run();
+                }
+            }, 2000);
         });
     }
 
@@ -55,9 +71,13 @@
          * TERMINATED-> Terminated Dialog鐘舵��-缁堟
          */
         logger.info("鍙栨秷鐩綍璁㈤槄鏃禿ialog鐘舵�佷负{}", DialogState.CONFIRMED);
+        if (timer != null ) {
+            timer.cancel();
+            timer = null;
+        }
         if (dialog != null && dialog.getState().equals(DialogState.CONFIRMED)) {
             device.setSubscribeCycleForCatalog(0);
-            sipCommander.mobilePositionSubscribe(device, dialog, eventResult -> {
+            sipCommander.catalogSubscribe(device, dialog, eventResult -> {
                 ResponseEvent event = (ResponseEvent) eventResult.event;
                 if (event.getResponse().getRawContent() != null) {
                     // 鎴愬姛
@@ -72,4 +92,10 @@
             });
         }
     }
+
+    @Override
+    public DialogState getDialogState() {
+        if (dialog == null) return null;
+        return dialog.getState();
+    }
 }

--
Gitblit v1.8.0