From d8eb22351c6d0bfe0c9f233edfd593538e6838c9 Mon Sep 17 00:00:00 2001 From: liurunyu <lry9898@163.com> Date: 星期四, 24 四月 2025 13:58:49 +0800 Subject: [PATCH] 1、表阀一体机协议开阀类型变化; 2、表阀一体机协议开关阀报中增加水价数据; --- pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/channel/rmi/RmiUnit.java | 101 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 101 insertions(+), 0 deletions(-) diff --git a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/channel/rmi/RmiUnit.java b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/channel/rmi/RmiUnit.java new file mode 100644 index 0000000..8117f66 --- /dev/null +++ b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/channel/rmi/RmiUnit.java @@ -0,0 +1,101 @@ +package com.dy.common.mw.channel.rmi; + +import java.io.IOException; +import java.rmi.registry.LocateRegistry; +import java.rmi.registry.Registry; +import java.rmi.server.UnicastRemoteObject; + +import com.dy.common.mw.UnitAdapterInterface; +import com.dy.common.mw.UnitInterface; +import com.dy.common.mw.UnitCallbackInterface; + +public class RmiUnit implements UnitInterface { + + private static RmiUnit instance = new RmiUnit() ; + private static boolean started = false ; + + private static RmiUnitAdapter adapter ; + + private static RmiFrameWork rmiFrm = null ; + + + private RmiUnit(){} + + public static RmiUnit getInstance(){ + return instance ; + } + + + @Override + public void setAdapter(UnitAdapterInterface adapter) throws Exception { + if(adapter == null){ + throw new Exception("Rmi妯″潡閫傞厤鍣ㄥ璞′笉鑳戒负绌猴紒") ; + } + RmiUnit.adapter = (RmiUnitAdapter)adapter ; + RmiConfigVo vo = RmiUnit.adapter.getConfig() ; + if(vo == null){ + throw new Exception("Rmi妯″潡灞炴�ч厤缃璞′笉鑳戒负绌猴紒") ; + } + if(vo.port == null){ + throw new Exception("Rmi妯″潡port灞炴�у�间笉鑳戒负绌猴紒") ; + } + if(vo.context == null || vo.context.trim().equals("")){ + throw new Exception("Rmi妯″潡context灞炴�у�间笉鑳戒负绌猴紒") ; + } + } + /** + * 鍚姩妯″潡 + */ + public void start(UnitCallbackInterface callback) throws Exception { + if(!started){ + started = true ; + + RmiConfigVo vo = RmiUnit.adapter.getConfig() ; + + boolean isException = false ; + try { + + //鏀瑰眬鍩熷彉閲忎负闈欐�佸叏灞�鍙橀噺锛岄槻姝㈠眬鍩熷彉閲忓湪鏃犲紩鐢ㄦ椂琚瀮鍦惧洖鏀讹紝浠庤�屽鎴风寰椾笉鍒癛MI鏈嶅姟绔� + if(rmiFrm == null){ + rmiFrm = new RmiFrameWorkImpl(RmiUnit.adapter); + } + + //杩炴帴鍒版湰鍦癑NDI + Registry registry = LocateRegistry.createRegistry(vo.port); + + //瑙i櫎娉ㄥ唽 + UnicastRemoteObject.unexportObject(rmiFrm, true); + + //娉ㄥ唽 + registry.bind(vo.context, UnicastRemoteObject.exportObject(rmiFrm, 0)); + + } catch (IOException e) { + e.printStackTrace(); + System.out.println("Rmi閫氫俊妯″潡鍚姩澶辫触锛�"); + isException = true ; + } + + if(!isException){ + if(vo.showStartInfo != null && vo.showStartInfo){ + System.out.println("Rmi妯″潡鎴愬姛鍚姩锛岀鍙o細" + vo.port + "锛屼笂涓嬫枃涓猴細" + vo.context ); + } + } + callback.call(null); + } + } + + @Override + public void stop(UnitCallbackInterface callback) { + } + + + public static boolean isStarted() { + return started; + } + + public RmiUnitAdapter getAdapter() { + return adapter; + } + + +} \ No newline at end of file -- Gitblit v1.8.0