From 72d6f51598277ad462f592b230d602f2ff5a060e Mon Sep 17 00:00:00 2001 From: ludj Date: Sat, 4 Feb 2023 10:50:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nl/acs/opc/DeviceOpcProtocolRunable.java | 24 +++++-------------- .../org/nl/acs/opc/OpcServerServiceImpl.java | 5 +++- .../src/main/java/org/nl/acs/opc/OpcUtl.java | 12 ++++++++-- 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/opc/DeviceOpcProtocolRunable.java b/acs/nladmin-system/src/main/java/org/nl/acs/opc/DeviceOpcProtocolRunable.java index 49269e427..8f6c42fa0 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/opc/DeviceOpcProtocolRunable.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/opc/DeviceOpcProtocolRunable.java @@ -6,6 +6,7 @@ import cn.hutool.core.util.StrUtil; import lombok.extern.slf4j.Slf4j; import org.nl.acs.udw.UnifiedDataAccessor; import org.nl.acs.udw.UnifiedDataAccessorFactory; +import org.nl.modules.wql.util.SpringContextHolder; import org.openscada.opc.lib.da.Group; import org.openscada.opc.lib.da.Item; import org.openscada.opc.lib.da.ItemState; @@ -15,18 +16,19 @@ import java.util.*; @Slf4j public class DeviceOpcProtocolRunable implements Runnable { + OpcServerService opcServerService = SpringContextHolder.getBean(OpcServerServiceImpl.class); + + List protocols; OpcServerManageDto OpcServer; int error_num; String message; - private Server server; Group group; public DeviceOpcProtocolRunable() { this.error_num = 0; this.message = null; - this.server = null; } public List getProtocols() { @@ -64,14 +66,7 @@ public class DeviceOpcProtocolRunable implements Runnable { public void run() { while (true) { try { - server = - OpcServerUtl.getServerWithOutException( - this.OpcServer.getOpc_host(), - this.OpcServer.getCls_id(), - this.OpcServer.getUser(), - this.OpcServer.getPassword(), - this.OpcServer.getDomain()); - group = server.addGroup(); + group= opcServerService.getServer(this.OpcServer.getOpc_code()); List itemsString = new ArrayList(); Iterator it = this.protocols.iterator(); @@ -196,14 +191,6 @@ public class DeviceOpcProtocolRunable implements Runnable { } } } catch (Exception var30) { - if (this.server != null) { - try { - this.server.disconnect(); - } catch (Exception var6) { - } - this.server = null; - } - if (group != null) { try { group.clear(); @@ -213,6 +200,7 @@ public class DeviceOpcProtocolRunable implements Runnable { this.group = null; } + String error_message = "设备信息同步异常"; if (!StrUtil.equals(this.message, error_message)) { log.warn("", var30); diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/opc/OpcServerServiceImpl.java b/acs/nladmin-system/src/main/java/org/nl/acs/opc/OpcServerServiceImpl.java index 416c55f02..92a265428 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/opc/OpcServerServiceImpl.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/opc/OpcServerServiceImpl.java @@ -127,7 +127,10 @@ public class OpcServerServiceImpl implements OpcServerService, ApplicationAutoIn public synchronized void clearServer(String code) { try { Server server = (Server) this.servers.get(code); - server.disconnect(); + if (server!=null){ + server.disconnect(); + } + } catch (Exception e) { e.printStackTrace(); log.error("清理server异常,",e.getMessage()); diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/opc/OpcUtl.java b/acs/nladmin-system/src/main/java/org/nl/acs/opc/OpcUtl.java index 3ed420b6d..154e5972a 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/opc/OpcUtl.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/opc/OpcUtl.java @@ -18,8 +18,10 @@ import java.util.concurrent.Executors; @Slf4j public class OpcUtl { - private static int timeout = 180000; + private static int timeout = 300000; private static String key = "rpc.socketTimeout"; + private static int successNum=0; + private static int errNum=0; public static void checkTimeout() { if (Integer.getInteger(key, 0).intValue() != timeout) { @@ -204,9 +206,15 @@ public class OpcUtl { server = new Server(getConnection(host, clsid, user, password, domain), Executors.newSingleThreadScheduledExecutor()); server.connect(); + successNum++; return server; } catch (Exception e) { - throw new WDKException(e); + errNum++; + throw new WDKException(e.getMessage()); + }finally{ + System.out.println("successNum:"+successNum); + System.out.println("errNum:"+errNum); + System.out.println(11); } }