From 405e29c15b7583c1b001148d7981bc244dc08721 Mon Sep 17 00:00:00 2001 From: shikong <919411476@qq.com> Date: Sun, 7 Jan 2024 16:21:14 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=82=E5=B8=B8=E6=8D=95=E8=8E=B7=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gb28181/service/catalog/CatalogService.java | 6 ------ .../gb28181/utils/FutureDeferredResult.java | 17 ++++++++--------- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/gb28181-service/src/main/java/cn/skcks/docking/gb28181/service/catalog/CatalogService.java b/gb28181-service/src/main/java/cn/skcks/docking/gb28181/service/catalog/CatalogService.java index ab803b5..0931a15 100644 --- a/gb28181-service/src/main/java/cn/skcks/docking/gb28181/service/catalog/CatalogService.java +++ b/gb28181-service/src/main/java/cn/skcks/docking/gb28181/service/catalog/CatalogService.java @@ -7,16 +7,13 @@ 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.orm.mybatis.dynamic.model.DockingDevice; -import cn.skcks.docking.gb28181.orm.mybatis.dynamic.model.DockingDeviceChannel; import cn.skcks.docking.gb28181.service.device.DeviceChannelService; import cn.skcks.docking.gb28181.service.docking.device.cache.DockingDeviceCacheService; import cn.skcks.docking.gb28181.sip.manscdp.catalog.query.CatalogQueryDTO; import cn.skcks.docking.gb28181.sip.manscdp.catalog.response.CatalogItemDTO; -import cn.skcks.docking.gb28181.sip.manscdp.catalog.response.CatalogResponseDTO; import cn.skcks.docking.gb28181.sip.method.message.request.MessageRequestBuilder; import cn.skcks.docking.gb28181.sip.utils.MANSCDPUtils; import cn.skcks.docking.gb28181.sip.utils.SipUtil; -import gov.nist.javax.sip.message.SIPRequest; import lombok.RequiredArgsConstructor; import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; @@ -24,13 +21,10 @@ import org.springframework.stereotype.Service; import javax.sip.SipProvider; import javax.sip.message.Request; -import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.concurrent.CompletableFuture; -import java.util.concurrent.Flow; import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicLong; @Slf4j @Service diff --git a/gb28181-service/src/main/java/cn/skcks/docking/gb28181/utils/FutureDeferredResult.java b/gb28181-service/src/main/java/cn/skcks/docking/gb28181/utils/FutureDeferredResult.java index 050fe87..4b854ec 100644 --- a/gb28181-service/src/main/java/cn/skcks/docking/gb28181/utils/FutureDeferredResult.java +++ b/gb28181-service/src/main/java/cn/skcks/docking/gb28181/utils/FutureDeferredResult.java @@ -10,26 +10,25 @@ public class FutureDeferredResult { public static DeferredResult> toDeferredResultWithJson(CompletableFuture future){ DeferredResult> result = new DeferredResult<>(); future.whenComplete((data,throwable)->{ + if(throwable!= null){ + result.setResult(JsonResponse.error(throwable.getMessage())); + return; + } result.setResult(JsonResponse.success(data)); }); - future.exceptionally(e -> { - result.setResult(JsonResponse.error(e.getMessage())); - return null; - }); return result; } public static DeferredResult> toDeferredResultWithJsonAndTimeout(CompletableFuture future, long time, TimeUnit timeUnit){ DeferredResult> result = new DeferredResult<>(timeUnit.toMillis(time)); result.onTimeout(()-> result.setResult(JsonResponse.error("请求超时"))); - future.whenComplete((data,throwable)->{ + if(throwable!= null){ + result.setResult(JsonResponse.error(throwable.getMessage())); + return; + } result.setResult(JsonResponse.success(data)); }); - future.exceptionally(e -> { - result.setResult(JsonResponse.error(e.getMessage())); - return null; - }); return result; }