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

This commit is contained in:
648540858 2021-11-16 18:15:33 +08:00
parent 41f3c11e7d
commit 12b9f4d3db
6 changed files with 15 additions and 24 deletions

View File

@ -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";
}

View File

@ -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);
}

View File

@ -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");

View File

@ -1486,7 +1486,7 @@ public class SIPCommander implements ISIPCommander {
StringBuffer cmdXml = new StringBuffer(200);
cmdXml.append("<?xml version=\"1.0\" encoding=\"GB2312\"?>\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("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
cmdXml.append("</Query>\r\n");

View File

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

View File

@ -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 * * * ?";
}
}
}