StreamProxyTask.java
2.6 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package com.genersoft.iot.vmp.conf;
import com.genersoft.iot.vmp.service.StremProxyService1078;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.Date;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.TimeUnit;
@Component
public class StreamProxyTask {
@Autowired
private RedisTemplate redisTemplate;
@Autowired
private StremProxyService1078 stremProxyService1078;
private Logger logger = LoggerFactory.getLogger(StreamProxyTask.class);
public static final Long TIME_OUT = 180L;
@Scheduled(cron = "0 15 * * * ? ")
public void work() {
Set<String> keys = redisTemplate.keys("tag:history:port:*");
if (CollectionUtils.isEmpty(keys)) {
return;
}
Long nowDate = new Date().getTime();
for (String key : keys) {
String stream = StringUtils.substringAfter(key, "tag:history:port:");
if (StringUtils.isEmpty(stream)) {
continue;
}
Object value = redisTemplate.opsForValue().get("tag:history:httpPort:time:"+stream);
if(Objects.isNull(value)){
sendIORequestStop(stream);
continue;
}
try {
Long val = (Long) value;
if(val == 0L){
sendIORequestStop(stream);
continue;
}
Long val1 = (nowDate-val)/1000;
if(val1 > TIME_OUT){
sendIORequestStop(stream);
}
}catch (Exception e){
logger.error("[{}]停流失败",stream,e);
}
}
// task execution logic
}
private void sendIORequestStop(String stream){
try {
String sim = StringUtils.substringBeforeLast(stream,"-");
String channel = StringUtils.substringAfterLast(stream,"-");
Object port = redisTemplate.opsForValue().get("tag:history:port:" + stream);
Object portHtt = redisTemplate.opsForValue().get("tag:history:httpPort:" + stream);
stremProxyService1078.sendIORequestStop(sim,channel,stream, (Integer) port, (Integer) portHtt);
}catch (Exception e){
logger.error("[{}]停流失败",stream,e);
}
}
}