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 "子任务执行完成";
|
}
|
|
}
|