fix: 调整61850断线重连和日志告警

dev
huangfeng 8 months ago
parent f8fcabc730
commit a86f937481

@ -3,6 +3,7 @@ package com.xydl.cac.iec;
import com.beanit.iec61850bean.*;
import com.xydl.cac.entity.IcdIed;
import com.xydl.cac.entity.constants.Constants;
import com.xydl.cac.socket.WebSocketServer;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
@ -26,6 +27,7 @@ public class IecClient implements ClientEventListener {
public boolean keep = false;
public RealTimeDataService realTimeDataService;
public WebSocketServer webSocketServer;
int retry = 10;
public void connect(IcdIed _ied, String xml) throws Exception {
@ -71,7 +73,8 @@ public class IecClient implements ClientEventListener {
private void reconnect() throws Exception {
clientAssociation = clientSap.associate(InetAddress.getByName(ied.getIp()), ied.getPort(), null, this);
clientAssociation.setServerModel(serverModel);
log.info("61850断线重连成功, ied=" + ied.getName() + ", ip=" + ied.getIp() + ", port=" + ied.getPort());
log.info("61850订阅断线重连成功, ied=" + ied.getName() + ", ip=" + ied.getIp() + ", port=" + ied.getPort());
retry = 10;
}
public String getValue(String paramindex, String fc) throws Exception {
@ -141,36 +144,36 @@ public class IecClient implements ClientEventListener {
if (keep) {
this.disableReporting();
this.disconnect();
log.warn("61850订阅已断开, ied=" + ied.getName() + ", ip=" + ied.getIp() + ", port=" + ied.getPort());
while (retry > 0) {
retry--;
try {
if (retry <= 0) {
log.info("61850断线重连失败10次, 已断开不再重连. ied=" + ied.getName() + ", ip=" + ied.getIp() + ", port=" + ied.getPort());
if (realTimeDataService != null && ied != null) {
realTimeDataService.stopCollect(ied.getId());
}
} else {
if (retry >= 5) {
Thread.sleep(10 * 1000);
retry--;
this.reconnect();
} else if (retry == 4) {
log.info("61850断线重连失败6次, ied=" + ied.getName() + ", ip=" + ied.getIp() + ", port=" + ied.getPort());
log.warn("61850订阅断线重连已失败5次, ied=" + ied.getName() + ", ip=" + ied.getIp() + ", port=" + ied.getPort());
Thread.sleep(60 * 1000);
this.reconnect();
} else if (retry == 3) {
Thread.sleep(3 * 60 * 1000);
this.reconnect();
} else if (retry == 2) {
Thread.sleep(5 * 60 * 1000);
this.reconnect();
} else if (retry == 1) {
Thread.sleep(10 * 60 * 1000);
} else if (retry >= 1) {
Thread.sleep(60 * 1000);
this.reconnect();
} else {
String err = "61850订阅断线重连已失败多次不再重连. ied=" + ied.getName() + ", ip=" + ied.getIp() + ", port=" + ied.getPort();
log.warn(err);
if (realTimeDataService != null && ied != null) {
realTimeDataService.stopCollect(ied.getId());
}
if (webSocketServer != null) {
webSocketServer.sendMessage(err, null);
}
}
break;
} catch (Exception ignore) {
}
}
}
}
public static void main(String[] args) {
IecClient iecClient = new IecClient();

@ -8,6 +8,7 @@ import com.xydl.cac.exception.BusinessException;
import com.xydl.cac.model.StaticVariable;
import com.xydl.cac.repository.IcdFileRepository;
import com.xydl.cac.repository.IcdIedRepository;
import com.xydl.cac.socket.WebSocketServer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
@ -27,6 +28,8 @@ public class RealTimeDataService {
IcdFileRepository fileRepository;
@Resource
IcdIedRepository iedRepository;
@Resource
WebSocketServer webSocketServer;
public static boolean inDoing = false;
HashMap<Integer, IecClient> clientMap = new HashMap<>();
@ -62,6 +65,7 @@ public class RealTimeDataService {
iecClient.enableReporting();
iecClient.keep = true;
iecClient.realTimeDataService = this;
iecClient.webSocketServer = webSocketServer;
log.info("61850订阅成功, ied=" + ied.getName() + ", ip=" + ied.getIp() + ", port=" + ied.getPort());
ied.setStart(Constants.TRUE);
iedRepository.save(ied);

@ -112,7 +112,7 @@ public class RuleCheckTask {
}
log.warn("触发规则告警: " + str);
webSocketServer.sendMessage(str, warning.getId());
dingTalkPushUtil.pushText(str);
// dingTalkPushUtil.pushText(str);
}
}

Loading…
Cancel
Save