From 5d5e5a164fbaa4ee386b8e54f3d13779656808c1 Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: Tue, 16 Nov 2021 18:15:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=9B=AE=E5=BD=95=E8=AE=A2?= =?UTF-8?q?=E9=98=85=E7=9A=84=E5=AE=9A=E6=97=B6=E5=88=B7=E6=96=B0=E4=BB=A5?= =?UTF-8?q?=E5=8F=8A=E4=BF=A1=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../genersoft/iot/vmp/conf/DynamicTask.java | 5 ++-- .../transmit/SIPProcessorObserver.java | 3 --- .../cmd/SIPRequestHeaderProvider.java | 1 + .../transmit/cmd/impl/SIPCommander.java | 2 +- .../response/impl/ByeResponseProcessor.java | 1 - .../vmp/service/impl/DeviceServiceImpl.java | 27 +++++++------------ 6 files changed, 15 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/conf/DynamicTask.java b/src/main/java/com/genersoft/iot/vmp/conf/DynamicTask.java index 145c29b5..10dfc086 100644 --- a/src/main/java/com/genersoft/iot/vmp/conf/DynamicTask.java +++ b/src/main/java/com/genersoft/iot/vmp/conf/DynamicTask.java @@ -26,9 +26,10 @@ public class DynamicTask { return new ThreadPoolTaskScheduler(); } - public String startCron(String key, Runnable task, String corn) { + public String startCron(String key, Runnable task, int cycleForCatalog) { stopCron(key); - ScheduledFuture future = threadPoolTaskScheduler.schedule(task, new CronTrigger(corn)); + // scheduleWithFixedDelay 必须等待上一个任务结束才开始计时period, cycleForCatalog表示执行的间隔 + ScheduledFuture future = threadPoolTaskScheduler.scheduleWithFixedDelay(task, cycleForCatalog * 1000L); futureMap.put(key, future); return "startCron"; } diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/SIPProcessorObserver.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/SIPProcessorObserver.java index 48eebf8a..cac1a01e 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/SIPProcessorObserver.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/SIPProcessorObserver.java @@ -143,18 +143,15 @@ public class SIPProcessorObserver implements SipListener { @Override public void processIOException(IOExceptionEvent exceptionEvent) { -// System.out.println("processIOException"); } @Override public void processTransactionTerminated(TransactionTerminatedEvent transactionTerminatedEvent) { -// System.out.println("processTransactionTerminated"); } @Override public void processDialogTerminated(DialogTerminatedEvent dialogTerminatedEvent) { CallIdHeader callId = dialogTerminatedEvent.getDialog().getCallId(); - System.out.println("processDialogTerminated:::::" + callId); } diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/SIPRequestHeaderProvider.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/SIPRequestHeaderProvider.java index bb62902a..4eac1342 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/SIPRequestHeaderProvider.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/SIPRequestHeaderProvider.java @@ -204,6 +204,7 @@ public class SIPRequestHeaderProvider { // Event EventHeader eventHeader = sipFactory.createHeaderFactory().createEventHeader(event); + eventHeader.setEventType("Catalog"); request.addHeader(eventHeader); ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("APPLICATION", "MANSCDP+xml"); diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java index 7a0e901f..1af2cdf0 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java @@ -1486,7 +1486,7 @@ public class SIPCommander implements ISIPCommander { StringBuffer cmdXml = new StringBuffer(200); cmdXml.append("\r\n"); cmdXml.append("\r\n"); - cmdXml.append("CataLog\r\n"); + cmdXml.append("Catalog\r\n"); cmdXml.append("" + (int)((Math.random()*9+1)*100000) + "\r\n"); cmdXml.append("" + device.getDeviceId() + "\r\n"); cmdXml.append("\r\n"); diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/response/impl/ByeResponseProcessor.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/response/impl/ByeResponseProcessor.java index d44c1a9d..64933b80 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/response/impl/ByeResponseProcessor.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/response/impl/ByeResponseProcessor.java @@ -42,7 +42,6 @@ public class ByeResponseProcessor extends SIPResponseProcessorAbstract { @Override public void process(ResponseEvent evt) { // TODO Auto-generated method stub - System.out.println("收到bye"); } diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceServiceImpl.java index 7cee0965..c1500d2c 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceServiceImpl.java @@ -10,6 +10,9 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +/** + * 设备业务(目录订阅) + */ @Service public class DeviceServiceImpl implements IDeviceService { @@ -31,9 +34,10 @@ public class DeviceServiceImpl implements IDeviceService { CatalogSubscribeTask catalogSubscribeTask = new CatalogSubscribeTask(device, sipCommander); catalogSubscribeTask.run(); // 提前开始刷新订阅 - // TODO 暂时关闭目录订阅的定时刷新,直到此功能完善 -// String cron = getCron(device.getSubscribeCycleForCatalog() - 60); -// dynamicTask.startCron(device.getDeviceId(), catalogSubscribeTask, cron); + int subscribeCycleForCatalog = device.getSubscribeCycleForCatalog(); + // 设置最小值为30 + subscribeCycleForCatalog = Math.max(subscribeCycleForCatalog, 30); + dynamicTask.startCron(device.getDeviceId(), catalogSubscribeTask, subscribeCycleForCatalog - 5); return true; } @@ -42,21 +46,10 @@ public class DeviceServiceImpl implements IDeviceService { if (device == null || device.getSubscribeCycleForCatalog() < 0) { return false; } + logger.info("移除目录订阅【{}】", device.getDeviceId()); dynamicTask.stopCron(device.getDeviceId()); + device.setSubscribeCycleForCatalog(0); + sipCommander.catalogSubscribe(device, null, null); return true; } - - public String getCron(int time) { - if (time <= 59) { - return "0/" + time +" * * * * ?"; - }else if (time <= 60* 59) { - int minute = time/(60); - return "0 0/" + minute +" * * * ?"; - }else if (time <= 60* 60* 59) { - int hour = time/(60*60); - return "0 0 0/" + hour +" * * ?"; - }else { - return "0 0/10 * * * ?"; - } - } }