commit
0993bedb46
@ -23,24 +23,36 @@ public class SipSubscribe {
|
|||||||
|
|
||||||
private Map<String, SipSubscribe.Event> okSubscribes = new ConcurrentHashMap<>();
|
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(cron="*/5 * * * * ?") //每五秒执行一次
|
||||||
// @Scheduled(fixedRate= 100 * 60 * 60 )
|
// @Scheduled(fixedRate= 100 * 60 * 60 )
|
||||||
@Scheduled(cron="0 0 * * * ?") //每小时执行一次, 每个整点
|
@Scheduled(cron="0 0/5 * * * ?") //每5分钟执行一次
|
||||||
public void execute(){
|
public void execute(){
|
||||||
logger.info("[定时任务] 清理过期的订阅信息");
|
logger.info("[定时任务] 清理过期的订阅信息");
|
||||||
Calendar calendar = Calendar.getInstance();
|
Calendar calendar = Calendar.getInstance();
|
||||||
calendar.setTime(new Date());
|
calendar.setTime(new Date());
|
||||||
calendar.set(Calendar.HOUR, calendar.get(Calendar.HOUR) - 1);
|
calendar.set(Calendar.MINUTE, calendar.get(Calendar.MINUTE) - 5);
|
||||||
for (String key : timeSubscribes.keySet()) {
|
|
||||||
if (timeSubscribes.get(key).before(calendar.getTime())){
|
for (String key : okTimeSubscribes.keySet()) {
|
||||||
logger.info("[定时任务] 清理过期的订阅信息: {}", key);
|
if (okTimeSubscribes.get(key).before(calendar.getTime())){
|
||||||
errorSubscribes.remove(key);
|
// logger.info("[定时任务] 清理过期的订阅信息: {}", key);
|
||||||
okSubscribes.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 {
|
public interface Event {
|
||||||
@ -105,12 +117,12 @@ public class SipSubscribe {
|
|||||||
|
|
||||||
public void addErrorSubscribe(String key, SipSubscribe.Event event) {
|
public void addErrorSubscribe(String key, SipSubscribe.Event event) {
|
||||||
errorSubscribes.put(key, event);
|
errorSubscribes.put(key, event);
|
||||||
timeSubscribes.put(key, new Date());
|
errorTimeSubscribes.put(key, new Date());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addOkSubscribe(String key, SipSubscribe.Event event) {
|
public void addOkSubscribe(String key, SipSubscribe.Event event) {
|
||||||
okSubscribes.put(key, event);
|
okSubscribes.put(key, event);
|
||||||
timeSubscribes.put(key, new Date());
|
okTimeSubscribes.put(key, new Date());
|
||||||
}
|
}
|
||||||
|
|
||||||
public SipSubscribe.Event getErrorSubscribe(String key) {
|
public SipSubscribe.Event getErrorSubscribe(String key) {
|
||||||
@ -119,7 +131,7 @@ public class SipSubscribe {
|
|||||||
|
|
||||||
public void removeErrorSubscribe(String key) {
|
public void removeErrorSubscribe(String key) {
|
||||||
errorSubscribes.remove(key);
|
errorSubscribes.remove(key);
|
||||||
timeSubscribes.remove(key);
|
errorTimeSubscribes.remove(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SipSubscribe.Event getOkSubscribe(String key) {
|
public SipSubscribe.Event getOkSubscribe(String key) {
|
||||||
@ -128,7 +140,7 @@ public class SipSubscribe {
|
|||||||
|
|
||||||
public void removeOkSubscribe(String key) {
|
public void removeOkSubscribe(String key) {
|
||||||
okSubscribes.remove(key);
|
okSubscribes.remove(key);
|
||||||
timeSubscribes.remove(key);
|
okTimeSubscribes.remove(key);
|
||||||
}
|
}
|
||||||
public int getErrorSubscribesSize(){
|
public int getErrorSubscribesSize(){
|
||||||
return errorSubscribes.size();
|
return errorSubscribes.size();
|
||||||
|
Loading…
Reference in New Issue
Block a user