From d20d38e22b06559d758c568769017e2acf632583 Mon Sep 17 00:00:00 2001
From: zuoxiao <470321431@qq.com>
Date: 星期三, 23 四月 2025 14:06:48 +0800
Subject: [PATCH] Merge branch 'master' of http://8.140.179.55:20000/r/pipIrr-SV
---
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