perf: 重整订阅实时数据结构

dev
huangfeng 8 months ago
parent 3aeef8dbac
commit 96ef3aa860

@ -1,8 +1,8 @@
package com.xydl.cac.controller; package com.xydl.cac.controller;
import com.xydl.cac.iec.IecServerService; import com.xydl.cac.iec.IecServerService;
import com.xydl.cac.iec.RealTimeDataService;
import com.xydl.cac.model.Response; import com.xydl.cac.model.Response;
import com.xydl.cac.service.RealTimeService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -22,20 +22,20 @@ public class IecServerController extends BasicController {
@Resource @Resource
IecServerService iecServerService; IecServerService iecServerService;
@Resource @Resource
RealTimeService realTimeService; RealTimeDataService realTimeDataService;
@GetMapping("start") @GetMapping("start")
@ApiOperation("启动IEC服务端") @ApiOperation("启动IEC服务端")
public Response<String> start() throws Exception { public Response<String> start() throws Exception {
iecServerService.startServer(); iecServerService.startServer();
realTimeService.start(); realTimeDataService.start();
return Response.success("OK"); return Response.success("OK");
} }
@GetMapping("stop") @GetMapping("stop")
@ApiOperation("停止IEC服务端") @ApiOperation("停止IEC服务端")
public Response<String> stop() throws Exception { public Response<String> stop() throws Exception {
realTimeService.stop(); realTimeDataService.stop();
iecServerService.stop(); iecServerService.stop();
return Response.success("OK"); return Response.success("OK");
} }

@ -1,7 +1,6 @@
package com.xydl.cac.iec; package com.xydl.cac.iec;
import com.beanit.iec61850bean.*; import com.beanit.iec61850bean.*;
import com.xydl.cac.service.impl.RealTimeServiceImpl;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@ -84,7 +83,7 @@ public class IecClient implements ClientEventListener {
@Override @Override
public void newReport(Report report) { public void newReport(Report report) {
if (report != null) { if (report != null) {
RealTimeServiceImpl.processReport(report); RealTimeDataService.processReport(report);
} }
} }

@ -2,7 +2,6 @@ package com.xydl.cac.iec;
import com.xydl.cac.entity.IcdFile; import com.xydl.cac.entity.IcdFile;
import com.xydl.cac.repository.IcdFileRepository; import com.xydl.cac.repository.IcdFileRepository;
import com.xydl.cac.service.impl.RealTimeServiceImpl;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
@ -27,7 +26,7 @@ public class IecServerService {
IcdFile icdFile = icdFileList.get(0); IcdFile icdFile = icdFileList.get(0);
try { try {
iecServer.start(icdFile.getXml(), 102); iecServer.start(icdFile.getXml(), 102);
RealTimeServiceImpl.iecServer = iecServer; RealTimeDataService.iecServer = iecServer;
} catch (Exception e) { } catch (Exception e) {
log.error("启动IEC61850服务端异常.", e); log.error("启动IEC61850服务端异常.", e);
} }
@ -36,7 +35,7 @@ public class IecServerService {
@PreDestroy @PreDestroy
public void stop() { public void stop() {
RealTimeServiceImpl.iecServer = null; RealTimeDataService.iecServer = null;
if (iecServer != null) { if (iecServer != null) {
iecServer.close(); iecServer.close();
} }

@ -1,12 +1,10 @@
package com.xydl.cac.service.impl; package com.xydl.cac.iec;
import com.beanit.iec61850bean.*; import com.beanit.iec61850bean.*;
import com.xydl.cac.entity.IcdFile; import com.xydl.cac.entity.IcdFile;
import com.xydl.cac.entity.IcdIed; import com.xydl.cac.entity.IcdIed;
import com.xydl.cac.iec.IecClient; import com.xydl.cac.repository.IcdFileRepository;
import com.xydl.cac.iec.IecServer; import com.xydl.cac.repository.IcdIedRepository;
import com.xydl.cac.repository.*;
import com.xydl.cac.service.RealTimeService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
@ -17,11 +15,9 @@ import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
@Service @Service
@Slf4j @Slf4j
public class RealTimeServiceImpl implements RealTimeService { public class RealTimeDataService {
@Resource @Resource
IcdFileRepository fileRepository; IcdFileRepository fileRepository;
@Resource @Resource
@ -31,7 +27,6 @@ public class RealTimeServiceImpl implements RealTimeService {
public static IecServer iecServer = null; public static IecServer iecServer = null;
HashMap<String, IecClient> clientMap = new HashMap<>(); HashMap<String, IecClient> clientMap = new HashMap<>();
@Override
public void start() { public void start() {
List<IcdFile> icdFileList = fileRepository.findAll(); List<IcdFile> icdFileList = fileRepository.findAll();
if (CollectionUtils.isEmpty(icdFileList)) { if (CollectionUtils.isEmpty(icdFileList)) {
@ -56,7 +51,6 @@ public class RealTimeServiceImpl implements RealTimeService {
} }
@PreDestroy @PreDestroy
@Override
public void stop() { public void stop() {
Iterator<String> it = clientMap.keySet().iterator(); Iterator<String> it = clientMap.keySet().iterator();
while (it.hasNext()) { while (it.hasNext()) {

@ -1,8 +0,0 @@
package com.xydl.cac.service;
public interface RealTimeService {
void start();
void stop();
}
Loading…
Cancel
Save