优化设备在线状态

This commit is contained in:
648540858
2022-05-11 18:37:24 +08:00
parent c395cf42d1
commit f6893cf95b
52 changed files with 571 additions and 802 deletions

View File

@@ -4,6 +4,7 @@ import com.genersoft.iot.vmp.common.ApiSaveConstant;
import com.genersoft.iot.vmp.conf.security.SecurityUtils;
import com.genersoft.iot.vmp.service.ILogService;
import com.genersoft.iot.vmp.storager.dao.dto.LogDto;
import com.genersoft.iot.vmp.utils.DateUtil;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -16,7 +17,6 @@ import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.SimpleDateFormat;
/**
* @author lin
@@ -26,7 +26,6 @@ public class ApiAccessFilter extends OncePerRequestFilter {
private final static Logger logger = LoggerFactory.getLogger(ApiAccessFilter.class);
private final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
@Autowired
private UserSetting userSetting;
@@ -58,7 +57,7 @@ public class ApiAccessFilter extends OncePerRequestFilter {
logDto.setTiming(System.currentTimeMillis() - start);
logDto.setType(servletRequest.getMethod());
logDto.setUri(servletRequest.getRequestURI());
logDto.setCreateTime(format.format(System.currentTimeMillis()));
logDto.setCreateTime(DateUtil.getNow());
logService.add(logDto);
// logger.warn("[Api Access] [{}] [{}] [{}] [{}] [{}] {}ms",
// uriName, servletRequest.getMethod(), servletRequest.getRequestURI(), servletRequest.getRemoteAddr(), HttpStatus.valueOf(servletResponse.getStatus()),

View File

@@ -43,27 +43,27 @@ public class DynamicTask {
* 循环执行的任务
* @param key 任务ID
* @param task 任务
* @param cycleForCatalog 间隔
* @param cycleForCatalog 间隔 毫秒
* @return
*/
public void startCron(String key, Runnable task, int cycleForCatalog) {
ScheduledFuture future = futureMap.get(key);
if (future != null) {
if (future.isCancelled()) {
logger.info("任务【{}】已存在但是关闭状态!!!", key);
logger.debug("任务【{}】已存在但是关闭状态!!!", key);
} else {
logger.info("任务【{}】已存在且已启动!!!", key);
logger.debug("任务【{}】已存在且已启动!!!", key);
return;
}
}
// scheduleWithFixedDelay 必须等待上一个任务结束才开始计时period cycleForCatalog表示执行的间隔
future = threadPoolTaskScheduler.scheduleAtFixedRate(task, cycleForCatalog * 1000L);
future = threadPoolTaskScheduler.scheduleAtFixedRate(task, cycleForCatalog);
if (future != null){
futureMap.put(key, future);
runnableMap.put(key, task);
logger.info("任务【{}】启动成功!!!", key);
logger.debug("任务【{}】启动成功!!!", key);
}else {
logger.info("任务【{}】启动失败!!!", key);
logger.debug("任务【{}】启动失败!!!", key);
}
}
@@ -81,9 +81,9 @@ public class DynamicTask {
ScheduledFuture future = futureMap.get(key);
if (future != null) {
if (future.isCancelled()) {
logger.info("任务【{}】已存在但是关闭状态!!!", key);
logger.debug("任务【{}】已存在但是关闭状态!!!", key);
} else {
logger.info("任务【{}】已存在且已启动!!!", key);
logger.debug("任务【{}】已存在且已启动!!!", key);
return;
}
}
@@ -92,9 +92,9 @@ public class DynamicTask {
if (future != null){
futureMap.put(key, future);
runnableMap.put(key, task);
logger.info("任务【{}】启动成功!!!", key);
logger.debug("任务【{}】启动成功!!!", key);
}else {
logger.info("任务【{}】启动失败!!!", key);
logger.debug("任务【{}】启动失败!!!", key);
}
}

View File

@@ -1,12 +1,11 @@
package com.genersoft.iot.vmp.conf;
import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
import com.genersoft.iot.vmp.utils.DateUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.StringUtils;
import java.text.SimpleDateFormat;
import java.util.Date;
@Configuration("mediaConfig")
public class MediaConfig{
@@ -206,9 +205,8 @@ public class MediaConfig{
mediaServerItem.setRecordAssistPort(recordAssistPort);
mediaServerItem.setHookAliveInterval(120);
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
mediaServerItem.setCreateTime(format.format(System.currentTimeMillis()));
mediaServerItem.setUpdateTime(format.format(System.currentTimeMillis()));
mediaServerItem.setCreateTime(DateUtil.getNow());
mediaServerItem.setUpdateTime(DateUtil.getNow());
return mediaServerItem;
}

View File

@@ -35,10 +35,11 @@ public class ThreadPoolTaskConfig {
* 允许线程空闲时间(单位:默认为秒)
*/
private static final int keepAliveTime = 30;
/**
* 缓冲队列大小
*/
private static final int queueCapacity = 500;
private static final int queueCapacity = 10000;
/**
* 线程池名前缀
*/

View File

@@ -1,59 +0,0 @@
package com.genersoft.iot.vmp.conf.runner;
import com.genersoft.iot.vmp.conf.UserSetting;
import com.genersoft.iot.vmp.gb28181.bean.Device;
import com.genersoft.iot.vmp.service.IDeviceService;
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import java.util.List;
/**
* 系统启动时控制设备
*/
@Component
@Order(value=4)
public class SipDeviceRunner implements CommandLineRunner {
@Autowired
private IVideoManagerStorage storager;
@Autowired
private IRedisCatchStorage redisCatchStorage;
@Autowired
private UserSetting userSetting;
@Autowired
private IDeviceService deviceService;
@Override
public void run(String... args) throws Exception {
// 读取redis没有心跳信息的则设置为离线等收到下次心跳设置为在线
// 设置所有设备离线
storager.outlineForAll();
List<String> onlineForAll = redisCatchStorage.getOnlineForAll();
for (String deviceId : onlineForAll) {
storager.online(deviceId);
Device device = redisCatchStorage.getDevice(deviceId);
if (device != null ) {
if (device.getSubscribeCycleForCatalog() > 0) {
// 查询在线设备那些开启了订阅,为设备开启定时的目录订阅
deviceService.addCatalogSubscribe(device);
}
if (device.getSubscribeCycleForMobilePosition() > 0) {
deviceService.addMobilePositionSubscribe(device);
}
}
}
// 重置cseq计数
redisCatchStorage.resetAllCSEQ();
}
}