From 1a2b07f01ba4616fd9e894dddf474b56d020158c Mon Sep 17 00:00:00 2001 From: zhubaomin <zhubaomin> Date: 星期一, 07 四月 2025 15:18:51 +0800 Subject: [PATCH] 整理版本 --- pipIrr-platform/pipIrr-mw/pipIrr-mwTest-server/src/main/java/com/dy/testServer/Server.java | 170 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 170 insertions(+), 0 deletions(-) diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-server/src/main/java/com/dy/testServer/Server.java b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-server/src/main/java/com/dy/testServer/Server.java new file mode 100644 index 0000000..2349a1a --- /dev/null +++ b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-server/src/main/java/com/dy/testServer/Server.java @@ -0,0 +1,170 @@ +package com.dy.testServer; + +import java.io.Console; +import java.util.ArrayList; +import java.util.List; + +import com.dy.testServer.console.CommandConsole; +import com.dy.testServer.forRmi.Manager; +import org.jdom2.Document; + +import com.dy.common.mw.UnitInterface; +import com.dy.common.mw.UnitCallbackInterface; +import com.dy.common.mw.channel.rmi.RmiConfigVo; +import com.dy.common.mw.channel.rmi.RmiUnit; +import com.dy.common.util.NumUtil; +import com.dy.common.util.ConfigXmlNoSpringboot; + +public class Server{ + + private ConfigXmlNoSpringboot conf = null ; + private Document doc = null ; + private boolean showStartInfo = false ; + + private String RmiSvUrl ; + + private final List<UnitInterface> units = new ArrayList<>() ; + + /** + * @param args 鍙傛暟 + */ + public static void main(String[] args) { + new Server().startServer(args); + } + + /** + * 鍚姩鏈嶅姟 + */ + public void startServer(String[] args){ + Server sv = new Server(); + long start = System.currentTimeMillis() ; + try { + sv.conf = new ConfigXmlNoSpringboot() ; + sv.doc = sv.conf.createDom(sv.getClass(), "config.xml") ; + //////////////// + //鏈嶅姟 閰嶇疆 + sv.showStartInfo = sv.conf.getSetAttrBoolean(sv.doc, "config.server", "showStartInfo", null, null) ; + + sv.startUnits() ; + + String svName ; + try{ + svName = sv.conf.getSetAttrTxt(sv.doc, "config.server", "name", null, false, null) ; + }catch(Exception e){ + svName = "" ; + } + + System.out.println("OOOOOOOOOO OOOOOOOO OOOOOOOO") ; + System.out.println("@@@@@@@@@@@@@@@@#O $@@@@@@@@& @@@@@@@@#") ; + System.out.println("@@@@@@@@@@@@@@@@@@@# @@@@@@@@# $@@@@@@@@&") ; + System.out.println("@@@@@@@@@@@@@@@@@@@@@# #@@@@@@@@@@@@@@@@O") ; + System.out.println("@@@@@@@@@@@@@@@@@@@@@@@ &@@@@@@@@@@@@@@") ; + System.out.println("@@@@@@$ $@@@@@@@@@& O@@@@@@@@@@@#") ; + System.out.println("@@@@@@$ @@@@@@@@@ @@@@@@@@@& " + svName + "mwTestSv " ) ; + System.out.println("@@@@@@$ @@@@@@@@@ &@@@@@@@@") ; + System.out.println("@@@@@@$ O@@@@@@@@@ &@@@@@@@@") ; + if(sv.RmiSvUrl != null){ + System.out.println("@@@@@@$ #@@@@@@@@@$ &@@@@@@@@ RmiSv " + sv.RmiSvUrl ) ; + }else{ + System.out.println("@@@@@@$ #@@@@@@@@@$ &@@@@@@@@" ) ; + } + System.out.println("@@@@@@@@@@@@@@@@@@@@@@# &@@@@@@@@ Runing in standalone mode" ) ; + System.out.println("@@@@@@@@@@@@@@@@@@@@@& &@@@@@@@@ Startup in " + (System.currentTimeMillis() - start) + " MS" ) ; + System.out.println("@@@@@@@@@@@@@@@@@@@# &@@@@@@@@") ; + System.out.println("@@@@@@@@@@@@@@@@#O &@@@@@@@@") ; + + + + Console console = System.console(); + if (console == null) { + throw new IllegalStateException("涓ラ噸閿欒锛屾湭鑳藉緱鍒版帶鍒跺彴瀵硅薄!"); + } + CommandConsole mwConsole = new CommandConsole(console) ; + mwConsole.init(args); + boolean exit = mwConsole.clientConsole() ; + if(exit){ + System.exit(-1); + } + }catch(Exception e){ + e.printStackTrace(); + } + } + + private void startUnits(){ + try { + /////////////// + //鍩烘湰閰嶇疆 + String txt = conf.getSetAttrTxt(doc, "config.base", "rtuAddrStart", null, false, null) ; + if(txt == null || txt.trim().equals("")){ + throw new Exception("鍏冪礌config.base鐨勫睘鎬tuAddrStart鐨勫�间负绌哄瓧绗︿覆!"); + } + txt = txt.trim() ; + if(!NumUtil.isPlusIntNumber(txt)){ + throw new Exception("鍏冪礌config.base鐨勫睘鎬tuAddrStart鐨勫�煎繀椤讳负鏁板��!"); + } + if(txt.startsWith("0")){ + throw new Exception("鍏冪礌config.base鐨勫睘鎬tuAddrStart鐨勬暟鍊间笉鑳戒互0寮�澶�!"); + } + if(!(txt.length() == 10 || txt.length() == 12)){ + throw new Exception("鍏冪礌config.base鐨勫睘鎬tuAddrStart鐨勬暟鍊奸暱搴﹀繀椤讳负10浣嶆垨12浣�!"); + } + ServerProperties.rtuAddrStart = Long.valueOf(txt) ; + + txt = conf.getSetAttrTxt(doc, "config.base", "rtuAddrEnd", null, false, null) ; + if(txt == null || txt.trim().equals("")){ + throw new Exception("鍏冪礌config.base鐨勫睘鎬tuAddrEnd鐨勫�间负绌哄瓧绗︿覆!"); + } + txt = txt.trim() ; + if(!NumUtil.isPlusIntNumber(txt)){ + throw new Exception("鍏冪礌config.base鐨勫睘鎬tuAddrEnd鐨勫�煎繀椤讳负鏁板��!"); + } + if(txt.startsWith("0")){ + throw new Exception("鍏冪礌config.base鐨勫睘鎬tuAddrEnd鐨勬暟鍊间笉鑳戒互0寮�澶�!"); + } + if(!(txt.length() == 10 || txt.length() == 12)){ + throw new Exception("鍏冪礌config.base鐨勫睘鎬tuAddrEnd鐨勬暟鍊奸暱搴﹀繀椤讳负10浣嶆垨12浣�!"); + } + ServerProperties.rtuAddrEnd = Long.valueOf(txt) ; + if(ServerProperties.rtuAddrEnd <= ServerProperties.rtuAddrStart){ + throw new Exception("鍏冪礌config.base鐨勫睘鎬tuAddrEnd鐨勬暟鍊煎繀椤诲ぇ浜巖tuAddrStart!"); + } + + ServerProperties.rtuAddrPerMwTest = conf.getSetAttrPlusInt(doc, "config.base", "rtuAddrPerMwTest", null, 1, null, null) ; + if(ServerProperties.rtuAddrPerMwTest > ServerProperties.rtuAddrEnd - ServerProperties.rtuAddrStart){ + throw new Exception("鍏冪礌config.base鐨勫睘鎬tuAddrPerMwTest鐨勬暟鍊奸厤缃笉姝g‘!"); + } + ServerProperties.tcpServerIp = conf.getSetAttrTxt(doc, "config.base", "tcpServerIp", null, false, null) ; + ServerProperties.tcpServerPort = conf.getSetAttrPlusInt(doc, "config.base", "tcpServerPort", null, 1, 65535, null) ; + ServerProperties.sendInterval = conf.getSetAttrPlusInt(doc, "config.base", "sendInterval", null, 1, null, null) ; + ServerProperties.heartbeatTimes = conf.getSetAttrPlusInt(doc, "config.base", "heartbeatTimes", null, 1, null, null) ; + ServerProperties.sendTimes = conf.getSetAttrPlusInt(doc, "config.base", "sendTimes", null, 1, null, null) ; + ServerProperties.sendOverThenCloseConnect = conf.getSetAttrPlusInt(doc, "config.base", "sendOverThenCloseConnect", null, 0, 1, null) ; + + + ///////////////// + //RMI妯″潡 + Manager.init(); + RmiConfigVo rmiVo = new RmiConfigVo(); + rmiVo.enable = conf.getSetAttrBoolean(doc, "config.rmi", "enable", null, null) ; + if(rmiVo.enable){ + rmiVo.port = conf.getSetAttrPlusInt(doc, "config.rmi", "port", null, 100, 65535, null); + rmiVo.context = conf.getSetAttrTxt(doc, "config.rmi", "context", null, false, null); + rmiVo.showStartInfo = showStartInfo ; + AdapterImp_RmiUnit rmiAdap = new AdapterImp_RmiUnit(); + rmiAdap.setConfig(rmiVo); + RmiUnit rmiUnit = RmiUnit.getInstance(); + rmiUnit.setAdapter(rmiAdap); + rmiUnit.start(new UnitCallbackInterface(){ + @Override + public void call(Object obj) { + } + }); + RmiSvUrl = "[ip]:" + rmiVo.port + "/" + rmiVo.context ; + units.add(rmiUnit) ; + } + } catch (Exception e) { + e.printStackTrace(); + } + } + +} -- Gitblit v1.8.0