From 6e90050db47ca1d9ecec3de6bd95ea1bd1ca4060 Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期一, 29 八月 2022 11:50:36 +0800
Subject: [PATCH] 去除zlm使用redis过期作为心跳超时的方式

---
 src/main/java/com/genersoft/iot/vmp/gb28181/event/offline/KeepaliveTimeoutListenerForPlatform.java |   81 ++++++++++++++++++++++++++++++++++++++++
 1 files changed, 81 insertions(+), 0 deletions(-)

diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/event/offline/KeepaliveTimeoutListenerForPlatform.java b/src/main/java/com/genersoft/iot/vmp/gb28181/event/offline/KeepaliveTimeoutListenerForPlatform.java
new file mode 100644
index 0000000..ead8246
--- /dev/null
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/event/offline/KeepaliveTimeoutListenerForPlatform.java
@@ -0,0 +1,81 @@
+package com.genersoft.iot.vmp.gb28181.event.offline;
+
+import com.genersoft.iot.vmp.conf.UserSetting;
+import com.genersoft.iot.vmp.conf.redis.RedisKeyExpirationEventMessageListener;
+import com.genersoft.iot.vmp.gb28181.bean.Device;
+import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
+import com.genersoft.iot.vmp.gb28181.event.SipSubscribe;
+import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.connection.Message;
+import org.springframework.data.redis.listener.RedisMessageListenerContainer;
+import org.springframework.stereotype.Component;
+
+import com.genersoft.iot.vmp.common.VideoManagerConstants;
+import com.genersoft.iot.vmp.gb28181.event.EventPublisher;
+
+/**    
+ * 璁惧蹇冭烦瓒呮椂鐩戝惉,鍊熷姪redis杩囨湡鐗规�э紝杩涜鐩戝惉锛岀洃鍚埌璇存槑璁惧蹇冭烦瓒呮椂锛屽彂閫佺绾夸簨浠�
+ * @author swwheihei
+ */
+@Component
+public class KeepaliveTimeoutListenerForPlatform extends RedisKeyExpirationEventMessageListener {
+
+    private Logger logger = LoggerFactory.getLogger(KeepaliveTimeoutListenerForPlatform.class);
+
+	@Autowired
+	private EventPublisher publisher;
+
+	@Autowired
+	private UserSetting userSetting;
+
+	@Autowired
+	private SipSubscribe sipSubscribe;
+
+	@Autowired
+	private IVideoManagerStorage storager;
+
+    public KeepaliveTimeoutListenerForPlatform(RedisMessageListenerContainer listenerContainer, UserSetting userSetting) {
+        super(listenerContainer, userSetting);
+    }
+
+
+    /**
+     * 鐩戝惉澶辨晥鐨刱ey
+     * @param message
+     * @param pattern
+     */
+    @Override
+    public void onMessage(Message message, byte[] pattern) {
+        //  鑾峰彇澶辨晥鐨刱ey
+        String expiredKey = message.toString();
+        // 骞冲彴蹇冭烦鍒版湡,闇�瑕侀噸鍙�, 鍒ゆ柇鏄惁宸茬粡澶氭鏈敹鍒板績璺冲洖澶�, 澶氭鏈敹鍒�,鍒欓噸鏂板彂璧锋敞鍐�, 娉ㄥ唽灏濊瘯澶氭鏈緱鍒板洖澶�,鍒欒涓哄钩鍙扮绾�
+        String PLATFORM_KEEPLIVEKEY_PREFIX = VideoManagerConstants.PLATFORM_KEEPALIVE_PREFIX + userSetting.getServerId() + "_";
+        String PLATFORM_REGISTER_PREFIX = VideoManagerConstants.PLATFORM_REGISTER_PREFIX + userSetting.getServerId() + "_";
+        String REGISTER_INFO_PREFIX = VideoManagerConstants.PLATFORM_REGISTER_INFO_PREFIX + userSetting.getServerId() + "_";
+        if (expiredKey.startsWith(PLATFORM_KEEPLIVEKEY_PREFIX)) {
+            String platformGbId = expiredKey.substring(PLATFORM_KEEPLIVEKEY_PREFIX.length());
+            ParentPlatform platform = storager.queryParentPlatByServerGBId(platformGbId);
+            if (platform != null) {
+                publisher.platformKeepaliveExpireEventPublish(platformGbId);
+            }
+        }else if (expiredKey.startsWith(PLATFORM_REGISTER_PREFIX)) {
+            String platformGbId = expiredKey.substring(PLATFORM_REGISTER_PREFIX.length(),expiredKey.length());
+            ParentPlatform platform = storager.queryParentPlatByServerGBId(platformGbId);
+            if (platform != null) {
+                publisher.platformRegisterCycleEventPublish(platformGbId);
+            }
+        }else if (expiredKey.startsWith(REGISTER_INFO_PREFIX)) {
+            String callId = expiredKey.substring(REGISTER_INFO_PREFIX.length());
+            if (sipSubscribe.getErrorSubscribe(callId) != null) {
+                SipSubscribe.EventResult eventResult = new SipSubscribe.EventResult();
+                eventResult.callId = callId;
+                eventResult.msg = "娉ㄥ唽瓒呮椂";
+                eventResult.type = "register timeout";
+                sipSubscribe.getErrorSubscribe(callId).response(eventResult);
+            }
+        }
+    }
+}

--
Gitblit v1.8.0