From c6a7bcdcff73d71647a3f51120f7e07a4fb8eb11 Mon Sep 17 00:00:00 2001 From: shikong <919411476@qq.com> Date: Wed, 23 Aug 2023 10:37:22 +0800 Subject: [PATCH] =?UTF-8?q?subscribe=20key=20=E6=94=B9=E4=B8=BA=20?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=20GenericSubscribe.Helper.getKey?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../message/request/MessageRequestProcessor.java | 10 +++++----- .../core/sip/message/subscribe/GenericSubscribe.java | 8 +++++++- .../docking/gb28181/service/record/RecordService.java | 4 ++-- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/gb28181-service/src/main/java/cn/skcks/docking/gb28181/core/sip/message/processor/message/request/MessageRequestProcessor.java b/gb28181-service/src/main/java/cn/skcks/docking/gb28181/core/sip/message/processor/message/request/MessageRequestProcessor.java index d9f087d..2bfd61b 100644 --- a/gb28181-service/src/main/java/cn/skcks/docking/gb28181/core/sip/message/processor/message/request/MessageRequestProcessor.java +++ b/gb28181-service/src/main/java/cn/skcks/docking/gb28181/core/sip/message/processor/message/request/MessageRequestProcessor.java @@ -2,7 +2,6 @@ package cn.skcks.docking.gb28181.core.sip.message.processor.message.request; import cn.skcks.docking.gb28181.common.json.ResponseStatus; import cn.skcks.docking.gb28181.common.xml.XmlUtils; -import cn.skcks.docking.gb28181.core.sip.gb28181.cache.CacheUtil; import cn.skcks.docking.gb28181.core.sip.gb28181.constant.CmdType; import cn.skcks.docking.gb28181.core.sip.gb28181.constant.GB28181Constant; import cn.skcks.docking.gb28181.core.sip.listener.SipListener; @@ -10,6 +9,7 @@ import cn.skcks.docking.gb28181.core.sip.message.processor.MessageProcessor; import cn.skcks.docking.gb28181.core.sip.message.processor.message.request.dto.MessageDTO; import cn.skcks.docking.gb28181.core.sip.message.processor.message.types.recordinfo.reponse.dto.RecordInfoResponseDTO; import cn.skcks.docking.gb28181.core.sip.message.sender.SipMessageSender; +import cn.skcks.docking.gb28181.core.sip.message.subscribe.GenericSubscribe; import cn.skcks.docking.gb28181.core.sip.message.subscribe.SipSubscribe; import cn.skcks.docking.gb28181.core.sip.utils.SipUtil; import cn.skcks.docking.gb28181.orm.mybatis.dynamic.model.DockingDevice; @@ -71,10 +71,10 @@ public class MessageRequestProcessor implements MessageProcessor { } else if(messageDto.getCmdType().equalsIgnoreCase(CmdType.RECORD_INFO)){ response = ok; RecordInfoResponseDTO dto = XmlUtils.parse(content, RecordInfoResponseDTO.class, GB28181Constant.CHARSET); - String key = CacheUtil.getKey(CmdType.RECORD_INFO, dto.getDeviceId(), dto.getSn()); - Optional.ofNullable(subscribe.getRecordInfoSubscribe().getPublisher(key)).ifPresentOrElse(publisher->{ - publisher.submit(dto); - },()-> log.warn("对应订阅 {} 已结束, 异常数据 => {}",key, dto)); + String key = GenericSubscribe.Helper.getKey(CmdType.RECORD_INFO, dto.getDeviceId(), dto.getSn()); + Optional.ofNullable(subscribe.getRecordInfoSubscribe().getPublisher(key)) + .ifPresentOrElse(publisher-> publisher.submit(dto), + ()-> log.warn("对应订阅 {} 已结束, 异常数据 => {}",key, dto)); } else { response = response(request, Response.NOT_IMPLEMENTED, ResponseStatus.NOT_IMPLEMENTED.getMessage()); } diff --git a/gb28181-service/src/main/java/cn/skcks/docking/gb28181/core/sip/message/subscribe/GenericSubscribe.java b/gb28181-service/src/main/java/cn/skcks/docking/gb28181/core/sip/message/subscribe/GenericSubscribe.java index cf064a6..40595ec 100644 --- a/gb28181-service/src/main/java/cn/skcks/docking/gb28181/core/sip/message/subscribe/GenericSubscribe.java +++ b/gb28181-service/src/main/java/cn/skcks/docking/gb28181/core/sip/message/subscribe/GenericSubscribe.java @@ -1,6 +1,7 @@ package cn.skcks.docking.gb28181.core.sip.message.subscribe; -import cn.skcks.docking.gb28181.core.sip.message.processor.message.types.recordinfo.reponse.dto.RecordInfoResponseDTO; +import org.apache.commons.lang3.ArrayUtils; +import org.apache.commons.lang3.StringUtils; import java.util.Map; import java.util.concurrent.Executor; @@ -18,6 +19,11 @@ public interface GenericSubscribe { void delPublisher(String key); class Helper { + public final static String SEPARATOR = ":"; + public static String getKey(String prefix,String... ids){ + return StringUtils.joinWith(SEPARATOR, (Object[]) ArrayUtils.addFirst(ids,prefix)); + } + public static void close(Map> publishers){ publishers.values().forEach(SubmissionPublisher::close); publishers.clear(); diff --git a/gb28181-service/src/main/java/cn/skcks/docking/gb28181/service/record/RecordService.java b/gb28181-service/src/main/java/cn/skcks/docking/gb28181/service/record/RecordService.java index 0ea931f..9286b9a 100644 --- a/gb28181-service/src/main/java/cn/skcks/docking/gb28181/service/record/RecordService.java +++ b/gb28181-service/src/main/java/cn/skcks/docking/gb28181/service/record/RecordService.java @@ -3,13 +3,13 @@ package cn.skcks.docking.gb28181.service.record; import cn.hutool.core.date.DateUtil; import cn.skcks.docking.gb28181.common.json.JsonResponse; import cn.skcks.docking.gb28181.common.xml.XmlUtils; -import cn.skcks.docking.gb28181.core.sip.gb28181.cache.CacheUtil; import cn.skcks.docking.gb28181.core.sip.gb28181.constant.CmdType; import cn.skcks.docking.gb28181.core.sip.message.processor.message.types.recordinfo.query.dto.RecordInfoRequestDTO; import cn.skcks.docking.gb28181.core.sip.message.processor.message.types.recordinfo.reponse.dto.RecordInfoItemDTO; import cn.skcks.docking.gb28181.core.sip.message.processor.message.types.recordinfo.reponse.dto.RecordInfoResponseDTO; import cn.skcks.docking.gb28181.core.sip.message.request.SipRequestBuilder; import cn.skcks.docking.gb28181.core.sip.message.sender.SipMessageSender; +import cn.skcks.docking.gb28181.core.sip.message.subscribe.GenericSubscribe; import cn.skcks.docking.gb28181.core.sip.message.subscribe.SipSubscribe; import cn.skcks.docking.gb28181.core.sip.service.SipService; import cn.skcks.docking.gb28181.core.sip.utils.SipUtil; @@ -69,7 +69,7 @@ public class RecordService { null, callId); - String key = CacheUtil.getKey(CmdType.RECORD_INFO, deviceId, sn); + String key = GenericSubscribe.Helper.getKey(CmdType.RECORD_INFO, deviceId, sn); subscribe.getRecordInfoSubscribe().addPublisher(key); sender.send(senderIp, request); List list = new ArrayList<>();