feat: 增加主动断线检测

dev
huangfeng 7 months ago
parent 15fc339dab
commit e7b4662fd6

@ -1,8 +1,8 @@
package com.xydl.cac.controller; package com.xydl.cac.controller;
import com.xydl.cac.iec.IecClient; import com.xydl.cac.iec.IecClient;
import com.xydl.cac.iec.RealTimeDataService;
import com.xydl.cac.model.Response; import com.xydl.cac.model.Response;
import com.xydl.cac.model.StaticVariable;
import com.xydl.cac.service.IcdFileConfigService; import com.xydl.cac.service.IcdFileConfigService;
import com.xydl.cac.socket.WebSocketServer; import com.xydl.cac.socket.WebSocketServer;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
@ -26,8 +26,6 @@ public class TestController extends BasicController {
IcdFileConfigService configService; IcdFileConfigService configService;
@Resource @Resource
WebSocketServer webSocketServer; WebSocketServer webSocketServer;
@Resource
RealTimeDataService realTimeDataService;
@GetMapping("compare61850") @GetMapping("compare61850")
@ApiOperation("比对61850的不同点") @ApiOperation("比对61850的不同点")
@ -45,6 +43,6 @@ public class TestController extends BasicController {
@GetMapping("realTimeMap") @GetMapping("realTimeMap")
@ApiOperation("实时订阅Map") @ApiOperation("实时订阅Map")
public Response<HashMap<Integer, IecClient>> realTimeMap() { 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"); StaticVariable.doneWarnMap.put(key, "1");
_webSocketServer.sendMessage(err, null); _webSocketServer.sendMessage(err, null);
} }
RealTimeDataService.onErrorCheck(ied.getId());
} finally { } finally {
iecClient.disconnect(); iecClient.disconnect();
} }
@ -180,7 +181,11 @@ public class IEDCollectService {
} catch (Exception ex) { } catch (Exception ex) {
String err = "61850采集文件异常, ied=" + ied.getName() + ", ip=" + ied.getIp() + ", path=" + config.getPath(); String err = "61850采集文件异常, ied=" + ied.getName() + ", ip=" + ied.getIp() + ", path=" + config.getPath();
log.error(err, ex); 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.io.InputStream;
import java.net.InetAddress; import java.net.InetAddress;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Date;
import java.util.List; import java.util.List;
@Slf4j @Slf4j
@ -29,6 +30,7 @@ public class IecClient implements ClientEventListener {
private RealTimeDataService realTimeDataService; private RealTimeDataService realTimeDataService;
private WebSocketServer webSocketServer; private WebSocketServer webSocketServer;
public int retry = 10; public int retry = 10;
public Date lastReportTime;
public IecClient() { public IecClient() {
} }
@ -84,6 +86,7 @@ public class IecClient implements ClientEventListener {
clientAssociation.setServerModel(serverModel); 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; retry = 10;
keep = true;
} }
public String getValue(String paramindex, String fc) throws Exception { 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()); log.info("61850订阅成功, ied=" + ied.getName() + ", ip=" + ied.getIp() + ", port=" + ied.getPort());
keep = true;
} }
public void disableReporting() { public void disableReporting() {
@ -132,6 +136,7 @@ public class IecClient implements ClientEventListener {
} else { } else {
log.info("61850停止订阅, ied=" + ied.getName() + ", ip=" + ied.getIp() + ", port=" + ied.getPort()); log.info("61850停止订阅, ied=" + ied.getName() + ", ip=" + ied.getIp() + ", port=" + ied.getPort());
} }
keep = false;
} }
public List<FileInformation> listFile(String path) throws Exception { public List<FileInformation> listFile(String path) throws Exception {
@ -150,6 +155,7 @@ public class IecClient implements ClientEventListener {
@Override @Override
public void newReport(Report report) { public void newReport(Report report) {
if (report != null) { if (report != null) {
lastReportTime = new Date();
RealTimeDataService.processReport(report); RealTimeDataService.processReport(report);
} }
} }
@ -157,6 +163,7 @@ public class IecClient implements ClientEventListener {
@Override @Override
public void associationClosed(IOException e) { public void associationClosed(IOException e) {
if (keep) { if (keep) {
keep = false;
this.disableReporting(); this.disableReporting();
this.disconnect(); this.disconnect();
while (retry > 0) { while (retry > 0) {

@ -29,7 +29,6 @@ public class RealTimeDataService {
WebSocketServer webSocketServer; WebSocketServer webSocketServer;
public static boolean inDoing = false; public static boolean inDoing = false;
public HashMap<Integer, IecClient> clientMap = new HashMap<>();
@PostConstruct @PostConstruct
private void init() { private void init() {
@ -60,10 +59,9 @@ public class RealTimeDataService {
IecClient iecClient = new IecClient(this, webSocketServer); IecClient iecClient = new IecClient(this, webSocketServer);
iecClient.connect(ied, icdFile.getXml()); iecClient.connect(ied, icdFile.getXml());
iecClient.enableReporting(); iecClient.enableReporting();
iecClient.keep = true;
ied.setStart(Constants.TRUE); ied.setStart(Constants.TRUE);
iedRepository.save(ied); iedRepository.save(ied);
clientMap.put(ied.getId(), iecClient); StaticVariable.realTimeClientMap.put(ied.getId(), iecClient);
} catch (Exception ex) { } catch (Exception ex) {
String err = "61850订阅异常, ied=" + ied.getName() + ", ip=" + ied.getIp() + ", port=" + ied.getPort(); String err = "61850订阅异常, ied=" + ied.getName() + ", ip=" + ied.getIp() + ", port=" + ied.getPort();
log.error(err, ex); 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) { private void onlyStop(Integer iedId) {
IecClient iecClient = clientMap.get(iedId); IecClient iecClient = StaticVariable.realTimeClientMap.get(iedId);
if (iecClient != null) { if (iecClient != null) {
iecClient.keep = false;
iecClient.disableReporting(); iecClient.disableReporting();
iecClient.disconnect(); iecClient.disconnect();
clientMap.remove(iedId); StaticVariable.realTimeClientMap.remove(iedId);
} }
} }
@ -98,7 +102,7 @@ public class RealTimeDataService {
private void stop() { private void stop() {
log.info("关闭61850订阅服务."); log.info("关闭61850订阅服务.");
List<Integer> idList = new ArrayList<>(); List<Integer> idList = new ArrayList<>();
Iterator<Integer> it = clientMap.keySet().iterator(); Iterator<Integer> it = StaticVariable.realTimeClientMap.keySet().iterator();
while (it.hasNext()) { while (it.hasNext()) {
idList.add(it.next()); 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.ModevType;
import com.xydl.cac.entity.WarnRule; import com.xydl.cac.entity.WarnRule;
import com.xydl.cac.entity.Zsb; import com.xydl.cac.entity.Zsb;
import com.xydl.cac.iec.IecClient;
import com.xydl.cac.iec.IecServer; import com.xydl.cac.iec.IecServer;
import java.util.HashMap; import java.util.HashMap;
@ -16,6 +17,7 @@ public class StaticVariable {
public static HashMap<Integer, HashMap<String, String>> sensorLastDataMap = new HashMap<>(); public static HashMap<Integer, HashMap<String, String>> sensorLastDataMap = new HashMap<>();
public static HashMap<String, String> paramRelationMap = new HashMap<>(); public static HashMap<String, String> paramRelationMap = new HashMap<>();
public static HashMap<String, String> doneWarnMap = 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 HashMap<String, String> unit_Cache = new HashMap<>();
public static List<ModevType> modevType_Cache = null; public static List<ModevType> modevType_Cache = null;

Loading…
Cancel
Save