优化订阅信息的发送与取消订阅
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
package com.genersoft.iot.vmp.gb28181.task;
|
||||
|
||||
public interface ISubscribeTask extends Runnable{
|
||||
void stop();
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package com.genersoft.iot.vmp.gb28181.task.impl;
|
||||
|
||||
import com.genersoft.iot.vmp.gb28181.bean.Device;
|
||||
import com.genersoft.iot.vmp.gb28181.task.ISubscribeTask;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommander;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.sip.Dialog;
|
||||
import javax.sip.DialogState;
|
||||
import javax.sip.ResponseEvent;
|
||||
|
||||
/**
|
||||
* 目录订阅任务
|
||||
*/
|
||||
public class CatalogSubscribeTask implements ISubscribeTask {
|
||||
private final Logger logger = LoggerFactory.getLogger(CatalogSubscribeTask.class);
|
||||
private Device device;
|
||||
private final ISIPCommander sipCommander;
|
||||
private Dialog dialog;
|
||||
|
||||
public CatalogSubscribeTask(Device device, ISIPCommander sipCommander) {
|
||||
this.device = device;
|
||||
this.sipCommander = sipCommander;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
sipCommander.catalogSubscribe(device, dialog, eventResult -> {
|
||||
if (eventResult.dialog != null || eventResult.dialog.getState().equals(DialogState.CONFIRMED)) {
|
||||
dialog = eventResult.dialog;
|
||||
}
|
||||
ResponseEvent event = (ResponseEvent) eventResult.event;
|
||||
if (event.getResponse().getRawContent() != null) {
|
||||
// 成功
|
||||
logger.info("[目录订阅]成功: {}", device.getDeviceId());
|
||||
}else {
|
||||
// 成功
|
||||
logger.info("[目录订阅]成功: {}", device.getDeviceId());
|
||||
}
|
||||
},eventResult -> {
|
||||
dialog = null;
|
||||
// 失败
|
||||
logger.warn("[目录订阅]失败,信令发送失败: {}-{} ", device.getDeviceId(), eventResult.msg);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
/**
|
||||
* dialog 的各个状态
|
||||
* EARLY-> Early state状态-初始请求发送以后,收到了一个临时响应消息
|
||||
* CONFIRMED-> Confirmed Dialog状态-已确认
|
||||
* COMPLETED-> Completed Dialog状态-已完成
|
||||
* TERMINATED-> Terminated Dialog状态-终止
|
||||
*/
|
||||
logger.info("取消目录订阅时dialog状态为{}", DialogState.CONFIRMED);
|
||||
if (dialog != null && dialog.getState().equals(DialogState.CONFIRMED)) {
|
||||
device.setSubscribeCycleForCatalog(0);
|
||||
sipCommander.mobilePositionSubscribe(device, dialog, 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,10 +1,10 @@
|
||||
package com.genersoft.iot.vmp.gb28181.task;
|
||||
package com.genersoft.iot.vmp.gb28181.task.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.GbStream;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.SubscribeHolder;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.SubscribeInfo;
|
||||
import com.genersoft.iot.vmp.gb28181.task.ISubscribeTask;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform;
|
||||
import com.genersoft.iot.vmp.service.bean.GPSMsgInfo;
|
||||
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
||||
@@ -13,7 +13,10 @@ import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.List;
|
||||
|
||||
public class GPSSubscribeTask implements Runnable{
|
||||
/**
|
||||
* 向已经订阅(移动位置)的上级发送MobilePosition消息
|
||||
*/
|
||||
public class MobilePositionSubscribeHandlerTask implements ISubscribeTask {
|
||||
|
||||
private IRedisCatchStorage redisCatchStorage;
|
||||
private IVideoManagerStorage storager;
|
||||
@@ -25,7 +28,7 @@ public class GPSSubscribeTask implements Runnable{
|
||||
|
||||
private final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
public GPSSubscribeTask(IRedisCatchStorage redisCatchStorage, ISIPCommanderForPlatform sipCommanderForPlatform, IVideoManagerStorage storager, String platformId, String sn, String key, SubscribeHolder subscribeInfo) {
|
||||
public MobilePositionSubscribeHandlerTask(IRedisCatchStorage redisCatchStorage, ISIPCommanderForPlatform sipCommanderForPlatform, IVideoManagerStorage storager, String platformId, String sn, String key, SubscribeHolder subscribeInfo) {
|
||||
this.redisCatchStorage = redisCatchStorage;
|
||||
this.storager = storager;
|
||||
this.platformId = platformId;
|
||||
@@ -66,4 +69,9 @@ public class GPSSubscribeTask implements Runnable{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package com.genersoft.iot.vmp.gb28181.task.impl;
|
||||
|
||||
import com.genersoft.iot.vmp.gb28181.bean.Device;
|
||||
import com.genersoft.iot.vmp.gb28181.task.ISubscribeTask;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommander;
|
||||
import org.dom4j.Element;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.sip.Dialog;
|
||||
import javax.sip.DialogState;
|
||||
import javax.sip.ResponseEvent;
|
||||
|
||||
/**
|
||||
* 移动位置订阅的定时更新
|
||||
*/
|
||||
public class MobilePositionSubscribeTask implements ISubscribeTask {
|
||||
private final Logger logger = LoggerFactory.getLogger(MobilePositionSubscribeTask.class);
|
||||
private Device device;
|
||||
private ISIPCommander sipCommander;
|
||||
private Dialog dialog;
|
||||
|
||||
public MobilePositionSubscribeTask(Device device, ISIPCommander sipCommander) {
|
||||
this.device = device;
|
||||
this.sipCommander = sipCommander;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
sipCommander.mobilePositionSubscribe(device, dialog, eventResult -> {
|
||||
if (eventResult.dialog != null || eventResult.dialog.getState().equals(DialogState.CONFIRMED)) {
|
||||
dialog = eventResult.dialog;
|
||||
}
|
||||
ResponseEvent event = (ResponseEvent) eventResult.event;
|
||||
if (event.getResponse().getRawContent() != null) {
|
||||
// 成功
|
||||
logger.info("[移动位置订阅]成功: {}", device.getDeviceId());
|
||||
}else {
|
||||
// 成功
|
||||
logger.info("[移动位置订阅]成功: {}", device.getDeviceId());
|
||||
}
|
||||
},eventResult -> {
|
||||
dialog = null;
|
||||
// 失败
|
||||
logger.warn("[移动位置订阅]失败,信令发送失败: {}-{} ", device.getDeviceId(), eventResult.msg);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
/**
|
||||
* dialog 的各个状态
|
||||
* EARLY-> Early state状态-初始请求发送以后,收到了一个临时响应消息
|
||||
* CONFIRMED-> Confirmed Dialog状态-已确认
|
||||
* COMPLETED-> Completed Dialog状态-已完成
|
||||
* TERMINATED-> Terminated Dialog状态-终止
|
||||
*/
|
||||
logger.info("取消移动订阅时dialog状态为{}", dialog.getState());
|
||||
if (dialog != null && dialog.getState().equals(DialogState.CONFIRMED)) {
|
||||
device.setSubscribeCycleForMobilePosition(0);
|
||||
sipCommander.mobilePositionSubscribe(device, dialog, 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);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user