From 619a86e0ed6cdda88e2458b9ec4302d202d2215f Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: 星期四, 06 六月 2024 19:59:48 +0800 Subject: [PATCH] 修复循环引用 --- src/main/java/com/genersoft/iot/vmp/gb28181/bean/SubscribeHolder.java | 44 +++++++++++++++++++++++++++++--------------- 1 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/bean/SubscribeHolder.java b/src/main/java/com/genersoft/iot/vmp/gb28181/bean/SubscribeHolder.java index d385d9a..8c00c49 100755 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/bean/SubscribeHolder.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/bean/SubscribeHolder.java @@ -4,7 +4,7 @@ import com.genersoft.iot.vmp.conf.DynamicTask; import com.genersoft.iot.vmp.conf.UserSetting; import com.genersoft.iot.vmp.gb28181.task.ISubscribeTask; -import com.genersoft.iot.vmp.gb28181.task.impl.MobilePositionSubscribeHandlerTask; +import com.genersoft.iot.vmp.service.IPlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -32,11 +32,13 @@ public void putCatalogSubscribe(String platformId, SubscribeInfo subscribeInfo) { catalogMap.put(platformId, subscribeInfo); - // 娣诲姞璁㈤槄鍒版湡 - String taskOverdueKey = taskOverduePrefix + "catalog_" + platformId; - // 娣诲姞浠诲姟澶勭悊璁㈤槄杩囨湡 - dynamicTask.startDelay(taskOverdueKey, () -> removeCatalogSubscribe(subscribeInfo.getId()), - subscribeInfo.getExpires() * 1000); + if (subscribeInfo.getExpires() > 0) { + // 娣诲姞璁㈤槄鍒版湡 + String taskOverdueKey = taskOverduePrefix + "catalog_" + platformId; + // 娣诲姞浠诲姟澶勭悊璁㈤槄杩囨湡 + dynamicTask.startDelay(taskOverdueKey, () -> removeCatalogSubscribe(subscribeInfo.getId()), + subscribeInfo.getExpires() * 1000); + } } public SubscribeInfo getCatalogSubscribe(String platformId) { @@ -50,24 +52,26 @@ Runnable runnable = dynamicTask.get(taskOverdueKey); if (runnable instanceof ISubscribeTask) { ISubscribeTask subscribeTask = (ISubscribeTask) runnable; - subscribeTask.stop(); + subscribeTask.stop(null); } // 娣诲姞浠诲姟澶勭悊璁㈤槄杩囨湡 dynamicTask.stop(taskOverdueKey); } - public void putMobilePositionSubscribe(String platformId, SubscribeInfo subscribeInfo) { + public void putMobilePositionSubscribe(String platformId, SubscribeInfo subscribeInfo, Runnable gpsTask) { mobilePositionMap.put(platformId, subscribeInfo); String key = VideoManagerConstants.SIP_SUBSCRIBE_PREFIX + userSetting.getServerId() + "MobilePosition_" + platformId; // 娣诲姞浠诲姟澶勭悊GPS瀹氭椂鎺ㄩ�� - dynamicTask.startCron(key, new MobilePositionSubscribeHandlerTask(platformId), + dynamicTask.startCron(key, gpsTask, subscribeInfo.getGpsInterval() * 1000); String taskOverdueKey = taskOverduePrefix + "MobilePosition_" + platformId; - // 娣诲姞浠诲姟澶勭悊璁㈤槄杩囨湡 - dynamicTask.startDelay(taskOverdueKey, () -> { - removeMobilePositionSubscribe(subscribeInfo.getId()); - }, - subscribeInfo.getExpires() * 1000); + if (subscribeInfo.getExpires() > 0) { + // 娣诲姞浠诲姟澶勭悊璁㈤槄杩囨湡 + dynamicTask.startDelay(taskOverdueKey, () -> { + removeMobilePositionSubscribe(subscribeInfo.getId()); + }, + subscribeInfo.getExpires() * 1000); + } } public SubscribeInfo getMobilePositionSubscribe(String platformId) { @@ -83,7 +87,7 @@ Runnable runnable = dynamicTask.get(taskOverdueKey); if (runnable instanceof ISubscribeTask) { ISubscribeTask subscribeTask = (ISubscribeTask) runnable; - subscribeTask.stop(); + subscribeTask.stop(null); } // 娣诲姞浠诲姟澶勭悊璁㈤槄杩囨湡 dynamicTask.stop(taskOverdueKey); @@ -99,6 +103,16 @@ return platforms; } + public List<String> getAllMobilePositionSubscribePlatform() { + List<String> platforms = new ArrayList<>(); + if(!mobilePositionMap.isEmpty()) { + for (String key : mobilePositionMap.keySet()) { + platforms.add(mobilePositionMap.get(key).getId()); + } + } + return platforms; + } + public void removeAllSubscribe(String platformId) { removeMobilePositionSubscribe(platformId); removeCatalogSubscribe(platformId); -- Gitblit v1.8.0