|
|
|
@ -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,33 +144,33 @@ public class IecClient implements ClientEventListener {
|
|
|
|
|
if (keep) {
|
|
|
|
|
this.disableReporting();
|
|
|
|
|
this.disconnect();
|
|
|
|
|
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 {
|
|
|
|
|
log.warn("61850订阅已断开, ied=" + ied.getName() + ", ip=" + ied.getIp() + ", port=" + ied.getPort());
|
|
|
|
|
while (retry > 0) {
|
|
|
|
|
retry--;
|
|
|
|
|
try {
|
|
|
|
|
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) {
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception ignore) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|