feat: 增加主动断线检测

dev
huangfeng 7 months ago
parent 15fc339dab
commit e7b4662fd6

@ -1,8 +1,8 @@
package com.xydl.cac.controller;
import com.xydl.cac.iec.IecClient;
import com.xydl.cac.iec.RealTimeDataService;
import com.xydl.cac.model.Response;
import com.xydl.cac.model.StaticVariable;
import com.xydl.cac.service.IcdFileConfigService;
import com.xydl.cac.socket.WebSocketServer;
import io.swagger.annotations.Api;
@ -26,8 +26,6 @@ public class TestController extends BasicController {
IcdFileConfigService configService;
@Resource
WebSocketServer webSocketServer;
@Resource
RealTimeDataService realTimeDataService;
@GetMapping("compare61850")
@ApiOperation("比对61850的不同点")
@ -45,6 +43,6 @@ public class TestController extends BasicController {
@GetMapping("realTimeMap")
@ApiOperation("实时订阅Map")
public Response<HashMap<Integer, IecClient>> realTimeMap() {
return Response.success(realTimeDataService.clientMap);
return Response.success(StaticVariable.realTimeClientMap);
}
}

@ -84,6 +84,7 @@ public class IEDCollectService {
StaticVariable.doneWarnMap.put(key, "1");
_webSocketServer.sendMessage(err, null);
}
RealTimeDataService.onErrorCheck(ied.getId());
} finally {
iecClient.disconnect();
}
@ -180,7 +181,11 @@ public class IEDCollectService {
} catch (Exception ex) {
String err = "61850采集文件异常, ied=" + ied.getName() + ", ip=" + ied.getIp() + ", path=" + config.getPath();
log.error(err, ex);
_webSocketServer.sendMessage(err, null);
String key = ied.getName() + ied.getIp() + ied.getPort() + config.getPath();
if (!StaticVariable.doneWarnMap.containsKey(key)) {
StaticVariable.doneWarnMap.put(key, "1");
_webSocketServer.sendMessage(err, null);
}
}
}

@ -14,6 +14,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.net.InetAddress;
import java.nio.charset.StandardCharsets;
import java.util.Date;
import java.util.List;
@Slf4j
@ -29,6 +30,7 @@ public class IecClient implements ClientEventListener {
private RealTimeDataService realTimeDataService;
private WebSocketServer webSocketServer;
public int retry = 10;
public Date lastReportTime;
public IecClient() {
}
@ -84,6 +86,7 @@ public class IecClient implements ClientEventListener {
clientAssociation.setServerModel(serverModel);
log.info("61850订阅断线重连成功, ied=" + ied.getName() + ", ip=" + ied.getIp() + ", port=" + ied.getPort());
retry = 10;
keep = true;
}
public String getValue(String paramindex, String fc) throws Exception {
@ -108,6 +111,7 @@ public class IecClient implements ClientEventListener {
}
}
log.info("61850订阅成功, ied=" + ied.getName() + ", ip=" + ied.getIp() + ", port=" + ied.getPort());
keep = true;
}
public void disableReporting() {
@ -132,6 +136,7 @@ public class IecClient implements ClientEventListener {
} else {
log.info("61850停止订阅, ied=" + ied.getName() + ", ip=" + ied.getIp() + ", port=" + ied.getPort());
}
keep = false;
}
public List<FileInformation> listFile(String path) throws Exception {
@ -150,6 +155,7 @@ public class IecClient implements ClientEventListener {
@Override
public void newReport(Report report) {
if (report != null) {
lastReportTime = new Date();
RealTimeDataService.processReport(report);
}
}
@ -157,6 +163,7 @@ public class IecClient implements ClientEventListener {
@Override
public void associationClosed(IOException e) {
if (keep) {
keep = false;
this.disableReporting();
this.disconnect();
while (retry > 0) {

@ -29,7 +29,6 @@ public class RealTimeDataService {
WebSocketServer webSocketServer;
public static boolean inDoing = false;
public HashMap<Integer, IecClient> clientMap = new HashMap<>();
@PostConstruct
private void init() {
@ -60,10 +59,9 @@ public class RealTimeDataService {
IecClient iecClient = new IecClient(this, webSocketServer);
iecClient.connect(ied, icdFile.getXml());
iecClient.enableReporting();
iecClient.keep = true;
ied.setStart(Constants.TRUE);
iedRepository.save(ied);
clientMap.put(ied.getId(), iecClient);
StaticVariable.realTimeClientMap.put(ied.getId(), iecClient);
} catch (Exception ex) {
String err = "61850订阅异常, ied=" + ied.getName() + ", ip=" + ied.getIp() + ", port=" + ied.getPort();
log.error(err, ex);
@ -84,13 +82,19 @@ public class RealTimeDataService {
}
}
public static void onErrorCheck(Integer iedId) {
IecClient iecClient = StaticVariable.realTimeClientMap.get(iedId);
if (iecClient != null) {
iecClient.associationClosed(null);
}
}
private void onlyStop(Integer iedId) {
IecClient iecClient = clientMap.get(iedId);
IecClient iecClient = StaticVariable.realTimeClientMap.get(iedId);
if (iecClient != null) {
iecClient.keep = false;
iecClient.disableReporting();
iecClient.disconnect();
clientMap.remove(iedId);
StaticVariable.realTimeClientMap.remove(iedId);
}
}
@ -98,7 +102,7 @@ public class RealTimeDataService {
private void stop() {
log.info("关闭61850订阅服务.");
List<Integer> idList = new ArrayList<>();
Iterator<Integer> it = clientMap.keySet().iterator();
Iterator<Integer> it = StaticVariable.realTimeClientMap.keySet().iterator();
while (it.hasNext()) {
idList.add(it.next());
}

@ -4,6 +4,7 @@ import com.xydl.cac.entity.Jg;
import com.xydl.cac.entity.ModevType;
import com.xydl.cac.entity.WarnRule;
import com.xydl.cac.entity.Zsb;
import com.xydl.cac.iec.IecClient;
import com.xydl.cac.iec.IecServer;
import java.util.HashMap;
@ -16,6 +17,7 @@ public class StaticVariable {
public static HashMap<Integer, HashMap<String, String>> sensorLastDataMap = new HashMap<>();
public static HashMap<String, String> paramRelationMap = new HashMap<>();
public static HashMap<String, String> doneWarnMap = new HashMap<>();
public static HashMap<Integer, IecClient> realTimeClientMap = new HashMap<>();
public static HashMap<String, String> unit_Cache = new HashMap<>();
public static List<ModevType> modevType_Cache = null;

Loading…
Cancel
Save