From 85c5fafda53f21697499ff0587ff6dc0f2b00f0a Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期四, 16 三月 2023 09:34:20 +0800
Subject: [PATCH] 更新前后端分离部署文档
---
src/main/java/com/genersoft/iot/vmp/service/impl/PlatformServiceImpl.java | 205 +++++++++++++++++++++++++++++++++++---------------
1 files changed, 143 insertions(+), 62 deletions(-)
diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/PlatformServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/PlatformServiceImpl.java
index 3a5d19a..136689c 100644
--- a/src/main/java/com/genersoft/iot/vmp/service/impl/PlatformServiceImpl.java
+++ b/src/main/java/com/genersoft/iot/vmp/service/impl/PlatformServiceImpl.java
@@ -1,17 +1,17 @@
package com.genersoft.iot.vmp.service.impl;
import com.genersoft.iot.vmp.conf.DynamicTask;
-import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
-import com.genersoft.iot.vmp.gb28181.bean.ParentPlatformCatch;
-import com.genersoft.iot.vmp.gb28181.bean.SendRtpItem;
-import com.genersoft.iot.vmp.gb28181.bean.SubscribeHolder;
+import com.genersoft.iot.vmp.conf.UserSetting;
+import com.genersoft.iot.vmp.gb28181.bean.*;
import com.genersoft.iot.vmp.gb28181.event.SipSubscribe;
import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommanderFroPlatform;
import com.genersoft.iot.vmp.media.zlm.ZLMRTPServerFactory;
import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
import com.genersoft.iot.vmp.service.IMediaServerService;
import com.genersoft.iot.vmp.service.IPlatformService;
+import com.genersoft.iot.vmp.service.bean.GPSMsgInfo;
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
+import com.genersoft.iot.vmp.storager.dao.GbStreamMapper;
import com.genersoft.iot.vmp.storager.dao.ParentPlatformMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
@@ -20,7 +20,9 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
-import javax.sip.TimeoutEvent;
+import javax.sip.InvalidArgumentException;
+import javax.sip.SipException;
+import java.text.ParseException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -56,6 +58,12 @@
@Autowired
private SubscribeHolder subscribeHolder;
+
+ @Autowired
+ private GbStreamMapper gbStreamMapper;
+
+ @Autowired
+ private UserSetting userSetting;
@@ -93,16 +101,20 @@
if (parentPlatform.isEnable()) {
// 淇濆瓨鏃跺惎鐢ㄥ氨鍙戦�佹敞鍐�
// 娉ㄥ唽鎴愬姛鏃剁敱绋嬪簭鐩存帴璋冪敤浜唎nline鏂规硶
- commanderForPlatform.register(parentPlatform, eventResult -> {
- logger.info("[鍥芥爣绾ц仈] {},娣诲姞鍚戜笂绾ф敞鍐屽け璐ワ紝璇风‘瀹氫笂绾у钩鍙板彲鐢ㄦ椂閲嶆柊淇濆瓨", parentPlatform.getServerGBId());
- }, null);
+ try {
+ commanderForPlatform.register(parentPlatform, eventResult -> {
+ logger.info("[鍥芥爣绾ц仈] {},娣诲姞鍚戜笂绾ф敞鍐屽け璐ワ紝璇风‘瀹氫笂绾у钩鍙板彲鐢ㄦ椂閲嶆柊淇濆瓨", parentPlatform.getServerGBId());
+ }, null);
+ } catch (InvalidArgumentException | ParseException | SipException e) {
+ logger.error("[鍛戒护鍙戦�佸け璐 鍥芥爣绾ц仈: {}", e.getMessage());
+ }
}
return result > 0;
}
@Override
public void online(ParentPlatform parentPlatform) {
- logger.info("[鍥芥爣绾ц仈]锛歿}, 骞冲彴涓婄嚎", parentPlatform.getServerGBId());
+ logger.info("[鍥芥爣绾ц仈]锛歿}, 骞冲彴涓婄嚎/鏇存柊娉ㄥ唽", parentPlatform.getServerGBId());
platformMapper.updateParentPlatformStatus(parentPlatform.getServerGBId(), true);
ParentPlatformCatch parentPlatformCatch = redisCatchStorage.queryPlatformCatchInfo(parentPlatform.getServerGBId());
if (parentPlatformCatch != null) {
@@ -118,58 +130,87 @@
}
final String registerTaskKey = REGISTER_KEY_PREFIX + parentPlatform.getServerGBId();
- if (dynamicTask.contains(registerTaskKey)) {
- dynamicTask.stop(registerTaskKey);
- }
- // 娣诲姞娉ㄥ唽浠诲姟
- dynamicTask.startDelay(registerTaskKey,
+ if (!dynamicTask.isAlive(registerTaskKey)) {
+ // 娣诲姞娉ㄥ唽浠诲姟
+ dynamicTask.startCron(registerTaskKey,
// 娉ㄥ唽澶辫触锛堟敞鍐屾垚鍔熸椂鐢辩▼搴忕洿鎺ヨ皟鐢ㄤ簡online鏂规硶锛�
- ()->commanderForPlatform.register(parentPlatform, eventResult -> offline(parentPlatform),null),
- parentPlatform.getExpires()*1000);
+ ()-> {
+ registerTask(parentPlatform);
+ },
+ (parentPlatform.getExpires() - 10) *1000);
+ }
+
final String keepaliveTaskKey = KEEPALIVE_KEY_PREFIX + parentPlatform.getServerGBId();
if (!dynamicTask.contains(keepaliveTaskKey)) {
// 娣诲姞蹇冭烦浠诲姟
dynamicTask.startCron(keepaliveTaskKey,
- ()-> commanderForPlatform.keepalive(parentPlatform, eventResult -> {
- // 蹇冭烦澶辫触
- if (eventResult.type == SipSubscribe.EventResultType.timeout) {
- // 蹇冭烦瓒呮椂
- ParentPlatformCatch platformCatch = redisCatchStorage.queryPlatformCatchInfo(parentPlatform.getServerGBId());
- // 姝ゆ椂鏄涓夋蹇冭烦瓒呮椂锛� 骞冲彴绂荤嚎
- if (platformCatch.getKeepAliveReply() == 2) {
- // 璁剧疆骞冲彴绂荤嚎锛屽苟閲嶆柊娉ㄥ唽
- offline(parentPlatform);
- logger.info("[鍥芥爣绾ц仈] {}锛屼笁娆″績璺宠秴鏃跺悗鍐嶆鍙戣捣娉ㄥ唽", parentPlatform.getServerGBId());
- commanderForPlatform.register(parentPlatform, eventResult1 -> {
- logger.info("[鍥芥爣绾ц仈] {}锛屼笁娆″績璺宠秴鏃跺悗鍐嶆鍙戣捣娉ㄥ唽浠嶇劧澶辫触锛屽紑濮嬪畾鏃跺彂璧锋敞鍐岋紝闂撮殧涓�1鍒嗛挓", parentPlatform.getServerGBId());
- // 娣诲姞娉ㄥ唽浠诲姟
- dynamicTask.startCron(registerTaskKey,
- // 娉ㄥ唽澶辫触锛堟敞鍐屾垚鍔熸椂鐢辩▼搴忕洿鎺ヨ皟鐢ㄤ簡online鏂规硶锛�
- ()->logger.info("[鍥芥爣绾ц仈] {},骞冲彴绂荤嚎鍚庢寔缁彂璧锋敞鍐岋紝澶辫触", parentPlatform.getServerGBId()),
- 60*1000);
- }, null);
- }
+ ()-> {
+ try {
+ commanderForPlatform.keepalive(parentPlatform, eventResult -> {
+ // 蹇冭烦澶辫触
+ if (eventResult.type == SipSubscribe.EventResultType.timeout) {
+ // 蹇冭烦瓒呮椂
+ ParentPlatformCatch platformCatch = redisCatchStorage.queryPlatformCatchInfo(parentPlatform.getServerGBId());
+ // 姝ゆ椂鏄涓夋蹇冭烦瓒呮椂锛� 骞冲彴绂荤嚎
+ if (platformCatch.getKeepAliveReply() == 2) {
+ // 璁剧疆骞冲彴绂荤嚎锛屽苟閲嶆柊娉ㄥ唽
+ logger.info("[鍥芥爣绾ц仈] {}锛屼笁娆″績璺宠秴鏃跺悗鍐嶆鍙戣捣娉ㄥ唽", parentPlatform.getServerGBId());
+ try {
+ commanderForPlatform.register(parentPlatform, eventResult1 -> {
+ logger.info("[鍥芥爣绾ц仈] {}锛屼笁娆″績璺宠秴鏃跺悗鍐嶆鍙戣捣娉ㄥ唽浠嶇劧澶辫触锛屽紑濮嬪畾鏃跺彂璧锋敞鍐岋紝闂撮殧涓�1鍒嗛挓", parentPlatform.getServerGBId());
+ offline(parentPlatform, false);
+ }, null);
+ } catch (InvalidArgumentException | ParseException | SipException e) {
+ logger.error("[鍛戒护鍙戦�佸け璐 鍥芥爣绾ц仈 娉ㄥ唽: {}", e.getMessage());
+ }
+ }
- }else {
- logger.warn("[鍥芥爣绾ц仈]鍙戦�佸績璺虫敹鍒伴敊璇紝code锛� {}, msg: {}", eventResult.statusCode, eventResult.msg);
- }
+ }else {
+ logger.warn("[鍥芥爣绾ц仈]鍙戦�佸績璺虫敹鍒伴敊璇紝code锛� {}, msg: {}", eventResult.statusCode, eventResult.msg);
+ }
- }, eventResult -> {
- // 蹇冭烦鎴愬姛
- // 娓呯┖涔嬪墠鐨勫績璺宠秴鏃惰鏁�
- ParentPlatformCatch platformCatch = redisCatchStorage.queryPlatformCatchInfo(parentPlatform.getServerGBId());
- if (platformCatch.getKeepAliveReply() > 0) {
- platformCatch.setKeepAliveReply(0);
- redisCatchStorage.updatePlatformCatchInfo(platformCatch);
+ }, eventResult -> {
+ // 蹇冭烦鎴愬姛
+ // 娓呯┖涔嬪墠鐨勫績璺宠秴鏃惰鏁�
+ ParentPlatformCatch platformCatch = redisCatchStorage.queryPlatformCatchInfo(parentPlatform.getServerGBId());
+ if (platformCatch.getKeepAliveReply() > 0) {
+ platformCatch.setKeepAliveReply(0);
+ redisCatchStorage.updatePlatformCatchInfo(platformCatch);
+ }
+ });
+ } catch (SipException | InvalidArgumentException | ParseException e) {
+ logger.error("[鍛戒护鍙戦�佸け璐 鍥芥爣绾ц仈 鍙戦�佸績璺�: {}", e.getMessage());
}
- }),
- parentPlatform.getExpires()*1000);
+ },
+ (parentPlatform.getKeepTimeout() - 10)*1000);
+ }
+ }
+
+ private void registerTask(ParentPlatform parentPlatform){
+ try {
+ // 璁剧疆瓒呮椂閲嶅彂锛� 鍚庣画浠庡簳灞傛敮鎸佹秷鎭噸鍙�
+ String key = KEEPALIVE_KEY_PREFIX + parentPlatform.getServerGBId() + "_timeout";
+ if (dynamicTask.isAlive(key)) {
+ return;
+ }
+ dynamicTask.startDelay(key, ()->{
+ registerTask(parentPlatform);
+ }, 1000);
+ logger.info("[鍥芥爣绾ц仈] 骞冲彴锛歿}娉ㄥ唽鍗冲皢鍒版湡锛岄噸鏂版敞鍐�", parentPlatform.getServerGBId());
+ commanderForPlatform.register(parentPlatform, eventResult -> {
+ dynamicTask.stop(key);
+ offline(parentPlatform, false);
+ },eventResult -> {
+ dynamicTask.stop(key);
+ });
+ } catch (InvalidArgumentException | ParseException | SipException e) {
+ logger.error("[鍛戒护鍙戦�佸け璐 鍥芥爣绾ц仈瀹氭椂娉ㄥ唽: {}", e.getMessage());
}
}
@Override
- public void offline(ParentPlatform parentPlatform) {
+ public void offline(ParentPlatform parentPlatform, boolean stopRegister) {
logger.info("[骞冲彴绂荤嚎]锛歿}", parentPlatform.getServerGBId());
ParentPlatformCatch parentPlatformCatch = redisCatchStorage.queryPlatformCatchInfo(parentPlatform.getServerGBId());
parentPlatformCatch.setKeepAliveReply(0);
@@ -183,11 +224,13 @@
// 鍋滄鎵�鏈夋帹娴�
logger.info("[骞冲彴绂荤嚎] {}, 鍋滄鎵�鏈夋帹娴�", parentPlatform.getServerGBId());
stopAllPush(parentPlatform.getServerGBId());
- // 娓呴櫎娉ㄥ唽瀹氭椂
- logger.info("[骞冲彴绂荤嚎] {}, 鍋滄瀹氭椂娉ㄥ唽浠诲姟", parentPlatform.getServerGBId());
- final String registerTaskKey = REGISTER_KEY_PREFIX + parentPlatform.getServerGBId();
- if (dynamicTask.contains(registerTaskKey)) {
- dynamicTask.stop(registerTaskKey);
+ if (stopRegister) {
+ // 娓呴櫎娉ㄥ唽瀹氭椂
+ logger.info("[骞冲彴绂荤嚎] {}, 鍋滄瀹氭椂娉ㄥ唽浠诲姟", parentPlatform.getServerGBId());
+ final String registerTaskKey = REGISTER_KEY_PREFIX + parentPlatform.getServerGBId();
+ if (dynamicTask.contains(registerTaskKey)) {
+ dynamicTask.stop(registerTaskKey);
+ }
}
// 娓呴櫎蹇冭烦瀹氭椂
logger.info("[骞冲彴绂荤嚎] {}, 鍋滄瀹氭椂鍙戦�佸績璺充换鍔�", parentPlatform.getServerGBId());
@@ -213,20 +256,58 @@
param.put("stream", sendRtpItem.getStreamId());
zlmrtpServerFactory.stopSendRtpStream(mediaInfo, param);
}
-
}
}
@Override
public void login(ParentPlatform parentPlatform) {
final String registerTaskKey = REGISTER_KEY_PREFIX + parentPlatform.getServerGBId();
- commanderForPlatform.register(parentPlatform, eventResult1 -> {
- logger.info("[鍥芥爣绾ц仈] {}锛屽紑濮嬪畾鏃跺彂璧锋敞鍐岋紝闂撮殧涓�1鍒嗛挓", parentPlatform.getServerGBId());
- // 娣诲姞娉ㄥ唽浠诲姟
- dynamicTask.startCron(registerTaskKey,
- // 娉ㄥ唽澶辫触锛堟敞鍐屾垚鍔熸椂鐢辩▼搴忕洿鎺ヨ皟鐢ㄤ簡online鏂规硶锛�
- ()->logger.info("[鍥芥爣绾ц仈] {},骞冲彴绂荤嚎鍚庢寔缁彂璧锋敞鍐岋紝澶辫触", parentPlatform.getServerGBId()),
- 60*1000);
- }, null);
+ try {
+ commanderForPlatform.register(parentPlatform, eventResult1 -> {
+ logger.info("[鍥芥爣绾ц仈] {}锛屽紑濮嬪畾鏃跺彂璧锋敞鍐岋紝闂撮殧涓�1鍒嗛挓", parentPlatform.getServerGBId());
+ // 娣诲姞娉ㄥ唽浠诲姟
+ dynamicTask.startCron(registerTaskKey,
+ // 娉ㄥ唽澶辫触锛堟敞鍐屾垚鍔熸椂鐢辩▼搴忕洿鎺ヨ皟鐢ㄤ簡online鏂规硶锛�
+ ()->logger.info("[鍥芥爣绾ц仈] {},骞冲彴绂荤嚎鍚庢寔缁彂璧锋敞鍐岋紝澶辫触", parentPlatform.getServerGBId()),
+ 60*1000);
+ }, null);
+ } catch (InvalidArgumentException | ParseException | SipException e) {
+ logger.error("[鍛戒护鍙戦�佸け璐 鍥芥爣绾ц仈娉ㄥ唽: {}", e.getMessage());
+ }
+ }
+
+ @Override
+ public void sendNotifyMobilePosition(String platformId) {
+ ParentPlatform platform = platformMapper.getParentPlatByServerGBId(platformId);
+ if (platform == null) {
+ return;
+ }
+ SubscribeInfo subscribe = subscribeHolder.getMobilePositionSubscribe(platform.getServerGBId());
+ if (subscribe != null) {
+
+ // TODO 鏆傛椂鍙鐞嗚棰戞祦鐨勫洖澶�,鍚庣画澧炲姞瀵瑰浗鏍囪澶囩殑鏀寔
+ List<DeviceChannel> gbStreams = gbStreamMapper.queryGbStreamListInPlatform(platform.getServerGBId(), userSetting.isUsePushingAsStatus());
+ if (gbStreams.size() == 0) {
+ return;
+ }
+ for (DeviceChannel deviceChannel : gbStreams) {
+ String gbId = deviceChannel.getChannelId();
+ GPSMsgInfo gpsMsgInfo = redisCatchStorage.getGpsMsgInfo(gbId);
+ // 鏃犳渶鏂颁綅缃笉鍙戦��
+ if (gpsMsgInfo != null) {
+ // 缁忕含搴﹂兘涓�0涓嶅彂閫�
+ if (gpsMsgInfo.getLng() == 0 && gpsMsgInfo.getLat() == 0) {
+ continue;
+ }
+ // 鍙戦�丟PS娑堟伅
+ try {
+ commanderForPlatform.sendNotifyMobilePosition(platform, gpsMsgInfo, subscribe);
+ } catch (InvalidArgumentException | ParseException | NoSuchFieldException | SipException |
+ IllegalAccessException e) {
+ logger.error("[鍛戒护鍙戦�佸け璐 鍥芥爣绾ц仈 绉诲姩浣嶇疆閫氱煡: {}", e.getMessage());
+ }
+ }
+ }
+ }
}
}
--
Gitblit v1.8.0