ydpd
2022-03-02 e66b83965943e8471d5e2fb616899e0c8271e840
src/main/java/com/genersoft/iot/vmp/gb28181/event/SipSubscribe.java
@@ -1,5 +1,6 @@
package com.genersoft.iot.vmp.gb28181.event;
import com.genersoft.iot.vmp.gb28181.bean.DeviceNotFoundEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
@@ -22,7 +23,8 @@
    private Map<String, SipSubscribe.Event> okSubscribes = new ConcurrentHashMap<>();
    private Map<String, Date> timeSubscribes = new ConcurrentHashMap<>();
    private Map<String, Date> okTimeSubscribes = new ConcurrentHashMap<>();
    private Map<String, Date> errorTimeSubscribes = new ConcurrentHashMap<>();
//    @Scheduled(cron="*/5 * * * * ?")   //每五秒执行一次
//    @Scheduled(fixedRate= 100 * 60 * 60 )
@@ -32,14 +34,24 @@
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        calendar.set(Calendar.HOUR, calendar.get(Calendar.HOUR) - 1);
        for (String key : timeSubscribes.keySet()) {
            if (timeSubscribes.get(key).before(calendar.getTime())){
        for (String key : okTimeSubscribes.keySet()) {
            if (okTimeSubscribes.get(key).before(calendar.getTime())){
                logger.info("[定时任务] 清理过期的订阅信息: {}", key);
                errorSubscribes.remove(key);
                okSubscribes.remove(key);
                timeSubscribes.remove(key);
                okTimeSubscribes.remove(key);
            }
        }
        for (String key : errorTimeSubscribes.keySet()) {
            if (errorTimeSubscribes.get(key).before(calendar.getTime())){
                logger.info("[定时任务] 清理过期的订阅信息: {}", key);
                errorSubscribes.remove(key);
                errorTimeSubscribes.remove(key);
            }
        }
        logger.info("okTimeSubscribes.size:{}",okTimeSubscribes.size());
        logger.info("okSubscribes.size:{}",okSubscribes.size());
        logger.info("errorTimeSubscribes.size:{}",errorTimeSubscribes.size());
        logger.info("errorSubscribes.size:{}",errorSubscribes.size());
    }
    public interface Event {
@@ -91,6 +103,13 @@
                this.statusCode = -1024;
                this.callId = dialogTerminatedEvent.getDialog().getCallId().getCallId();
                this.dialog = dialogTerminatedEvent.getDialog();
            }else if (event instanceof DeviceNotFoundEvent) {
                DeviceNotFoundEvent deviceNotFoundEvent = (DeviceNotFoundEvent)event;
                this.type = "deviceNotFoundEvent";
                this.msg = "设备未找到";
                this.statusCode = -1024;
                this.callId = deviceNotFoundEvent.getDialog().getCallId().getCallId();
                this.dialog = deviceNotFoundEvent.getDialog();
            }
        }
    }