使用阿里代码规范。规范代码写法
This commit is contained in:
@@ -2,6 +2,9 @@ package com.genersoft.iot.vmp.gb28181.task;
|
||||
|
||||
import javax.sip.DialogState;
|
||||
|
||||
/**
|
||||
* @author lin
|
||||
*/
|
||||
public interface ISubscribeTask extends Runnable{
|
||||
void stop();
|
||||
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
package com.genersoft.iot.vmp.gb28181.task.impl;
|
||||
|
||||
import com.genersoft.iot.vmp.conf.DynamicTask;
|
||||
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 org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
|
||||
import javax.sip.Dialog;
|
||||
import javax.sip.DialogState;
|
||||
@@ -15,6 +17,7 @@ import java.util.TimerTask;
|
||||
|
||||
/**
|
||||
* 目录订阅任务
|
||||
* @author lin
|
||||
*/
|
||||
public class CatalogSubscribeTask implements ISubscribeTask {
|
||||
private final Logger logger = LoggerFactory.getLogger(CatalogSubscribeTask.class);
|
||||
@@ -22,18 +25,21 @@ public class CatalogSubscribeTask implements ISubscribeTask {
|
||||
private final ISIPCommander sipCommander;
|
||||
private Dialog dialog;
|
||||
|
||||
private Timer timer ;
|
||||
private DynamicTask dynamicTask;
|
||||
|
||||
public CatalogSubscribeTask(Device device, ISIPCommander sipCommander) {
|
||||
private String taskKey = "catalog-subscribe-timeout";
|
||||
|
||||
|
||||
public CatalogSubscribeTask(Device device, ISIPCommander sipCommander, DynamicTask dynamicTask) {
|
||||
this.device = device;
|
||||
this.sipCommander = sipCommander;
|
||||
this.dynamicTask = dynamicTask;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (timer != null ) {
|
||||
timer.cancel();
|
||||
timer = null;
|
||||
if (dynamicTask.get(taskKey) != null) {
|
||||
dynamicTask.stop(taskKey);
|
||||
}
|
||||
sipCommander.catalogSubscribe(device, dialog, eventResult -> {
|
||||
if (eventResult.dialog != null || eventResult.dialog.getState().equals(DialogState.CONFIRMED)) {
|
||||
@@ -51,13 +57,7 @@ public class CatalogSubscribeTask implements ISubscribeTask {
|
||||
dialog = null;
|
||||
// 失败
|
||||
logger.warn("[目录订阅]失败,信令发送失败: {}-{} ", device.getDeviceId(), eventResult.msg);
|
||||
timer = new Timer();
|
||||
timer.schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
CatalogSubscribeTask.this.run();
|
||||
}
|
||||
}, 2000);
|
||||
dynamicTask.startDelay(taskKey, CatalogSubscribeTask.this, 2000);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -71,9 +71,8 @@ public class CatalogSubscribeTask implements ISubscribeTask {
|
||||
* TERMINATED-> Terminated Dialog状态-终止
|
||||
*/
|
||||
logger.info("取消目录订阅时dialog状态为{}", DialogState.CONFIRMED);
|
||||
if (timer != null ) {
|
||||
timer.cancel();
|
||||
timer = null;
|
||||
if (dynamicTask.get(taskKey) != null) {
|
||||
dynamicTask.stop(taskKey);
|
||||
}
|
||||
if (dialog != null && dialog.getState().equals(DialogState.CONFIRMED)) {
|
||||
device.setSubscribeCycleForCatalog(0);
|
||||
@@ -95,7 +94,9 @@ public class CatalogSubscribeTask implements ISubscribeTask {
|
||||
|
||||
@Override
|
||||
public DialogState getDialogState() {
|
||||
if (dialog == null) return null;
|
||||
if (dialog == null) {
|
||||
return null;
|
||||
}
|
||||
return dialog.getState();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.genersoft.iot.vmp.gb28181.task.impl;
|
||||
|
||||
import com.genersoft.iot.vmp.conf.DynamicTask;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.*;
|
||||
import com.genersoft.iot.vmp.gb28181.task.ISubscribeTask;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform;
|
||||
@@ -15,6 +16,7 @@ import java.util.List;
|
||||
|
||||
/**
|
||||
* 向已经订阅(移动位置)的上级发送MobilePosition消息
|
||||
* @author lin
|
||||
*/
|
||||
public class MobilePositionSubscribeHandlerTask implements ISubscribeTask {
|
||||
|
||||
@@ -25,10 +27,18 @@ public class MobilePositionSubscribeHandlerTask implements ISubscribeTask {
|
||||
private ISIPCommanderForPlatform sipCommanderForPlatform;
|
||||
private SubscribeHolder subscribeHolder;
|
||||
private ParentPlatform platform;
|
||||
|
||||
private String sn;
|
||||
private String key;
|
||||
|
||||
public MobilePositionSubscribeHandlerTask(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,
|
||||
DynamicTask dynamicTask) {
|
||||
this.redisCatchStorage = redisCatchStorage;
|
||||
this.storager = storager;
|
||||
this.platform = storager.queryParentPlatByServerGBId(platformId);
|
||||
@@ -41,7 +51,9 @@ public class MobilePositionSubscribeHandlerTask implements ISubscribeTask {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
if (platform == null) return;
|
||||
if (platform == null) {
|
||||
return;
|
||||
}
|
||||
SubscribeInfo subscribe = subscribeHolder.getMobilePositionSubscribe(platform.getServerGBId());
|
||||
if (subscribe != null) {
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.genersoft.iot.vmp.gb28181.task.impl;
|
||||
|
||||
import com.genersoft.iot.vmp.conf.DynamicTask;
|
||||
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;
|
||||
@@ -16,25 +17,26 @@ import java.util.TimerTask;
|
||||
|
||||
/**
|
||||
* 移动位置订阅的定时更新
|
||||
* @author lin
|
||||
*/
|
||||
public class MobilePositionSubscribeTask implements ISubscribeTask {
|
||||
private final Logger logger = LoggerFactory.getLogger(MobilePositionSubscribeTask.class);
|
||||
private Device device;
|
||||
private ISIPCommander sipCommander;
|
||||
private Dialog dialog;
|
||||
private DynamicTask dynamicTask;
|
||||
private String taskKey = "mobile-position-subscribe-timeout";
|
||||
|
||||
private Timer timer ;
|
||||
|
||||
public MobilePositionSubscribeTask(Device device, ISIPCommander sipCommander) {
|
||||
public MobilePositionSubscribeTask(Device device, ISIPCommander sipCommander, DynamicTask dynamicTask) {
|
||||
this.device = device;
|
||||
this.sipCommander = sipCommander;
|
||||
this.dynamicTask = dynamicTask;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (timer != null ) {
|
||||
timer.cancel();
|
||||
timer = null;
|
||||
if (dynamicTask.get(taskKey) != null) {
|
||||
dynamicTask.stop(taskKey);
|
||||
}
|
||||
sipCommander.mobilePositionSubscribe(device, dialog, eventResult -> {
|
||||
// if (eventResult.dialog != null || eventResult.dialog.getState().equals(DialogState.CONFIRMED)) {
|
||||
@@ -52,13 +54,7 @@ public class MobilePositionSubscribeTask implements ISubscribeTask {
|
||||
dialog = null;
|
||||
// 失败
|
||||
logger.warn("[移动位置订阅]失败,信令发送失败: {}-{} ", device.getDeviceId(), eventResult.msg);
|
||||
timer = new Timer();
|
||||
timer.schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
MobilePositionSubscribeTask.this.run();
|
||||
}
|
||||
}, 2000);
|
||||
dynamicTask.startDelay(taskKey, MobilePositionSubscribeTask.this, 2000);
|
||||
});
|
||||
|
||||
}
|
||||
@@ -72,9 +68,8 @@ public class MobilePositionSubscribeTask implements ISubscribeTask {
|
||||
* COMPLETED-> Completed Dialog状态-已完成
|
||||
* TERMINATED-> Terminated Dialog状态-终止
|
||||
*/
|
||||
if (timer != null ) {
|
||||
timer.cancel();
|
||||
timer = null;
|
||||
if (dynamicTask.get(taskKey) != null) {
|
||||
dynamicTask.stop(taskKey);
|
||||
}
|
||||
if (dialog != null && dialog.getState().equals(DialogState.CONFIRMED)) {
|
||||
logger.info("取消移动订阅时dialog状态为{}", dialog.getState());
|
||||
@@ -96,7 +91,9 @@ public class MobilePositionSubscribeTask implements ISubscribeTask {
|
||||
}
|
||||
@Override
|
||||
public DialogState getDialogState() {
|
||||
if (dialog == null) return null;
|
||||
if (dialog == null) {
|
||||
return null;
|
||||
}
|
||||
return dialog.getState();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user