From 3ab0649752503532f1d61a82fb48c667a3378980 Mon Sep 17 00:00:00 2001 From: huangfeng Date: Mon, 6 Jan 2025 14:15:57 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E7=AB=AF=E7=9A=84=E6=8E=A7=E5=88=B6=E6=9C=8D=E5=8A=A1=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xydl/cac/iec104/Iec104ServerService.java | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/main/java/com/xydl/cac/iec104/Iec104ServerService.java diff --git a/src/main/java/com/xydl/cac/iec104/Iec104ServerService.java b/src/main/java/com/xydl/cac/iec104/Iec104ServerService.java new file mode 100644 index 0000000..bba2a14 --- /dev/null +++ b/src/main/java/com/xydl/cac/iec104/Iec104ServerService.java @@ -0,0 +1,52 @@ +package com.xydl.cac.iec104; + +import com.xydl.cac.exception.BusinessException; +import com.xydl.cac.model.StaticVariable; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; + +@Service +@Slf4j +public class Iec104ServerService { + + + @PostConstruct + private void init() { + try { +// this.startServer(2404); + } catch (Exception ignore) { + } + } + + public void startServer(int port) throws BusinessException { + try { + Iec104Server server = new Iec104Server(); + server.start(port); + StaticVariable.iec104Server = server; + } catch (Exception e) { + log.error("启动IEC104服务端异常.", e); + throw new BusinessException(e.getMessage()); + } + } + + public void stopServer() { + this.doStopServer(); + } + + private void doStopServer() { + if (StaticVariable.iec104Server != null) { + StaticVariable.iec104Server.stop(); + StaticVariable.iec104Server = null; + } + } + + @PreDestroy + private void stop() { + StaticVariable.shutdown = 1; + this.doStopServer(); + } + +}