Browse Source

修复目录订阅的定时刷新以及信令

pull/231/head
648540858 3 years ago
parent
commit
5d5e5a164f
  1. 5
      src/main/java/com/genersoft/iot/vmp/conf/DynamicTask.java
  2. 3
      src/main/java/com/genersoft/iot/vmp/gb28181/transmit/SIPProcessorObserver.java
  3. 1
      src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/SIPRequestHeaderProvider.java
  4. 2
      src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java
  5. 1
      src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/response/impl/ByeResponseProcessor.java
  6. 27
      src/main/java/com/genersoft/iot/vmp/service/impl/DeviceServiceImpl.java

5
src/main/java/com/genersoft/iot/vmp/conf/DynamicTask.java

@ -26,9 +26,10 @@ public class DynamicTask {
return new ThreadPoolTaskScheduler(); return new ThreadPoolTaskScheduler();
} }
public String startCron(String key, Runnable task, String corn) { public String startCron(String key, Runnable task, int cycleForCatalog) {
stopCron(key); stopCron(key);
ScheduledFuture future = threadPoolTaskScheduler.schedule(task, new CronTrigger(corn)); // scheduleWithFixedDelay 必须等待上一个任务结束才开始计时period, cycleForCatalog表示执行的间隔
ScheduledFuture future = threadPoolTaskScheduler.scheduleWithFixedDelay(task, cycleForCatalog * 1000L);
futureMap.put(key, future); futureMap.put(key, future);
return "startCron"; return "startCron";
} }

3
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/SIPProcessorObserver.java

@ -143,18 +143,15 @@ public class SIPProcessorObserver implements SipListener {
@Override @Override
public void processIOException(IOExceptionEvent exceptionEvent) { public void processIOException(IOExceptionEvent exceptionEvent) {
// System.out.println("processIOException");
} }
@Override @Override
public void processTransactionTerminated(TransactionTerminatedEvent transactionTerminatedEvent) { public void processTransactionTerminated(TransactionTerminatedEvent transactionTerminatedEvent) {
// System.out.println("processTransactionTerminated");
} }
@Override @Override
public void processDialogTerminated(DialogTerminatedEvent dialogTerminatedEvent) { public void processDialogTerminated(DialogTerminatedEvent dialogTerminatedEvent) {
CallIdHeader callId = dialogTerminatedEvent.getDialog().getCallId(); CallIdHeader callId = dialogTerminatedEvent.getDialog().getCallId();
System.out.println("processDialogTerminated:::::" + callId);
} }

1
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/SIPRequestHeaderProvider.java

@ -204,6 +204,7 @@ public class SIPRequestHeaderProvider {
// Event // Event
EventHeader eventHeader = sipFactory.createHeaderFactory().createEventHeader(event); EventHeader eventHeader = sipFactory.createHeaderFactory().createEventHeader(event);
eventHeader.setEventType("Catalog");
request.addHeader(eventHeader); request.addHeader(eventHeader);
ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("APPLICATION", "MANSCDP+xml"); ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("APPLICATION", "MANSCDP+xml");

2
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); StringBuffer cmdXml = new StringBuffer(200);
cmdXml.append("<?xml version=\"1.0\" encoding=\"GB2312\"?>\r\n"); cmdXml.append("<?xml version=\"1.0\" encoding=\"GB2312\"?>\r\n");
cmdXml.append("<Query>\r\n"); cmdXml.append("<Query>\r\n");
cmdXml.append("<CmdType>CataLog</CmdType>\r\n"); cmdXml.append("<CmdType>Catalog</CmdType>\r\n");
cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n"); cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
cmdXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n"); cmdXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
cmdXml.append("</Query>\r\n"); cmdXml.append("</Query>\r\n");

1
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/response/impl/ByeResponseProcessor.java

@ -42,7 +42,6 @@ public class ByeResponseProcessor extends SIPResponseProcessorAbstract {
@Override @Override
public void process(ResponseEvent evt) { public void process(ResponseEvent evt) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
System.out.println("收到bye");
} }

27
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.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
/**
* 设备业务目录订阅
*/
@Service @Service
public class DeviceServiceImpl implements IDeviceService { public class DeviceServiceImpl implements IDeviceService {
@ -31,9 +34,10 @@ public class DeviceServiceImpl implements IDeviceService {
CatalogSubscribeTask catalogSubscribeTask = new CatalogSubscribeTask(device, sipCommander); CatalogSubscribeTask catalogSubscribeTask = new CatalogSubscribeTask(device, sipCommander);
catalogSubscribeTask.run(); catalogSubscribeTask.run();
// 提前开始刷新订阅 // 提前开始刷新订阅
// TODO 暂时关闭目录订阅的定时刷新,直到此功能完善 int subscribeCycleForCatalog = device.getSubscribeCycleForCatalog();
// String cron = getCron(device.getSubscribeCycleForCatalog() - 60); // 设置最小值为30
// dynamicTask.startCron(device.getDeviceId(), catalogSubscribeTask, cron); subscribeCycleForCatalog = Math.max(subscribeCycleForCatalog, 30);
dynamicTask.startCron(device.getDeviceId(), catalogSubscribeTask, subscribeCycleForCatalog - 5);
return true; return true;
} }
@ -42,21 +46,10 @@ public class DeviceServiceImpl implements IDeviceService {
if (device == null || device.getSubscribeCycleForCatalog() < 0) { if (device == null || device.getSubscribeCycleForCatalog() < 0) {
return false; return false;
} }
logger.info("移除目录订阅【{}】", device.getDeviceId());
dynamicTask.stopCron(device.getDeviceId()); dynamicTask.stopCron(device.getDeviceId());
device.setSubscribeCycleForCatalog(0);
sipCommander.catalogSubscribe(device, null, null);
return true; 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 * * * ?";
}
}
} }

Loading…
Cancel
Save