VaServerCheckRunner.java
2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package com.viontech.fanxing.task.runner;
import com.alibaba.fastjson.JSONObject;
import com.viontech.fanxing.task.model.vaserver.VaServerInfo;
import com.viontech.fanxing.task.service.VAServerService;
import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RLock;
import org.redisson.api.RMap;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.Map;
import java.util.Set;
/**
* .
*
* @author 谢明辉
* @date 2021/10/19
*/
@Component
@Slf4j
public class VaServerCheckRunner {
@Resource
private VAServerService vaServerService;
@Scheduled(cron = "3 0/5 * * * ? ")
public void check() {
try {
RMap<String, VaServerInfo> vaServerInfoMap = vaServerService.getVaServerRedisRepository().getVaServerInfoMap();
Set<Map.Entry<String, VaServerInfo>> entries = vaServerInfoMap.readAllEntrySet();
for (Map.Entry<String, VaServerInfo> entry : entries) {
RLock devLock = null;
try {
String devId = entry.getKey();
VaServerInfo vaServerInfo = entry.getValue();
if (vaServerInfo.getStatus() == 1) {
devLock = vaServerService.getVaServerRedisRepository().getDevLock(devId);
JSONObject status = vaServerService.getStatus(devId);
JSONObject resource = status.getJSONObject("resource");
JSONObject brief = resource.getJSONObject("brief");
float videoResource = brief.getFloatValue("video_total");
float availableResource = brief.getFloatValue("video_free");
vaServerInfo.setAvailableResources(availableResource);
vaServerInfo.setVideoResource(videoResource);
vaServerService.getVaServerRedisRepository().addOrUpdate(devId, vaServerInfo);
} else {
log.info("设备处于离线状态:{}", devId);
}
} catch (Exception e) {
log.info("", e);
if (devLock != null) {
devLock.forceUnlock();
}
}
}
} catch (Exception e) {
log.error("", e);
}
}
}