vince
2023-09-04 e241acb82959328535d8f903902863bd420df139
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package com.ld.igds.protocol.zldz.task;
 
import com.ld.igds.protocol.zldz.command.BaseRemoteImpl;
import com.ld.igds.util.RedisUtil;
import lombok.extern.slf4j.Slf4j;
 
import java.util.concurrent.Callable;
 
/**
 * 子任务,用于判断重发和异常处理,命令发送后将命令信息存放缓存,当前
 *
 * @author andy.jia
 */
@Slf4j
public class ReSendCommonTask extends BaseRemoteImpl implements Callable<String> {
 
    private CommandTask commandData;
 
    private RedisUtil redisUtil;
 
    private String redisKey;
 
    public RedisUtil getRedisUtil() {
        return redisUtil;
    }
 
    public void setRedisUtil(RedisUtil redisUtil) {
        this.redisUtil = redisUtil;
    }
 
    public String getRedisKey() {
        return redisKey;
    }
 
    public void setRedisKey(String redisKey) {
        this.redisKey = redisKey;
    }
 
    public void setCommandData(CommandTask commandData) {
        this.commandData = commandData;
    }
 
    public CommandTask getCommandData() {
        return commandData;
    }
 
    public ReSendCommonTask() {
        super();
    }
 
    public ReSendCommonTask(CommandTask commandData, RedisUtil redisUtil, String redisKey) {
        super();
        this.commandData = commandData;
        this.redisUtil = redisUtil;
        this.redisKey = redisKey;
    }
 
    @Override
    public String call() throws Exception {
 
        //1,获取缓存中信息
        Thread.sleep(15 * 1000);
 
        CommandTask redisData = (CommandTask) redisUtil.get(redisKey);
        if (null == redisData) {
            return "命令第1次等待,终端已经正常返回";
        } else {
            log.info("{}-第1次命令补发命令={}", commandData.getIp(), commandData.getCommand());
            super.send(commandData.getIp(), commandData.getPort(), commandData.getByteCommand());
        }
 
        //2,等待20S
        Thread.sleep(15 * 1000);
        redisData = (CommandTask) redisUtil.get(redisKey);
        if (null == redisData) {
            return "命令第2次等等,终端已经正常返回";
        } else {
            log.info("{}-第2次命令补命令={}", commandData.getIp(), commandData.getCommand());
            super.send(commandData.getIp(), commandData.getPort(), commandData.getByteCommand());
        }
 
        //2,等待20S
        Thread.sleep(15 * 1000);
        redisData = (CommandTask) redisUtil.get(redisKey);
        if (null == redisData) {
            return "命令第3次等等,终端已经正常返回";
        } else {
            log.info("{}-第3次命令补发后,仍然没有返回,取消等待。", commandData.getIp());
            //super.destory(commandData.getIp(), commandData.getPort());
        }
 
        return "子任务执行完成";
    }
 
}