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/media/zlm/ZlmHttpHookSubscribe.java | 14 ++++++++++---- 1 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZlmHttpHookSubscribe.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZlmHttpHookSubscribe.java old mode 100644 new mode 100755 index cf33bb2..5e46f55 --- a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZlmHttpHookSubscribe.java +++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZlmHttpHookSubscribe.java @@ -4,6 +4,7 @@ import com.genersoft.iot.vmp.media.zlm.dto.HookType; import com.genersoft.iot.vmp.media.zlm.dto.IHookSubscribe; import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; +import com.genersoft.iot.vmp.media.zlm.dto.hook.HookParam; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.scheduling.annotation.Scheduled; @@ -26,7 +27,7 @@ @FunctionalInterface public interface Event{ - void response(MediaServerItem mediaServerItem, JSONObject response); + void response(MediaServerItem mediaServerItem, HookParam hookParam); } private Map<HookType, Map<IHookSubscribe, ZlmHttpHookSubscribe.Event>> allSubscribes = new ConcurrentHashMap<>(); @@ -38,6 +39,7 @@ hookSubscribe.setExpires(expiresInstant); } allSubscribes.computeIfAbsent(hookSubscribe.getHookType(), k -> new ConcurrentHashMap<>()).put(hookSubscribe, event); + System.out.println(allSubscribes); } public ZlmHttpHookSubscribe.Event sendNotify(HookType type, JSONObject hookResponse) { @@ -48,6 +50,7 @@ } for (IHookSubscribe key : eventMap.keySet()) { Boolean result = null; + for (String s : key.getContent().keySet()) { if (result == null) { result = key.getContent().getString(s).equals(hookResponse.getString(s)); @@ -98,7 +101,10 @@ if (!CollectionUtils.isEmpty(entriesToRemove)) { for (Map.Entry<IHookSubscribe, ZlmHttpHookSubscribe.Event> entry : entriesToRemove) { - entries.remove(entry); + eventMap.remove(entry.getKey()); + } + if (eventMap.size() == 0) { + allSubscribes.remove(hookSubscribe.getHookType()); } } @@ -134,9 +140,9 @@ /** * 瀵硅闃呮暟鎹繘琛岃繃鏈熸竻鐞� */ - @Scheduled(cron="0 0/5 * * * ?") //姣�5鍒嗛挓鎵ц涓�娆� +// @Scheduled(cron="0 0/5 * * * ?") //姣�5鍒嗛挓鎵ц涓�娆� + @Scheduled(fixedRate = 2 * 1000) public void execute(){ - Instant instant = Instant.now().minusMillis(TimeUnit.MINUTES.toMillis(5)); int total = 0; for (HookType hookType : allSubscribes.keySet()) { -- Gitblit v1.8.0