优化订阅信息的发送与取消订阅
This commit is contained in:
@@ -1,42 +0,0 @@
|
||||
package com.genersoft.iot.vmp.service.bean;
|
||||
|
||||
import com.genersoft.iot.vmp.gb28181.bean.Device;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommander;
|
||||
import com.genersoft.iot.vmp.gb28181.utils.XmlUtil;
|
||||
import org.dom4j.DocumentException;
|
||||
import org.dom4j.Element;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.sip.ResponseEvent;
|
||||
|
||||
/**
|
||||
* 目录订阅任务
|
||||
*/
|
||||
public class CatalogSubscribeTask implements Runnable{
|
||||
private final Logger logger = LoggerFactory.getLogger(CatalogSubscribeTask.class);
|
||||
private Device device;
|
||||
private ISIPCommander sipCommander;
|
||||
|
||||
public CatalogSubscribeTask(Device device, ISIPCommander sipCommander) {
|
||||
this.device = device;
|
||||
this.sipCommander = sipCommander;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
sipCommander.catalogSubscribe(device, eventResult -> {
|
||||
ResponseEvent event = (ResponseEvent) eventResult.event;
|
||||
if (event.getResponse().getRawContent() != null) {
|
||||
// 成功
|
||||
logger.info("[目录订阅]成功: {}", device.getDeviceId());
|
||||
}else {
|
||||
// 成功
|
||||
logger.info("[目录订阅]成功: {}", device.getDeviceId());
|
||||
}
|
||||
},eventResult -> {
|
||||
// 失败
|
||||
logger.warn("[目录订阅]失败,信令发送失败: {}-{} ", device.getDeviceId(), eventResult.msg);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
package com.genersoft.iot.vmp.service.bean;
|
||||
|
||||
import com.genersoft.iot.vmp.gb28181.bean.Device;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommander;
|
||||
import org.dom4j.Element;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.sip.ResponseEvent;
|
||||
|
||||
public class MobilePositionSubscribeTask implements Runnable{
|
||||
private final Logger logger = LoggerFactory.getLogger(MobilePositionSubscribeTask.class);
|
||||
private Device device;
|
||||
private ISIPCommander sipCommander;
|
||||
|
||||
public MobilePositionSubscribeTask(Device device, ISIPCommander sipCommander) {
|
||||
this.device = device;
|
||||
this.sipCommander = sipCommander;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
sipCommander.mobilePositionSubscribe(device, eventResult -> {
|
||||
ResponseEvent event = (ResponseEvent) eventResult.event;
|
||||
Element rootElement = null;
|
||||
if (event.getResponse().getRawContent() != null) {
|
||||
// 成功
|
||||
logger.info("[移动位置订阅]成功: {}", device.getDeviceId());
|
||||
}else {
|
||||
// 成功
|
||||
logger.info("[移动位置订阅]成功: {}", device.getDeviceId());
|
||||
}
|
||||
},eventResult -> {
|
||||
// 失败
|
||||
logger.warn("[移动位置订阅]失败,信令发送失败: {}-{} ", device.getDeviceId(), eventResult.msg);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -4,8 +4,8 @@ import com.genersoft.iot.vmp.conf.DynamicTask;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.Device;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommander;
|
||||
import com.genersoft.iot.vmp.service.IDeviceService;
|
||||
import com.genersoft.iot.vmp.service.bean.CatalogSubscribeTask;
|
||||
import com.genersoft.iot.vmp.service.bean.MobilePositionSubscribeTask;
|
||||
import com.genersoft.iot.vmp.gb28181.task.impl.CatalogSubscribeTask;
|
||||
import com.genersoft.iot.vmp.gb28181.task.impl.MobilePositionSubscribeTask;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -42,7 +42,7 @@ public class DeviceServiceImpl implements IDeviceService {
|
||||
int subscribeCycleForCatalog = device.getSubscribeCycleForCatalog();
|
||||
// 设置最小值为30
|
||||
subscribeCycleForCatalog = Math.max(subscribeCycleForCatalog, 30);
|
||||
dynamicTask.startCron(device.getDeviceId() + "catalog", catalogSubscribeTask, subscribeCycleForCatalog - 5);
|
||||
dynamicTask.startCron(device.getDeviceId() + "catalog", catalogSubscribeTask, subscribeCycleForCatalog);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -53,8 +53,6 @@ public class DeviceServiceImpl implements IDeviceService {
|
||||
}
|
||||
logger.info("移除目录订阅: {}", device.getDeviceId());
|
||||
dynamicTask.stop(device.getDeviceId() + "catalog");
|
||||
device.setSubscribeCycleForCatalog(0);
|
||||
sipCommander.catalogSubscribe(device, null, null);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -75,7 +73,7 @@ public class DeviceServiceImpl implements IDeviceService {
|
||||
int subscribeCycleForCatalog = device.getSubscribeCycleForCatalog();
|
||||
// 设置最小值为30
|
||||
subscribeCycleForCatalog = Math.max(subscribeCycleForCatalog, 30);
|
||||
dynamicTask.startCron(device.getDeviceId() + "mobile_position" , mobilePositionSubscribeTask, subscribeCycleForCatalog - 5);
|
||||
dynamicTask.startCron(device.getDeviceId() + "mobile_position" , mobilePositionSubscribeTask, subscribeCycleForCatalog -1 );
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -86,8 +84,6 @@ public class DeviceServiceImpl implements IDeviceService {
|
||||
}
|
||||
logger.info("移除移动位置订阅: {}", device.getDeviceId());
|
||||
dynamicTask.stop(device.getDeviceId() + "mobile_position");
|
||||
device.setSubscribeCycleForCatalog(0);
|
||||
sipCommander.mobilePositionSubscribe(device, null, null);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user