perf: 启停增加锁定控制

dev
huangfeng 8 months ago
parent 5d7cbdbf28
commit 20888804da

@ -1,5 +1,6 @@
package com.xydl.cac.controller; package com.xydl.cac.controller;
import com.xydl.cac.exception.BusinessException;
import com.xydl.cac.iec.IecServerService; import com.xydl.cac.iec.IecServerService;
import com.xydl.cac.iec.RealTimeDataService; import com.xydl.cac.iec.RealTimeDataService;
import com.xydl.cac.model.Response; import com.xydl.cac.model.Response;
@ -30,16 +31,26 @@ public class IecServerController extends BasicController {
@PostMapping("start") @PostMapping("start")
@ApiOperation("启动IEC服务端") @ApiOperation("启动IEC服务端")
public Response<String> start(@Validated @NotNull(message = "fileId不能为空!") Integer fileId) throws Exception { public Response<String> start(@Validated @NotNull(message = "fileId不能为空!") Integer fileId) throws Exception {
if (RealTimeDataService.inDoing) {
throw new BusinessException("请稍后再操作");
}
RealTimeDataService.inDoing = true;
iecServerService.startServer(fileId); iecServerService.startServer(fileId);
realTimeDataService.start(); realTimeDataService.start();
RealTimeDataService.inDoing = false;
return Response.success("OK"); return Response.success("OK");
} }
@PostMapping("stop") @PostMapping("stop")
@ApiOperation("停止IEC服务端") @ApiOperation("停止IEC服务端")
public Response<String> stop() throws Exception { public Response<String> stop() throws Exception {
if (RealTimeDataService.inDoing) {
throw new BusinessException("请稍后再操作");
}
RealTimeDataService.inDoing = true;
realTimeDataService.stop(); realTimeDataService.stop();
iecServerService.stop(); iecServerService.stop();
RealTimeDataService.inDoing = false;
return Response.success("OK"); return Response.success("OK");
} }

@ -25,6 +25,7 @@ public class RealTimeDataService {
public static HashMap<String, String> dataMap = new HashMap<>(); public static HashMap<String, String> dataMap = new HashMap<>();
public static IecServer iecServer = null; public static IecServer iecServer = null;
public static boolean inDoing = false;
HashMap<String, IecClient> clientMap = new HashMap<>(); HashMap<String, IecClient> clientMap = new HashMap<>();
public void start() { public void start() {

Loading…
Cancel
Save