From c475f9ad3290c2593897736144758b54e2b2f407 Mon Sep 17 00:00:00 2001 From: liurunyu <lry9898@163.com> Date: 星期一, 27 十一月 2023 19:30:13 +0800 Subject: [PATCH] mwTest-client初步实现 --- pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/rmiClient/Code.java | 15 pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpConnect/LocalDecoder.java | 91 ++ pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/rmiClient/ResRegisterVo.java | 45 + pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/UpDataVo.java | 174 ++++ pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/rmiClient/RmiRequestVo.java | 96 ++ pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/.gitignore | 34 pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/resources/application.yml | 1 pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/rmiClient/RmiClUnit.java | 268 ++++++ pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/rmiClient/RmiClUnitConfigVo.java | 29 pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/rmiClient/RmiClient.java | 40 pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/HttpClUnit.java | 112 ++ pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/resources/log4j2.yml | 64 + pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/rmiClient/ResStartVo.java | 47 + pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpClient/MyThreadJob.java | 55 + pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpConnect/MinaConnect.java | 55 + pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/RtuData4HAC_NBhV2_5.java | 46 + pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/pom.xml | 121 ++ pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpConnect/LocalEncoder.java | 51 + pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpConnect/MinaConnectPool.java | 107 ++ pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/AdapterImp_SupportUnit.java | 20 pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/ServerProperties.java | 18 pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/TestBase64.java | 23 pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpClient/TcpClUnitConfigVo.java | 7 pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/HttpClUnitConfigVo.java | 5 pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/HttpPost.java | 11 pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpConnect/LocalCodecFactory.java | 35 pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/HttpClUnitAdapter.java | 9 pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpConnect/MinaHandler.java | 94 ++ pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/resources/Config.xml | 48 + pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/Server.java | 134 +++ pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/rmiClient/ResConfigVo.java | 84 ++ pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/RtuData4MeterV1_0.java | 165 ++++ pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpClient/TcpClUnitAdapter.java | 7 pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/AdapterImp_RmiClUnit.java | 19 pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/rmiClient/RmiClUnitAdapter.java | 10 pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/UpDataPayloadVo.java | 16 pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/MyThreadJob.java | 76 + pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/rmiClient/RmiResponseVo.java | 77 + pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/AdapterImp_HttpClUnit.java | 19 pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpClient/TcpClUnit.java | 110 ++ 40 files changed, 2,438 insertions(+), 0 deletions(-) diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/.gitignore b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/.gitignore new file mode 100644 index 0000000..99e214e --- /dev/null +++ b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/.gitignore @@ -0,0 +1,34 @@ +HELP.md +target/ +/pipIrr-mwTest-client.iml +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/pom.xml b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/pom.xml new file mode 100644 index 0000000..6e14d6b --- /dev/null +++ b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/pom.xml @@ -0,0 +1,121 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <artifactId>pipIrr-mw</artifactId> + <groupId>com.dy</groupId> + <version>1.0.0</version> + </parent> + + <packaging>jar</packaging> + <artifactId>pipIrr-mwTest-client</artifactId> + <version>1.0.0</version> + <name>pipIrr-mwTest-client</name> + <description>妯℃嫙RTU娴嬭瘯绔�</description> + + <dependencies> + <!-- apache mina --> + <dependency> + <groupId>org.apache.mina</groupId> + <artifactId>mina-core</artifactId> + <version>2.2.2</version> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + <version>2.0.7</version> + </dependency> + + <!-- 娴嬭瘯 --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <!-- 璇ユ彃浠朵笉浼氬皢椤圭洰涓紩鍏ョ殑渚濊禆鎵撹繘鏈�缁堢殑 Jar 鏂囦欢 --> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-jar-plugin</artifactId> + <configuration> + <archive> + <!-- 鐢熸垚鐨刯ar涓紝涓嶈鍖呭惈pom.xml鍜宲om.properties杩欎袱涓枃浠� --> + <addMavenDescriptor>false</addMavenDescriptor> + <!-- 杩欓儴鍒嗗彲鏈夊彲鏃�,鍔犱笂鐨勮瘽鍒欑洿鎺ョ敓鎴愬彲杩愯jar鍖� --> + <manifest> + <mainClass>com.dy.testClient.Server</mainClass> + <useUniqueVersions>false</useUniqueVersions> + <addClasspath>true</addClasspath> + <classpathPrefix>lib/</classpathPrefix> + </manifest> + <!-- manifestEntries鐨勪綔鐢ㄦ槸鎸囧畾鏈湴锛堣嚜宸变笅杞界殑lib涓嬬殑锛塲ar鍖呮坊鍔犲埌MANIFEST.MF鏂囦欢涓幓 + <manifestEntries> + <Class-Path>.lib/alipay-sdk.java.jar</Class-Path> + </manifestEntries> + --> + </archive> + <!-- 鎺掗櫎鏌愪釜鏂囦欢 + <excludes> + <exclude>com/dy/App.class</exclude> + </excludes> + --> + <!-- 鍙墽琛宩ar杩涜鍛藉悕銆傝繖鏍蜂細鎵撳寘鎴愪袱涓猨ar鍖咃紝涓嶄細瀵规櫘閫歫ar閲嶆柊鍛藉悕銆� + <classifier>exec</classifier> + --> + </configuration> + </plugin> + <plugin> + <!-- 褰撻」鐩腑渚濊禆姣旇緝澶氭椂锛屾垜浠彲浠ュ�熷姪 maven-dependency-plugin 鎻掍欢鑷姩甯垜浠笅杞戒緷璧栫殑 Jar 鏂囦欢锛屾帹鑽愬皢璇ユ彃浠剁粦瀹氬埌package鐢熷懡鍛ㄦ湡涓� --> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-dependency-plugin</artifactId> + <executions> + <execution> + <!-- 缁戝畾鐢熷懡鍛ㄦ湡 --> + <phase>package</phase> + <goals> + <goal>copy-dependencies</goal> + </goals> + <!-- 璁剧疆渚濊禆鐨勫瓨鏀捐矾寰� --> + <configuration> + <outputDirectory>${project.build.directory}/lib</outputDirectory> + </configuration> + </execution> + </executions> + </plugin> + <plugin> + <!-- 璁剧疆java缂栬瘧鐗堟湰锛岃繍琛岀幆澧冪増鏈� --> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <!-- source锛� 婧愪唬鐮佺紪璇戠増鏈紱target锛� 鐩爣骞冲彴缂栬瘧鐗堟湰锛沞ncoding锛� 瀛楃闆嗙紪鐮併�� --> + <configuration> + <source>${java.version}</source> + <target>${java.version}</target> + <encoding>${encoding}</encoding> + </configuration> + </plugin> + <plugin> + <!-- 瑙e喅璧勬簮鏂囦欢鐨勭紪鐮侀棶棰� --> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-resources-plugin</artifactId> + <configuration> + <encoding>${encoding}</encoding> + </configuration> + </plugin> + + <plugin> + <!-- maven閲屾墽琛屾祴璇曠敤渚嬬殑鎻掍欢 --> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <skipTests>true</skipTests> + </configuration> + </plugin> + + </plugins> + </build> +</project> diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/AdapterImp_HttpClUnit.java b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/AdapterImp_HttpClUnit.java new file mode 100644 index 0000000..2796884 --- /dev/null +++ b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/AdapterImp_HttpClUnit.java @@ -0,0 +1,19 @@ +package com.dy.testClient; + +import com.dy.testClient.tcpClient.TcpClUnitAdapter; +import com.dy.testClient.tcpClient.TcpClUnitConfigVo; + + +public class AdapterImp_TcpClUnit implements TcpClUnitAdapter { + + private TcpClUnitConfigVo configVo ; + + public TcpClUnitConfigVo getConfig() { + return configVo; + } + + public void setConfig(TcpClUnitConfigVo configVo){ + this.configVo = configVo ; + } + +} diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/AdapterImp_RmiClUnit.java b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/AdapterImp_RmiClUnit.java new file mode 100644 index 0000000..2ca9436 --- /dev/null +++ b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/AdapterImp_RmiClUnit.java @@ -0,0 +1,19 @@ +package com.dy.testClient; + + +import com.dy.testClient.rmiClient.RmiClUnitAdapter; +import com.dy.testClient.rmiClient.RmiClUnitConfigVo; + +public class AdapterImp_RmiClUnit implements RmiClUnitAdapter { + + private RmiClUnitConfigVo configVo ; + + public RmiClUnitConfigVo getConfig() { + return configVo; + } + + public void setConfig(RmiClUnitConfigVo configVo){ + this.configVo = configVo ; + } + +} diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/AdapterImp_SupportUnit.java b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/AdapterImp_SupportUnit.java new file mode 100644 index 0000000..93d2c61 --- /dev/null +++ b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/AdapterImp_SupportUnit.java @@ -0,0 +1,20 @@ +package com.dy.testClient; + +import com.dy.common.mw.support.SupportUnitAdapter; +import com.dy.common.mw.support.SupportUnitConfigVo; + +public class AdapterImp_SupportUnit implements SupportUnitAdapter { + + private SupportUnitConfigVo configVo = null ; + + @Override + public SupportUnitConfigVo getConfig() { + return this.configVo; + } + + public void setConfig(SupportUnitConfigVo configVo) { + this.configVo = configVo; + } + + +} diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/Server.java b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/Server.java new file mode 100644 index 0000000..51ec694 --- /dev/null +++ b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/Server.java @@ -0,0 +1,134 @@ +package com.dy.testClient; +import java.util.ArrayList; +import java.util.List; + +import com.dy.testClient.tcpClient.TcpClUnit; +import com.dy.testClient.tcpClient.TcpClUnitConfigVo; +import org.jdom2.Document; + +import com.dy.testClient.rmiClient.RmiClUnit; +import com.dy.testClient.rmiClient.RmiClUnitConfigVo; +import com.dy.common.mw.UnitInterface; +import com.dy.common.mw.support.SupportUnit; +import com.dy.common.mw.support.SupportUnitConfigVo; +import com.dy.common.util.ConfigXml; +public class Server { + + private ConfigXml conf = null ; + private Document doc = null ; + private boolean showStartInfo = false ; + + private final List<UnitInterface> units = new ArrayList<UnitInterface>() ; + + /** + * @param args + */ + public static void main(String[] args) { + Server sv = new Server(); + Long start = System.currentTimeMillis() ; + try { + sv.conf = new ConfigXml() ; + 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 = null ; + try{ + svName = sv.conf.getSetAttrTxt(sv.doc, "config.server", "name", null, false, null) ; + }catch(Exception e){ + svName = "" ; + } + + System.out.println("") ; + 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 + "tcpTestClient " ) ; + System.out.println("@@@@@@$ @@@@@@@@@ &@@@@@@@@") ; + System.out.println("@@@@@@$ O@@@@@@@@@ &@@@@@@@@") ; + 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 &@@@@@@@@") ; + System.out.println("") ; + + }catch(Exception e){ + e.printStackTrace(); + } + } + + private void startUnits(){ + try { + //////////////////////////////////////////////////////// + //鏀寔妯″潡锛� springHibernate鍜� 绾跨▼姹� + SupportUnitConfigVo supVo = new SupportUnitConfigVo() ; + //鐭伐浣滄椂闀跨嚎绋嬫睜锛岀嚎绋嬭礋璐g敤鏃惰緝鐭殑宸ヤ綔浠诲姟 + supVo.short_maxThread = conf.getSetAttrPlusInt(doc, "config.support", "short_maxThread", null, 1, 1000, null) ;//姹犱腑鏈�澶х嚎绋嬫暟涓烘墍鏈塁PU鏍告暟+1 + supVo.short_minThread = conf.getSetAttrPlusInt(doc, "config.support", "short_minThread", null, 1, 5, null) ;//姹犱腑鏈�灏忕嚎绋嬫暟 + supVo.short_freeTimeout = conf.getSetAttrPlusInt(doc, "config.support", "short_freeTimeout", null, 1, 90, null) * 1000 ;//绾跨▼鏁扮┖闂叉椂闀匡紝鑻ユ睜涓嚎绋嬫暟閲忓ぇ浜巑inThread锛屼笖鏈夌殑绾跨▼绌洪棽鏃堕暱瓒呰繃freeTimeout锛屽垯娓呴櫎璇ョ嚎绋嬶紝涓轰簡涓嶆竻闄わ紝鎶妋inThread涓巑axThread璁剧疆鐩哥瓑 + supVo.short_busyTimeout = conf.getSetAttrPlusInt(doc, "config.support", "short_busyTimeout", null, 1, 10, null) * 1000 ;//绾跨▼涓嶉棿鏂伐浣滄椂闀匡紙鍗曚綅涓虹)瓒呮椂闄愶紝璁や负绾跨▼宸茬粡浜嗗穿婧冿紝灏嗗己鍒舵竻闄わ紝鐭伐浣滄椂闀胯缃负5绉� + //闀垮伐浣滄椂闀跨嚎绋嬫睜锛岀嚎绋嬭礋璐g敤鏃惰緝闀跨殑宸ヤ綔浠诲姟 + supVo.long_maxThread = conf.getSetAttrInt(doc, "config.support", "long_maxThread", null, -1, 1000, null) ;//姹犱腑鏈�澶х嚎绋嬫暟,鑻ヤ负-1锛屼笉鍙楅檺鍒� + if(supVo.long_maxThread < 0){ + supVo.long_maxThread = -1 ; + } + supVo.long_minThread = conf.getSetAttrPlusInt(doc, "config.support", "long_minThread", null, 0, 5, null) ;//姹犱腑鏈�灏忕嚎绋嬫暟 + supVo.long_freeTimeout = conf.getSetAttrPlusInt(doc, "config.support", "long_freeTimeout", null, 1, 90, null) * 1000 ;//绾跨▼鏁扮┖闂叉椂闀匡紝鑻ユ睜涓嚎绋嬫暟閲忓ぇ浜巑inThread锛屼笖鏈夌殑绾跨▼绌洪棽鏃堕暱瓒呰繃freeTimeout锛屽垯娓呴櫎璇ョ嚎绋� + supVo.long_busyTimeout = conf.getSetAttrInt(doc, "config.support", "long_busyTimeout", null, -1, 10, null) ;//绾跨▼涓嶉棿鏂伐浣滄椂闀匡紙鍗曚綅涓虹)瓒呮椂闄愶紝鑻ヤ负-1锛屼笉鍙楅檺鍒� + if(supVo.long_busyTimeout < 0){ + supVo.long_busyTimeout = -1 ; + } + + supVo.showStartInfo = showStartInfo ; + + AdapterImp_SupportUnit supAdap = new AdapterImp_SupportUnit() ; + supAdap.setConfig(supVo); + SupportUnit supUnit = SupportUnit.getInstance() ; + supUnit.setAdapter(supAdap); + supUnit.start(obj -> { + }); + units.add(supUnit) ; + + // /////////////// + // rmi 妯″潡 + RmiClUnitConfigVo rmiClVo = new RmiClUnitConfigVo(); + rmiClVo.svUrl = conf.getSetAttrTxt(doc, "config.rmiCl", "rmiSvUrl", null, false, null) ; + rmiClVo.svContext = conf.getSetAttrTxt(doc, "config.rmiCl", "rmiSvContext", null, false, null) ; + rmiClVo.svPort = conf.getSetAttrPlusInt(doc, "config.rmiCl", "rmiSvPort", null, 0, 65535, null) ; + AdapterImp_RmiClUnit rmiClAdap = new AdapterImp_RmiClUnit(); + rmiClAdap.setConfig(rmiClVo); + RmiClUnit rmiClUnit = RmiClUnit.getInstance(); + rmiClUnit.setAdapter(rmiClAdap); + rmiClUnit.start(obj -> { + }); + units.add(rmiClUnit) ; + + + // /////////////// + // Tcp Client 妯″潡 + TcpClUnitConfigVo tcpClVo = new TcpClUnitConfigVo(); + tcpClVo.enable = conf.getSetAttrBoolean(doc, "config.tcpCl", "enable", null, null) ; + tcpClVo.heartbeatTimes = conf.getSetAttrPlusInt(doc, "config.tcpCl", "heartbeatTimes", null, 1, 10, null) ;//杩炵画閰嶇疆娆℃暟蹇冭烦鍚庡彂閫佷竴娆℃暟鎹� + tcpClVo.sendInterval = conf.getSetAttrPlusInt(doc, "config.tcpCl", "sendInterval", null, 1, 60, null) ;//鍙戦�佸績璺虫垨鏁版嵁鐨勬椂闂撮棿闅� + if(tcpClVo.enable){ + AdapterImp_TcpClUnit httpClAdap = new AdapterImp_TcpClUnit(); + httpClAdap.setConfig(tcpClVo); + TcpClUnit httpClUnit = TcpClUnit.getInstance(); + httpClUnit.setAdapter(httpClAdap); + httpClUnit.start(obj -> { + }); + units.add(httpClUnit) ; + } + } catch (Exception e) { + e.printStackTrace(); + } + } +} + diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/ServerProperties.java b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/ServerProperties.java new file mode 100644 index 0000000..7379686 --- /dev/null +++ b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/ServerProperties.java @@ -0,0 +1,18 @@ +package com.dy.testClient; + +public class ServerProperties { + + //RTU寮�濮嬪湴鍧� + public static Long rtuAddrStart = 0L ; + //RTU鎴鍦板潃 + public static Long rtuAddrEnd = 0L ; + //鏈嶅姟绔疘P + public static String serverIp = "" ; + //鏈嶅姟绔笂涓嬫枃 + public static Integer serverPort = 0 ; + //鍙戦�佹暟鎹鏁� + public static Integer sendTimes = 0 ; + + //mwTestServer鎺у埗鏄惁鍚姩 + public static boolean startWork = false ; +} diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/HttpClUnit.java b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/HttpClUnit.java new file mode 100644 index 0000000..9851e91 --- /dev/null +++ b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/HttpClUnit.java @@ -0,0 +1,112 @@ +package com.dy.testClient.httpCl; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import com.dy.testClient.rmiClient.RmiClUnit; +import com.dy.testClient.ServerProperties; +import com.dy.common.threadPool.ThreadPool; +import com.dy.common.threadPool.TreadPoolFactory; +import com.dy.common.mw.UnitAdapterInterface; +import com.dy.common.mw.UnitInterface; +import com.dy.common.mw.UnitStartedCallbackInterface; + +public class HttpClUnit implements UnitInterface { + + private static Logger log = LogManager.getLogger(HttpClUnit.class) ; + + private static HttpClUnit instance = new HttpClUnit() ; + + public static HttpClUnitAdapter adapter ; + public static HttpClUnitConfigVo confVo ; + + private static ThreadPool.Pool pool ; + + private static Integer totalRunedClientCount = 0; + private static Integer totalOverClientCount = 0; + + private static Long startTime = 0L ; + + private HttpClUnit(){} ; + + public static HttpClUnit getInstance(){ + return instance ; + } + + @Override + public void setAdapter(UnitAdapterInterface adapter) throws Exception { + if(adapter == null){ + throw new Exception("Http Client妯″潡閫傞厤鍣ㄥ璞′笉鑳戒负绌猴紒") ; + } + HttpClUnit.adapter = (HttpClUnitAdapter)adapter ; + HttpClUnit.confVo = HttpClUnit.adapter.getConfig() ; + if(HttpClUnit.confVo == null){ + throw new Exception("Http Client妯″潡閰嶇疆瀵硅薄涓嶈兘涓虹┖锛�") ; + } + } + + @Override + public void start(UnitStartedCallbackInterface callback) throws Exception { + pool = TreadPoolFactory.getThreadPoolLong() ; + System.out.println("Http Client妯″潡鎴愬姛鍚姩"); + this.doStart(); + callback.call(null) ; + } + + @Override + public void stop(UnitStartedCallbackInterface callback) throws Exception { + callback.call(null); + } + + private void doStart(){ + new Thread(new Runnable(){ + @Override + public void run() { + try { + while(true){ + if(!ServerProperties.startWork){ + Thread.sleep(100L); + }else{ + startTime = System.currentTimeMillis() ; + for(Long i = ServerProperties.rtuAddrStart ; i <= ServerProperties.rtuAddrEnd; i++){ + totalRunedClientCount++ ; + startClient(i) ; + } + while(true){ + if(totalOverClientCount.longValue() >= totalRunedClientCount.longValue()){ + Long seconds = (System.currentTimeMillis() - startTime)/1000 ; + RmiClUnit.getInstance().reportHadReportOver(seconds) ; + System.out.println("鍏辩敤鏃�" + seconds + "绉�"); + break ; + }else{ + Thread.sleep(100L); + } + } + break; + } + } + } catch (Exception e) { + e.printStackTrace(); + } + } + }).start(); + } + + private void startClient(Long imei){ + try { + pool.putJob(new MyThreadJob("" + imei)); + } catch (Exception e) { + log.error("HttpClUnit.startClient() ", e); + } + } + + + public static synchronized void clientOver(){ + totalOverClientCount++; + if(totalOverClientCount % 100 == 0){ + RmiClUnit.getInstance().reportHadReportCount(totalOverClientCount); + System.out.println("宸茬粡鍙戦��" + totalOverClientCount + "鏉℃暟鎹�"); + } + } + +} diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/HttpClUnitAdapter.java b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/HttpClUnitAdapter.java new file mode 100644 index 0000000..8f80484 --- /dev/null +++ b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/HttpClUnitAdapter.java @@ -0,0 +1,9 @@ +package com.dy.testClient.httpCl; + +import com.dy.common.mw.UnitAdapterInterface; + +public interface HttpClUnitAdapter extends UnitAdapterInterface { + + public HttpClUnitConfigVo getConfig() ; + +} diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/HttpClUnitConfigVo.java b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/HttpClUnitConfigVo.java new file mode 100644 index 0000000..7b3513d --- /dev/null +++ b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/HttpClUnitConfigVo.java @@ -0,0 +1,5 @@ +package com.dy.testClient.httpCl; + +public class HttpClUnitConfigVo { + public boolean enable ; +} diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/HttpPost.java b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/HttpPost.java new file mode 100644 index 0000000..3b8e37b --- /dev/null +++ b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/HttpPost.java @@ -0,0 +1,11 @@ +package com.dy.testClient.httpCl; + +import com.dy.testClient.ServerProperties; +import com.dy.common.util.HttpUtils; + +public class HttpPost { + + public static synchronized void post(byte[] bytes) throws Exception{ + //HttpUtils.doPost(ServerProperties.serverUrl, ServerProperties.serverContext, null, null, bytes) ; + } +} diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/MyThreadJob.java b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/MyThreadJob.java new file mode 100644 index 0000000..d3494c5 --- /dev/null +++ b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/MyThreadJob.java @@ -0,0 +1,76 @@ +package com.dy.testClient.httpCl; + +import java.util.Base64; + +import com.dy.common.threadPool.ThreadPool; + +public class MyThreadJob implements ThreadPool.Job { + + public String imei ; + + public MyThreadJob(){ + } + public MyThreadJob(String imei){ + this.imei = imei ; + } + + @Override + public void execute() throws Exception { + testMeterV1_0() ; + //testHAC_NBhV2_5() ; + } + + private void testMeterV1_0(){ + try{ + RtuData4MeterV1_0 rd = new RtuData4MeterV1_0() ; + byte[] bs = rd.create(imei) ; + bs = Base64.getEncoder().encode(bs) ; + + UpDataPayloadVo payloadVo = new UpDataPayloadVo() ; + payloadVo.APPdata = new String(bs, "UTF-8") ; + + UpDataVo vo = new UpDataVo(imei, "8086" + imei ) ; + vo.payload = payloadVo ; + String json = vo.toJson() ; + byte[] bytes = json.getBytes() ; + HttpPost.post(bytes); + }catch(Exception e){ + e.printStackTrace(); + }finally{ + HttpClUnit.clientOver() ; + } + } + + @SuppressWarnings("unused") + private void testHAC_NBhV2_5(){ + try{ + RtuData4HAC_NBhV2_5 rd = new RtuData4HAC_NBhV2_5() ; + byte[] bs = rd.create(imei) ; + bs = Base64.getEncoder().encode(bs) ; + + UpDataPayloadVo payloadVo = new UpDataPayloadVo() ; + payloadVo.APPdata = new String(bs, "UTF-8") ; + + UpDataVo vo = new UpDataVo(imei, "8086" + imei ) ; + vo.payload = payloadVo ; + String json = vo.toJson() ; + byte[] bytes = json.getBytes() ; + HttpPost.post(bytes); + }catch(Exception e){ + e.printStackTrace(); + }finally{ + HttpClUnit.clientOver() ; + } + } + + @Override + public void destroy() { + } + + @Override + public boolean isDestroy() { + return false; + } + + +} diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/RtuData4HAC_NBhV2_5.java b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/RtuData4HAC_NBhV2_5.java new file mode 100644 index 0000000..52c839f --- /dev/null +++ b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/RtuData4HAC_NBhV2_5.java @@ -0,0 +1,46 @@ +package com.dy.testClient.httpCl; + +import com.dy.common.util.ByteUtil; + +public class RtuData4HAC_NBhV2_5 { + public byte[] create(String imei) throws Exception{ + /* + * 0101 + * 00 + * 02 + * 4643 + * 3C + * 00BE + * FF + * 86AB62626E642F332F30026A313233343536373839300D1A64B8FCE60E655554432B3801634E42680719016E110112655056332E30136C56332E30345F32323034323214001701A762626E652F38302F3001020600101A00000000171A00000000181A1A00000000181F00A462626E652F38312F30030101000201A462626E652F38322F30000001000200A262626E652F38342F30001A00015180A462626E652F39392F30016F3836333331383036303136393235390D3903010E390013 + * EA77 + * + */ + String hex = "0101024570753C001AFFA30D1B000001898AB2E3160E655554432B3862626E642F332F303190" ; + //String hex = "0101000246433C00BEFF86AB62626E642F332F30026A313233343536373839300D1A64B8FCE60E655554432B3801634E42680719016E110112655056332E30136C56332E30345F32323034323214001701A762626E652F38302F3001020600101A00000000171A00000000181A1A00000000181F00A462626E652F38312F30030101000201A462626E652F38322F30000001000200A262626E652F38342F30001A00015180A462626E652F39392F30016F3836333331383036303136393235390D3903010E390013EA77" ; + return ByteUtil.hex2Bytes(hex) ; + } + /* + * +86AB62626E642F332F30 +026A3132333435363738 +39300D1A64B8FCE60E65 +5554432B3801634E4268 +0719016E110112655056 +332E30136C56332E3034 +5F323230343232140017 +01A762626E652F38302F +3001020600101A000000 +00171A00000000181A1A +00000000181F00A46262 +6E652F38312F30030101 +000201A462626E652F38 +322F30000001000200A2 +62626E652F38342F3000 +1A00015180A462626E65 +2F39392F30016F383633 +33313830363031363932 +35390D3903010E390013 + */ + +} diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/RtuData4MeterV1_0.java b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/RtuData4MeterV1_0.java new file mode 100644 index 0000000..daf8340 --- /dev/null +++ b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/RtuData4MeterV1_0.java @@ -0,0 +1,165 @@ +package com.dy.testClient.httpCl; + +import com.dy.common.mw.protocol.pMeterV1_0_1.ProtocolConstantV1_0_1; +import com.dy.common.util.ByteUtil; +import com.dy.common.util.ByteUtilUnsigned; +import com.dy.common.util.CreateRadom; +import com.dy.common.util.DateTime; + +public class RtuData4MeterV1_0 { + public byte[] create(String imei) throws Exception{ + /* + * 68 + * 0051 + * 01 + * 0300000000000001 + * 12233445566778 + * 01 + * 221128152107 + * 0001E240 + * 000004D2 + * 24 + * 0129 + * 11 + * 002D + * 0035 + * 003D + * 006E + * 0038 + * 00C3 + * 00AC + * 004C + * 0028 + * 0081 + * 001B + * 005E + * 003D + * 0063 + * 00AB + * 0071 + * 00BB + * 0046 + * 004A + * 009B + * 0087 + * 00BE + * 0022 + * 00B0 + * DA + * 16 + */ + int len = 89 ; + byte[] bs = new byte[len] ; + bs[0] = ProtocolConstantV1_0_1.P_Head_Byte ; + ByteUtilUnsigned.short2Bytes_BE(bs, len, 1);//闀垮害 + bs[3] = (byte)101 ;//鍗忚鐗堟湰鍙� + while(true){ + if(imei.length() >= 16){ + break ; + }else{ + imei = "0" + imei ; + } + } + ByteUtil.string2BCD_BE(bs, imei, 4) ;//IMEI鍙� + + String meterNo = "" + (Long.valueOf(imei) + 1); + while(true){ + if(meterNo.length() >= 16){ + break ; + }else{ + meterNo = "0" + meterNo ; + } + } + ByteUtil.string2BCD_BE(bs, meterNo, 12) ;//姘磋〃鍙� + + bs[20] = 1 ;//鍔熻兘鐮� + + ByteUtil.string2BCD_BE(bs, DateTime.yyMMddhhmmss(), 21) ;//鏃堕棿 + + ByteUtilUnsigned.int2Bytes_BE(bs, 123456, 27);//瀹炴椂绱姘撮噺 + + ByteUtilUnsigned.int2Bytes_BE(bs, 54321, 31);//鏃ョ疮璁℃按閲� + + bs[35] = (byte)36;//鐢垫睜鐢靛帇 + + ByteUtilUnsigned.short2Bytes_BE(bs, 297, 36);//淇″彿寮哄害 + + byte sta = 0 ; + int num = CreateRadom.radom_4() ; + if(num%2 == 0){ + sta += 1 ;//闃�闂ㄧ姸鎬� + } + num = CreateRadom.radom_4() ; + if(num%2 == 0){ + sta += 4 ;//闃�闂ㄦ晠闅� + } + num = CreateRadom.radom_4() ; + if(num%2 == 0){ + sta += 8 ;//寮虹 + } + num = CreateRadom.radom_4() ; + if(num%2 == 0){ + sta += 16 ;//鐢垫睜娆犲帇 + } + bs[38] = sta;//琛ㄧ姸鎬� + + num = CreateRadom.radom(200, 10) ; + ByteUtilUnsigned.short2Bytes_BE(bs, num, 39);//1鐐瑰皬鏃剁敤姘撮噺 + num = CreateRadom.radom(200, 10) ; + ByteUtilUnsigned.short2Bytes_BE(bs, num, 41);//2鐐瑰皬鏃剁敤姘撮噺 + num = CreateRadom.radom(200, 10) ; + ByteUtilUnsigned.short2Bytes_BE(bs, num, 43);//3 + num = CreateRadom.radom(200, 10) ; + ByteUtilUnsigned.short2Bytes_BE(bs, num, 45);//4 + num = CreateRadom.radom(200, 10) ; + ByteUtilUnsigned.short2Bytes_BE(bs, num, 47);//5 + num = CreateRadom.radom(200, 10) ; + ByteUtilUnsigned.short2Bytes_BE(bs, num, 49);//6 + num = CreateRadom.radom(200, 10) ; + ByteUtilUnsigned.short2Bytes_BE(bs, num, 51);//7 + num = CreateRadom.radom(200, 10) ; + ByteUtilUnsigned.short2Bytes_BE(bs, num, 53);//8 + num = CreateRadom.radom(200, 10) ; + ByteUtilUnsigned.short2Bytes_BE(bs, num, 55);//9 + num = CreateRadom.radom(200, 10) ; + ByteUtilUnsigned.short2Bytes_BE(bs, num, 57);//10 + num = CreateRadom.radom(200, 10) ; + ByteUtilUnsigned.short2Bytes_BE(bs, num, 59);//11 + num = CreateRadom.radom(200, 10) ; + ByteUtilUnsigned.short2Bytes_BE(bs, num, 61);//12 + num = CreateRadom.radom(200, 10) ; + ByteUtilUnsigned.short2Bytes_BE(bs, num, 63);//13 + num = CreateRadom.radom(200, 10) ; + ByteUtilUnsigned.short2Bytes_BE(bs, num, 65);//14 + num = CreateRadom.radom(200, 10) ; + ByteUtilUnsigned.short2Bytes_BE(bs, num, 67);//15 + num = CreateRadom.radom(200, 10) ; + ByteUtilUnsigned.short2Bytes_BE(bs, num, 69);//16 + num = CreateRadom.radom(200, 10) ; + ByteUtilUnsigned.short2Bytes_BE(bs, num, 71);//17 + num = CreateRadom.radom(200, 10) ; + ByteUtilUnsigned.short2Bytes_BE(bs, num, 73);//18 + num = CreateRadom.radom(200, 10) ; + ByteUtilUnsigned.short2Bytes_BE(bs, num, 75);//19 + num = CreateRadom.radom(200, 10) ; + ByteUtilUnsigned.short2Bytes_BE(bs, num, 77);//20 + num = CreateRadom.radom(200, 10) ; + ByteUtilUnsigned.short2Bytes_BE(bs, num, 79);//21 + num = CreateRadom.radom(200, 10) ; + ByteUtilUnsigned.short2Bytes_BE(bs, num, 81);//22 + num = CreateRadom.radom(200, 10) ; + ByteUtilUnsigned.short2Bytes_BE(bs, num, 83);//23 + num = CreateRadom.radom(200, 10) ; + ByteUtilUnsigned.short2Bytes_BE(bs, num, 85);//24 + + byte he = 0 ; + for(byte i = 0 ; i <= 86; i++){ + he = (byte)(he + bs[i]) ; + } + ByteUtilUnsigned.byte2Byte(bs, he, 87) ; + bs[88] = ProtocolConstantV1_0_1.P_Tail_Byte ; + + return bs ; + } + +} diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/TestBase64.java b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/TestBase64.java new file mode 100644 index 0000000..8bdda86 --- /dev/null +++ b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/TestBase64.java @@ -0,0 +1,23 @@ +package com.dy.testClient.httpCl; + +import java.io.UnsupportedEncodingException; +import java.util.Base64; + +import com.dy.common.util.ByteUtil; + +public class TestBase64 { + + public static void main(String[] args) throws UnsupportedEncodingException{ + String hex1 = "6838363235393230353934333439373000002002303231310000000000000032003005002E000000000001000000000200000000032101010012330400300521010100123306016907016908000009FF0000FC16" ; + System.out.println(hex1); + byte[] bs = ByteUtil.hex2Bytes(hex1) ; + bs = Base64.getEncoder().encode(bs) ; + String base64 = new String(bs, "UTF-8") ; + System.out.println(base64); + + bs = Base64.getDecoder().decode(base64); + String hex2 = ByteUtil.bytes2Hex(bs, false) ; + System.out.println(hex2); + + } +} diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/UpDataPayloadVo.java b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/UpDataPayloadVo.java new file mode 100644 index 0000000..8e1e7ff --- /dev/null +++ b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/UpDataPayloadVo.java @@ -0,0 +1,16 @@ +package com.dy.testClient.httpCl; + +public class UpDataPayloadVo { + + public String APPdata ; + + + public String getAPPdata() { + return APPdata; + } + + public void setAPPdata(String aPPdata) { + APPdata = aPPdata; + } + +} diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/UpDataVo.java b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/UpDataVo.java new file mode 100644 index 0000000..88f1e19 --- /dev/null +++ b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/UpDataVo.java @@ -0,0 +1,174 @@ +package com.dy.testClient.httpCl; + + +import com.alibaba.fastjson2.JSON; + +public class UpDataVo { + + public Integer upPacketSN; //:-1, + public Integer upDataSN; //:-1, + public String topic; //:"v1/up/ad", + public Long timestamp; //:1667302244541, + public String tenantId; //:"2000114347", + public String serviceId; //:"", + public String protocol; //:"lwm2m", + public String productId; //:"15410798", + public UpDataPayloadVo payload; //:{"APPdata":"pQAYWhAGFQEmECIgETMgIQEBACASARckZFoAAFeq"}, + public String messageType; //:"dataReport", + public String deviceType; //:"", + public String deviceId; //:"59a4d90bf7a04aeea4d3523fe15d6f3f", + public String assocAssetId; //:"", + public String imsi; //:"undefined", + public String imei; //:"862592059434970" + + public UpDataVo(String imei, String deviceId){ + this.upPacketSN = - 1 ; + this.upDataSN = - 1 ; + this.topic = "v1/up/ad" ; + this.timestamp = System.currentTimeMillis() ; + this.tenantId = "2000114347" ; + this.serviceId = "" ; + this.protocol = "lwm2m" ; + this.productId = "15410798" ; + this.messageType = "dataReport" ; + this.deviceType = "" ; + this.deviceId = deviceId ; + this.assocAssetId = "" ; + this.imsi = "" ; + this.imei = imei ; + } + + public String toString(){ + StringBuffer sb = new StringBuffer() ; + sb.append("\nproductId锛�" + productId + "\n") ; + sb.append("deviceId锛�" + deviceId + "\n") ; + sb.append("imei锛�" + imei + "\n") ; + sb.append("payload锛�" + (payload==null?"":payload.APPdata) + "\n") ; + sb.append("timestamp锛�" + timestamp + "\n") ; + return sb.toString() ; + } + + /** + * 瀵硅薄杞垚json + * @return json + * @throws Exception 寮傚父 + */ + public String toJson()throws Exception{ + try{ + return JSON.toJSONString(this) ; + //return new JSONSerializer().exclude(new String[]{"class", "*.class"}).deepSerialize(this); + }catch(Exception e){ + throw new Exception(e.getMessage() , e ) ; + } + } + /** + * json杞垚瀵硅薄 + * @param json json + * @return 瀵硅薄 + * @throws Exception 寮傚父 + */ + public static UpDataVo jsonToObject(String json)throws Exception{ + try{ + return JSON.parseObject(json, UpDataVo.class) ; + //return new JSONDeserializer<UpDataVo>() + // .use("payload", UpDataPayloadVo.class) + // .deserialize(json, UpDataVo.class) ; + }catch(Exception e){ + throw new Exception(e.getMessage() , e ) ; + } + } + + + public Integer getUpPacketSN() { + return upPacketSN; + } + public void setUpPacketSN(Integer upPacketSN) { + this.upPacketSN = upPacketSN; + } + public Integer getUpDataSN() { + return upDataSN; + } + public void setUpDataSN(Integer upDataSN) { + this.upDataSN = upDataSN; + } + public String getTopic() { + return topic; + } + public void setTopic(String topic) { + this.topic = topic; + } + public Long getTimestamp() { + return timestamp; + } + public void setTimestamp(Long timestamp) { + this.timestamp = timestamp; + } + public String getTenantId() { + return tenantId; + } + public void setTenantId(String tenantId) { + this.tenantId = tenantId; + } + public String getServiceId() { + return serviceId; + } + public void setServiceId(String serviceId) { + this.serviceId = serviceId; + } + public String getProtocol() { + return protocol; + } + public void setProtocol(String protocol) { + this.protocol = protocol; + } + public String getProductId() { + return productId; + } + public void setProductId(String productId) { + this.productId = productId; + } + public UpDataPayloadVo getPayload() { + return payload; + } + public void setPayload(UpDataPayloadVo payload) { + this.payload = payload; + } + public String getMessageType() { + return messageType; + } + public void setMessageType(String messageType) { + this.messageType = messageType; + } + public String getDeviceType() { + return deviceType; + } + public void setDeviceType(String deviceType) { + this.deviceType = deviceType; + } + public String getDeviceId() { + return deviceId; + } + public void setDeviceId(String deviceId) { + this.deviceId = deviceId; + } + public String getAssocAssetId() { + return assocAssetId; + } + public void setAssocAssetId(String assocAssetId) { + this.assocAssetId = assocAssetId; + } + public String getIMSI() { + return imsi; + } + public void setIMSI(String iMSI) { + imsi = iMSI; + } + public String getIMEI() { + return imei; + } + public void setIMEI(String iMEI) { + imei = iMEI; + } + + +} diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/rmiClient/Code.java b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/rmiClient/Code.java new file mode 100644 index 0000000..4fcd76b --- /dev/null +++ b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/rmiClient/Code.java @@ -0,0 +1,15 @@ +package com.dy.testClient.rmiClient; + +public class Code { + + public static String cd1 = "001" ;//娉ㄥ唽 + + public static String cd2 = "002" ;//璇锋眰sepTest鐨勯厤缃� + + public static String cd3 = "003" ;//璇锋眰寮�濮嬪伐浣� + + public static String cd4 = "004" ;//鍚戞湇鍔$涓婃姤淇℃伅 + + public static String cd5 = "005" ;//鍚戞湇鍔$涓婃姤 鏁版嵁涓婃姤宸ヤ綔宸茬粡瀹屾垚 + +} diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/rmiClient/ResConfigVo.java b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/rmiClient/ResConfigVo.java new file mode 100644 index 0000000..c3affa5 --- /dev/null +++ b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/rmiClient/ResConfigVo.java @@ -0,0 +1,84 @@ +package com.dy.testClient.rmiClient; + +import com.alibaba.fastjson2.JSON; + +public class ResConfigVo { + //妯℃嫙瀹㈡埛鐨凴tuAddr璧峰鍙� + public Long rtuAddrStart = 0L ; + //妯℃嫙瀹㈡埛鐨処MEI鍙锋埅姝㈠彿 + public Long rtuAddrEnd = 0L ; + //鏈嶅姟绔疘P + public String serverIp = "" ; + //鏈嶅姟绔笂涓嬫枃 + public Integer serverPort = 0 ; + //鍙戦�佹暟鎹鏁� + public Integer sendTimes = 0 ; + + /** + * 瀵硅薄杞垚json + * @return 瀵硅薄json + * @throws Exception 寮傚父 + */ + public String toJson()throws Exception{ + try{ + return JSON.toJSONString(this) ; + //return new JSONSerializer().exclude(new String[]{"class", "*.class"}).deepSerialize(this); + }catch(Exception e){ + throw new Exception(e.getMessage() , e ) ; + } + } + /** + * json杞垚瀵硅薄 + * @param json json + * @return 瀵硅薄 + * @throws Exception 寮傚父 + */ + public static ResConfigVo jsonToObject(String json)throws Exception{ + try{ + return JSON.parseObject(json, ResConfigVo.class) ; + //return new JSONDeserializer<ResConfigVo>().deserialize(json, ResConfigVo.class) ; + }catch(Exception e){ + throw new Exception(e.getMessage() , e ) ; + } + } + + public Long getRtuAddrStart() { + return rtuAddrStart; + } + + public void setRtuAddrStart(Long rtuAddrStart) { + this.rtuAddrStart = rtuAddrStart; + } + + public Long getRtuAddrEnd() { + return rtuAddrEnd; + } + + public void setRtuAddrEnd(Long rtuAddrEnd) { + this.rtuAddrEnd = rtuAddrEnd; + } + + public String getServerIp() { + return serverIp; + } + + public void setServerIp(String serverIp) { + this.serverIp = serverIp; + } + + public Integer getServerPort() { + return serverPort; + } + + public void setServerPort(Integer serverPort) { + this.serverPort = serverPort; + } + + public Integer getSendTimes() { + return sendTimes; + } + + public void setSendTimes(Integer sendTimes) { + this.sendTimes = sendTimes; + } +} diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/rmiClient/ResRegisterVo.java b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/rmiClient/ResRegisterVo.java new file mode 100644 index 0000000..3977070 --- /dev/null +++ b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/rmiClient/ResRegisterVo.java @@ -0,0 +1,45 @@ +package com.dy.testClient.rmiClient; + +import com.alibaba.fastjson2.JSON; + +public class ResRegisterVo { + + public String token ; + + /** + * 瀵硅薄杞垚json + * @return json + * @throws Exception 寮傚父 + */ + public String toJson()throws Exception{ + try{ + return JSON.toJSONString(this) ; + //return new JSONSerializer().exclude(new String[]{"class", "*.class"}).deepSerialize(this); + }catch(Exception e){ + throw new Exception(e.getMessage() , e ) ; + } + } + /** + * json杞垚瀵硅薄 + * @param json json + * @return 瀵硅薄 + * @throws Exception 寮傚父 + */ + public static ResRegisterVo jsonToObject(String json)throws Exception{ + try{ + return JSON.parseObject(json, ResRegisterVo.class) ; + //return new JSONDeserializer<ResRegisterVo>().deserialize(json, ResRegisterVo.class) ; + }catch(Exception e){ + throw new Exception(e.getMessage() , e ) ; + } + } + + public String getToken() { + return token; + } + + public void setToken(String id) { + this.token = id; + } + +} diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/rmiClient/ResStartVo.java b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/rmiClient/ResStartVo.java new file mode 100644 index 0000000..12f2ca6 --- /dev/null +++ b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/rmiClient/ResStartVo.java @@ -0,0 +1,47 @@ +package com.dy.testClient.rmiClient; + + +import com.alibaba.fastjson2.JSON; + +public class ResStartVo { + + public boolean start ; + + + /** + * 瀵硅薄杞垚json + * @return json + * @throws Exception 寮傚父 + */ + public String toJson()throws Exception{ + try{ + return JSON.toJSONString(this) ; + //return new JSONSerializer().exclude(new String[]{"class", "*.class"}).deepSerialize(this); + }catch(Exception e){ + throw new Exception(e.getMessage() , e ) ; + } + } + /** + * json杞垚瀵硅薄 + * @param json json + * @return 瀵硅薄 + * @throws Exception 寮傚父 + */ + public static ResStartVo jsonToObject(String json)throws Exception{ + try{ + return JSON.parseObject(json, ResStartVo.class) ; + //return new JSONDeserializer<ResStartVo>().deserialize(json, ResStartVo.class) ; + }catch(Exception e){ + throw new Exception(e.getMessage() , e ) ; + } + } + + public boolean isStart() { + return start; + } + + public void setStart(boolean start) { + this.start = start; + } + +} diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/rmiClient/RmiClUnit.java b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/rmiClient/RmiClUnit.java new file mode 100644 index 0000000..8d30bb8 --- /dev/null +++ b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/rmiClient/RmiClUnit.java @@ -0,0 +1,268 @@ +package com.dy.testClient.rmiClient; + +import com.dy.testClient.ServerProperties; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import com.dy.common.mw.UnitAdapterInterface; +import com.dy.common.mw.UnitInterface; +import com.dy.common.mw.UnitStartedCallbackInterface; +import com.dy.common.mw.channel.rmi.RmiFrameWork; + +public class RmiClUnit implements UnitInterface { + + private static final Logger log = LogManager.getLogger(RmiClUnit.class) ; + + private static final String id = "" + System.nanoTime() ;//鑷繁鐨刬d + + public static String token ;//鏈嶅姟绔彂鐨則oken + + private static final RmiClUnit instance = new RmiClUnit() ; + + private static RmiFrameWork frmWork = null ; + + public static RmiClUnitAdapter adapter ; + public static RmiClUnitConfigVo confVo ; + + private RmiClUnit(){} + + public static RmiClUnit getInstance(){ + return instance ; + } + + @Override + public void setAdapter(UnitAdapterInterface adapter) throws Exception { + if(adapter == null){ + throw new Exception("Rmi Client妯″潡閫傞厤鍣ㄥ璞′笉鑳戒负绌猴紒") ; + } + RmiClUnit.adapter = (RmiClUnitAdapter)adapter ; + RmiClUnit.confVo = RmiClUnit.adapter.getConfig() ; + if(RmiClUnit.confVo == null){ + throw new Exception("Rmi Client妯″潡閰嶇疆瀵硅薄涓嶈兘涓虹┖锛�") ; + } + } + + @Override + public void start(UnitStartedCallbackInterface callback) throws Exception { + System.out.println("Rmi Client妯″潡鎴愬姛鍚姩"); + this.doStart(); + callback.call(null) ; + } + + @Override + public void stop(UnitStartedCallbackInterface callback) throws Exception { + callback.call(null); + } + + private void doStart(){ + new Thread(() -> { + while(true){ + try { + Thread.sleep(100L); + frmWork = getRmiFrameWork() ; + if(frmWork != null){ + break ; + } + } catch (Exception e) { + log.error("寰楀埌rmiFramWork澶辫触" + e.getMessage()); + continue ; + } + } + register(frmWork) ; + }).start(); + } + + public RmiFrameWork getRmiFrameWork(){ + RmiClient rmiCl = new RmiClient(confVo.svUrl, confVo.svPort, confVo.svContext) ; + return rmiCl.getRmiInterface() ; + } + + //鎶婁笂鎶ユ暟鎹殑鏁伴噺涓婃姤缁檓wTestServer + public void reportHadReportCount(Integer count){ + try { + Thread.sleep(100L); + RmiRequestVo rqVo = new RmiRequestVo() ; + rqVo.id = id ; + rqVo.token = token ; + rqVo.code = Code.cd4 ; + rqVo.count = count ; + String json = rqVo.toJson() ; + frmWork.syncRequest(json) ; + } catch (Exception e) { + log.error("鎶婁笂鎶ユ暟鎹殑鏁伴噺涓婃姤缁檓wTestServer澶辫触" + e.getMessage()); + } + } + + //鎶婃暟鎹笂鎶ュ畬鎴愭儏鍐� 涓婃姤缁檓wTestServer + public void reportHadReportOver(Long seconds){ + try { + Thread.sleep(100L); + RmiRequestVo rqVo = new RmiRequestVo() ; + rqVo.id = id ; + rqVo.token = token ; + rqVo.code = Code.cd5 ; + rqVo.over = true ; + rqVo.seconds = seconds ; + String json = rqVo.toJson() ; + frmWork.syncRequest(json) ; + } catch (Exception e) { + log.error("鎶婃暟鎹笂鎶ュ畬鎴愭儏鍐� 涓婃姤缁檓wTestServer澶辫触" + e.getMessage()); + } + } + + //鍚憁wTestServer娉ㄥ唽 + private void register(RmiFrameWork frmWork){ + boolean error = false ; + while(true){ + try { + Thread.sleep(100L); + RmiRequestVo rqVo = new RmiRequestVo() ; + rqVo.id = id ; + rqVo.code = Code.cd1 ; + String json = rqVo.toJson() ; + Object rObj = frmWork.syncRequest(json) ; + if(rObj != null){ + RmiResponseVo rspVo = RmiResponseVo.jsonToObject(String.valueOf(rObj), ResRegisterVo.class) ; + if(rspVo != null){ + if(rspVo.success){ + if(rspVo.obj != null && rspVo.obj instanceof ResRegisterVo){ + ResRegisterVo rVo = (ResRegisterVo)rspVo.obj ; + token = rVo.token ; + log.info("娉ㄥ唽鎴愬姛锛屽緱鍒皌oken=" + token); + break ; + }else{ + log.error("rmi娉ㄥ唽澶辫触锛氭湇鍔$杩斿洖ResRegisterVo涓簄ull"); + error = true ; + } + }else{ + log.error("rmi娉ㄥ唽澶辫触锛氭湇鍔$杩斿洖閿欒锛�" + rspVo.errorInfo); + error = true ; + } + }else{ + log.error("rmi娉ㄥ唽澶辫触锛氭湇鍔$杩斿洖鐨凴miResponseVo涓簄ull"); + error = true ; + } + }else{ + log.error("rmi娉ㄥ唽澶辫触锛氭湇鍔$杩斿洖json涓簄ull"); + error = true ; + } + } catch (Exception e) { + log.error("rmi娉ㄥ唽澶辫触" + e.getMessage()); + error = true ; + continue ; + } + } + if(!error){ + getConfig(frmWork) ; + } + } + + //浠巑wTestServer寰楀埌閰嶇疆 + private void getConfig(RmiFrameWork frmWork){ + boolean error = false ; + while(true){ + try { + Thread.sleep(100L); + RmiRequestVo rqVo = new RmiRequestVo() ; + rqVo.id = id ; + rqVo.token = token ; + rqVo.code = Code.cd2 ; + String json = rqVo.toJson() ; + Object rObj = frmWork.syncRequest(json) ; + if(rObj != null){ + RmiResponseVo rspVo = RmiResponseVo.jsonToObject(String.valueOf(rObj), ResConfigVo.class) ; + if(rspVo != null){ + if(rspVo.success){ + if(rspVo.obj != null && rspVo.obj instanceof ResConfigVo){ + ResConfigVo rVo = (ResConfigVo)rspVo.obj ; + if(rVo != null){ + ServerProperties.rtuAddrStart = rVo.rtuAddrStart; + ServerProperties.rtuAddrEnd = rVo.rtuAddrEnd; + ServerProperties.serverIp = rVo.serverIp; + ServerProperties.serverPort = rVo.serverPort; + ServerProperties.sendTimes = rVo.sendTimes ; + log.info("寰楀埌閰嶇疆鎴愬姛"); + log.info(" 寮�濮婻tuAddr=" + ServerProperties.rtuAddrStart); + log.info(" 鎴RtuAddr=" + ServerProperties.rtuAddrEnd); + log.info(" mwAccept鏈嶅姟IP=" + ServerProperties.serverIp); + log.info(" mwAccept鏈嶅姟绔彛=" + ServerProperties.serverPort); + log.info(" 姣廼mei涓婃姤鏁版嵁娆℃暟=" + ServerProperties.sendTimes); + break ; + }else{ + log.error("rmi寰楀埌閰嶇疆澶辫触锛歫son杞琑esConfigVo涓簄ull"); + error = true ; + } + }else{ + log.error("rmi寰楀埌閰嶇疆澶辫触锛氭湇鍔$杩斿洖ResConfigVo涓簄ull"); + error = true ; + } + }else{ + log.error("rmi寰楀埌閰嶇疆澶辫触锛氭湇鍔$杩斿洖閿欒锛�" + rspVo.errorInfo); + error = true ; + } + }else{ + log.error("rmi寰楀埌閰嶇疆澶辫触锛氭湇鍔$杩斿洖鐨凴miResponseVo涓簄ull"); + error = true ; + } + }else{ + log.error("rmi寰楀埌閰嶇疆澶辫触锛氭湇鍔$杩斿洖json涓簄ull"); + error = true ; + } + } catch (Exception e) { + log.error("rmi寰楀埌閰嶇疆澶辫触" + e.getMessage()); + error = true ; + continue ; + } + } + if(!error){ + getStart(frmWork) ; + } + } + + //浠巑wTestServer寰楀埌寮�濮嬩笂鎶ユ暟鎹殑璇峰厑璁� + private void getStart(RmiFrameWork frmWork){ + log.info("绛夊緟鏈嶅姟绔厑璁镐笂鎶ユ暟鎹�"); + while(true){ + try { + Thread.sleep(100L); + RmiRequestVo rqVo = new RmiRequestVo() ; + rqVo.id = id ; + rqVo.token = token ; + rqVo.code = Code.cd3 ; + String json = rqVo.toJson() ; + Object rObj = frmWork.syncRequest(json) ; + if(rObj != null){ + RmiResponseVo rspVo = RmiResponseVo.jsonToObject(String.valueOf(rObj), ResStartVo.class) ; + if(rspVo != null){ + if(rspVo.success){ + if(rspVo.obj != null && rspVo.obj instanceof ResStartVo){ + ResStartVo rVo = (ResStartVo)rspVo.obj ; + if(rVo != null){ + if(rVo.start){ + ServerProperties.startWork = true ; + log.info("鍏佽涓婃姤鏁版嵁宸ヤ綔浜�( ^_^ )"); + break ; + } + }else{ + log.error("rmi璇锋眰鍚姩澶辫触锛歫son杞琑esStartVo涓簄ull"); + } + }else{ + log.error("rmi璇锋眰鍚姩澶辫触锛氭湇鍔$杩斿洖ResStartVo涓簄ull"); + } + }else{ + log.error("rmi璇锋眰鍚姩澶辫触锛氭湇鍔$杩斿洖閿欒锛�" + rspVo.errorInfo); + } + }else{ + log.error("rmi璇锋眰鍚姩澶辫触锛氭湇鍔$杩斿洖鐨凴miResponseVo涓簄ull"); + } + }else{ + log.error("rmi璇锋眰鍚姩澶辫触锛氭湇鍔$杩斿洖json涓簄ull"); + } + } catch (Exception e) { + log.error("rmi璇锋眰鍚姩澶辫触" + e.getMessage()); + continue ; + } + } + } + +} \ No newline at end of file diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/rmiClient/RmiClUnitAdapter.java b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/rmiClient/RmiClUnitAdapter.java new file mode 100644 index 0000000..0c70886 --- /dev/null +++ b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/rmiClient/RmiClUnitAdapter.java @@ -0,0 +1,10 @@ +package com.dy.testClient.rmiClient; + +import com.dy.common.mw.UnitAdapterInterface; + +public interface RmiClUnitAdapter extends UnitAdapterInterface { + + public RmiClUnitConfigVo getConfig() ; + +} + diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/rmiClient/RmiClUnitConfigVo.java b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/rmiClient/RmiClUnitConfigVo.java new file mode 100644 index 0000000..5a64f2f --- /dev/null +++ b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/rmiClient/RmiClUnitConfigVo.java @@ -0,0 +1,29 @@ +package com.dy.testClient.rmiClient; + +public class RmiClUnitConfigVo { + + public String svUrl ; + public String svContext ; + public Integer svPort ; + + public String getSvUrl() { + return svUrl; + } + public void setSvUrl(String svUrl) { + this.svUrl = svUrl; + } + public String getSvContext() { + return svContext; + } + public void setSvContext(String svContext) { + this.svContext = svContext; + } + public Integer getSvPort() { + return svPort; + } + public void setSvPort(Integer svPort) { + this.svPort = svPort; + } + + +} diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/rmiClient/RmiClient.java b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/rmiClient/RmiClient.java new file mode 100644 index 0000000..c78b6ed --- /dev/null +++ b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/rmiClient/RmiClient.java @@ -0,0 +1,40 @@ +package com.dy.testClient.rmiClient; + +import java.rmi.Naming; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import com.dy.common.mw.channel.rmi.RmiFrameWork; + +public class RmiClient { + + private static Logger log = LogManager.getLogger(RmiClient.class.getName()) ; + + private String rmiServerIp; + private Integer rmiServerPort; + private String rmiServerContext ; + + public RmiClient(String rmiServerIp, Integer rmiServerPort, String rmiServerContext){ + this.rmiServerIp = rmiServerIp ; + this.rmiServerPort = rmiServerPort ; + this.rmiServerContext = rmiServerContext ; + } + + /** + * 寰楀埌涓棿浠禦MI + * @return + */ + @SuppressWarnings("finally") + public RmiFrameWork getRmiInterface() { + String rmiServerUrl = "rmi://" + this.rmiServerIp + ":" + this.rmiServerPort + "/" + this.rmiServerContext ; + RmiFrameWork rmiIntf = null; + try { + rmiIntf = (RmiFrameWork) Naming.lookup(rmiServerUrl); + } catch (Exception e) { + log.error("杩炴帴RMI鏈嶅姟锛�" + rmiServerUrl + "鏃跺嚭閿欍��", e); + } finally { + return rmiIntf; + } + } +} diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/rmiClient/RmiRequestVo.java b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/rmiClient/RmiRequestVo.java new file mode 100644 index 0000000..c21c432 --- /dev/null +++ b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/rmiClient/RmiRequestVo.java @@ -0,0 +1,96 @@ +package com.dy.testClient.rmiClient; + +import com.alibaba.fastjson2.JSON; + +public class RmiRequestVo { + + public String id ; + + public String token ; + + public String code ; + + public Integer count;//aepTest涓婃姤鏁版嵁鏁伴噺 + + public Boolean over ;//aepTest涓婃姤鏁版嵁缁撴潫 + + public Long seconds ;//aepTest涓婃姤鏁版嵁鐢ㄦ椂(绉�) + + /** + * 瀵硅薄杞垚json + * @return json + * @throws Exception 寮傚父 + */ + public String toJson()throws Exception{ + try{ + return JSON.toJSONString(this) ; + //return new JSONSerializer().exclude(new String[]{"class", "*.class"}).deepSerialize(this); + }catch(Exception e){ + throw new Exception(e.getMessage() , e ) ; + } + } + /** + * json杞垚瀵硅薄 + * @param json json + * @return 瀵硅薄 + * @throws Exception 寮傚父 + */ + public static RmiRequestVo jsonToObject(String json)throws Exception{ + try{ + return JSON.parseObject(json, RmiRequestVo.class) ; + //JSONDeserializer<RmiRequestVo> jsonD = new JSONDeserializer<RmiRequestVo>() ; + //RmiRequestVo rqVo = jsonD.deserialize(json, RmiRequestVo.class) ; + //return rqVo ; + }catch(Exception e){ + throw new Exception(e.getMessage() , e ) ; + } + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getToken() { + return token; + } + + public void setToken(String token) { + this.token = token; + } + + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } + + public Integer getCount() { + return count; + } + + public void setCount(Integer count) { + this.count = count; + } + + public Boolean getOver() { + return over; + } + + public void setOver(Boolean over) { + this.over = over; + } + + public Long getSeconds() { + return seconds; + } + + public void setSeconds(Long seconds) { + this.seconds = seconds; + } +} diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/rmiClient/RmiResponseVo.java b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/rmiClient/RmiResponseVo.java new file mode 100644 index 0000000..658591a --- /dev/null +++ b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/rmiClient/RmiResponseVo.java @@ -0,0 +1,77 @@ +package com.dy.testClient.rmiClient; + +import com.alibaba.fastjson2.JSON; + +public class RmiResponseVo { + + public boolean success = true ; + + public String errorInfo ; + + public String code ; + + public Object obj ; + + /** + * 瀵硅薄杞垚json + * @return json + * @throws Exception 寮傚父 + */ + public String toJson()throws Exception{ + try{ + return JSON.toJSONString(this) ; + //return new JSONSerializer().exclude(new String[]{"class", "*.class"}).deepSerialize(this); + }catch(Exception e){ + throw new Exception(e.getMessage() , e ) ; + } + } + /** + * json杞垚瀵硅薄 + * @param json + * @return 瀵硅薄 + * @throws Exception 寮傚父 + */ + public static RmiResponseVo jsonToObject(String json, Class<?> clazz)throws Exception{ + try{ + return JSON.parseObject(json, RmiResponseVo.class) ; + //JSONDeserializer<RmiResponseVo> jsonD = new JSONDeserializer<RmiResponseVo>() ; + //jsonD.use("obj", clazz) ; + //RmiResponseVo resp = jsonD.deserialize(json, RmiResponseVo.class) ; + //return resp ; + }catch(Exception e){ + throw new Exception(e.getMessage() , e ) ; + } + } + + public boolean isSuccess() { + return success; + } + + public void setSuccess(boolean success) { + this.success = success; + } + + public String getErrorInfo() { + return errorInfo; + } + + public void setErrorInfo(String errorInfo) { + this.errorInfo = errorInfo; + } + + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } + + public Object getObj() { + return obj; + } + + public void setObj(Object obj) { + this.obj = obj; + } +} diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpClient/MyThreadJob.java b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpClient/MyThreadJob.java new file mode 100644 index 0000000..eee927c --- /dev/null +++ b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpClient/MyThreadJob.java @@ -0,0 +1,55 @@ +package com.dy.testClient.tcpClient; + +import com.dy.common.threadPool.ThreadPool; +import com.dy.testClient.httpCl.*; + +import java.util.Base64; + +public class MyThreadJob implements ThreadPool.Job { + + public String rtuAddr; + + public MyThreadJob(){ + } + public MyThreadJob(String rtuAddr){ + this.rtuAddr = rtuAddr ; + } + + @Override + public void execute() throws Exception { + testP206V1_0_0() ; + } + + private void testP206V1_0_0(){ + try{ + RtuData4MeterV1_0 rd = new RtuData4MeterV1_0() ; + byte[] bs = rd.create(rtuAddr) ; + bs = Base64.getEncoder().encode(bs) ; + + UpDataPayloadVo payloadVo = new UpDataPayloadVo() ; + payloadVo.APPdata = new String(bs, "UTF-8") ; + + UpDataVo vo = new UpDataVo(rtuAddr, "8086" + rtuAddr) ; + vo.payload = payloadVo ; + String json = vo.toJson() ; + byte[] bytes = json.getBytes() ; + HttpPost.post(bytes); + }catch(Exception e){ + e.printStackTrace(); + }finally{ + HttpClUnit.clientOver() ; + } + } + + + @Override + public void destroy() { + } + + @Override + public boolean isDestroy() { + return false; + } + + +} diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpClient/TcpClUnit.java b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpClient/TcpClUnit.java new file mode 100644 index 0000000..b25512c --- /dev/null +++ b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpClient/TcpClUnit.java @@ -0,0 +1,110 @@ +package com.dy.testClient.tcpClient; + +import com.dy.common.mw.UnitAdapterInterface; +import com.dy.common.mw.UnitInterface; +import com.dy.common.mw.UnitStartedCallbackInterface; +import com.dy.common.threadPool.ThreadPool; +import com.dy.common.threadPool.TreadPoolFactory; +import com.dy.testClient.ServerProperties; +import com.dy.testClient.rmiClient.RmiClUnit; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +public class TcpClUnit implements UnitInterface { + + private static final Logger log = LogManager.getLogger(TcpClUnit.class) ; + + private static TcpClUnit instance = new TcpClUnit() ; + + public static TcpClUnitAdapter adapter ; + public static TcpClUnitConfigVo confVo ; + + private static ThreadPool.Pool pool ; + + private static Integer totalRunedClientCount = 0; + private static Integer totalOverClientCount = 0; + + private static Long startTime = 0L ; + + private TcpClUnit(){} ; + + public static TcpClUnit getInstance(){ + return instance ; + } + + @Override + public void setAdapter(UnitAdapterInterface adapter) throws Exception { + if(adapter == null){ + throw new Exception("Tcp Client妯″潡閫傞厤鍣ㄥ璞′笉鑳戒负绌猴紒") ; + } + TcpClUnit.adapter = (TcpClUnitAdapter)adapter ; + TcpClUnit.confVo = TcpClUnit.adapter.getConfig() ; + if(TcpClUnit.confVo == null){ + throw new Exception("Tcp Client妯″潡閰嶇疆瀵硅薄涓嶈兘涓虹┖锛�") ; + } + } + + @Override + public void start(UnitStartedCallbackInterface callback) throws Exception { + pool = TreadPoolFactory.getThreadPoolLong() ; + System.out.println("Tcp Client妯″潡鎴愬姛鍚姩"); + this.doStart(); + callback.call(null) ; + } + + @Override + public void stop(UnitStartedCallbackInterface callback) throws Exception { + callback.call(null); + } + + private void doStart(){ + new Thread(new Runnable(){ + @Override + public void run() { + try { + while(true){ + if(!ServerProperties.startWork){ + Thread.sleep(100L); + }else{ + startTime = System.currentTimeMillis() ; + for(Long addr = ServerProperties.rtuAddrStart; addr <= ServerProperties.rtuAddrEnd; addr++){ + totalRunedClientCount++ ; + startClient(addr) ; + } + while(true){ + if(totalOverClientCount.longValue() >= totalRunedClientCount.longValue()){ + Long seconds = (System.currentTimeMillis() - startTime)/1000 ; + RmiClUnit.getInstance().reportHadReportOver(seconds) ; + System.out.println("鍏辩敤鏃�" + seconds + "绉�"); + break ; + }else{ + Thread.sleep(100L); + } + } + break; + } + } + } catch (Exception e) { + e.printStackTrace(); + } + } + }).start(); + } + + private void startClient(Long rtuAddr){ + try { + pool.putJob(new MyThreadJob("" + rtuAddr)); + } catch (Exception e) { + log.error("TcpClUnit.startClient() ", e); + } + } + + + public static synchronized void clientOver(){ + totalOverClientCount++; + if(totalOverClientCount % 100 == 0){ + RmiClUnit.getInstance().reportHadReportCount(totalOverClientCount); + System.out.println("宸茬粡鍙戦��" + totalOverClientCount * + "鏉℃暟鎹�"); + } + } +} diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpClient/TcpClUnitAdapter.java b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpClient/TcpClUnitAdapter.java new file mode 100644 index 0000000..43b6027 --- /dev/null +++ b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpClient/TcpClUnitAdapter.java @@ -0,0 +1,7 @@ +package com.dy.testClient.tcpClient; + +import com.dy.common.mw.UnitAdapterInterface; + +public interface TcpClUnitAdapter extends UnitAdapterInterface { + public TcpClUnitConfigVo getConfig() ; +} diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpClient/TcpClUnitConfigVo.java b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpClient/TcpClUnitConfigVo.java new file mode 100644 index 0000000..0cc19ba --- /dev/null +++ b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpClient/TcpClUnitConfigVo.java @@ -0,0 +1,7 @@ +package com.dy.testClient.tcpClient; + +public class TcpClUnitConfigVo { + public boolean enable ; + public int heartbeatTimes ; + public int sendInterval ; +} diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpConnect/LocalCodecFactory.java b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpConnect/LocalCodecFactory.java new file mode 100644 index 0000000..9f59b93 --- /dev/null +++ b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpConnect/LocalCodecFactory.java @@ -0,0 +1,35 @@ +package com.dy.testClient.tcpConnect; + +import org.apache.mina.filter.codec.ProtocolCodecFactory; +import org.apache.mina.filter.codec.ProtocolEncoder; +import org.apache.mina.filter.codec.ProtocolDecoder; +import org.apache.mina.core.session.IoSession; + +public class LocalCodecFactory implements ProtocolCodecFactory { + private ProtocolEncoder encoder; + private ProtocolDecoder decoder; + + public LocalCodecFactory() { + encoder = new LocalEncoder(); + decoder = new LocalDecoder(); + } + + /** + * 寰楀埌鍗忚缂栫爜鍣� + * @param ioSession 缃戠粶浼氳瘽 + * @return 鍗忚缂栫爜鍣� + */ + @Override + public ProtocolEncoder getEncoder(IoSession ioSession) { + return encoder; + } + /** + * 寰楀埌鍗忚瑙g爜鍣� + * @param ioSession 缃戠粶浼氳瘽 + * @return 鍗忚瑙g爜鍣� + */ + @Override + public ProtocolDecoder getDecoder(IoSession ioSession) { + return decoder; + } +} diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpConnect/LocalDecoder.java b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpConnect/LocalDecoder.java new file mode 100644 index 0000000..05aad53 --- /dev/null +++ b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpConnect/LocalDecoder.java @@ -0,0 +1,91 @@ +package com.dy.testClient.tcpConnect; +import java.io.*; + +import org.apache.mina.core.buffer.IoBuffer; +import org.apache.mina.core.session.IoSession; +import org.apache.mina.filter.codec.CumulativeProtocolDecoder; +import org.apache.mina.filter.codec.ProtocolDecoderOutput; + +import com.am.cs12.command.*; + +public class LocalDecoder extends CumulativeProtocolDecoder { + + private static final String DECODER_STATE_KEY = LocalDecoder.class.getName() + ".STATE"; + + public static final int MAX_SIZE = 2147483647 ; + + private class DecoderState { + Command com; + } + + /** + * 瀵圭綉缁滀紶杈撴潵鐨勬暟鎹繘琛岃В鐮� + */ + protected boolean doDecode(IoSession session, IoBuffer in, ProtocolDecoderOutput out) throws IOException, Exception{ + //浠庝細璇濅腑寰楀埌宸茬粡瑙g爜鐨勬暟鎹� + DecoderState decoderState = (DecoderState) session.getAttribute(DECODER_STATE_KEY); + if (decoderState == null) { + decoderState = new DecoderState(); + session.setAttribute(DECODER_STATE_KEY, decoderState); + } + if (decoderState.com == null) { + //璇曠潃璇诲彇鍛戒护鍖哄煙鏁版嵁 + //MAX_IMAGE_SIZE 鐩殑鏄槻姝㈠ぇ鏁版嵁閲忔敾鍑� + if (in.prefixedDataAvailable(4, MAX_SIZE)) { + decoderState.com = readCommand(in); + } else { + //鍛戒护鍖哄煙鏃犺冻澶熺殑鏁版嵁 + return false; + } + } + if (decoderState.com != null) { + //璇曠潃璇诲彇鏁版嵁(鏂囦欢)鍖哄煙鏁版嵁 + //MAX_IMAGE_SIZE 鐩殑鏄槻姝㈠ぇ鏁版嵁閲忔敾鍑� + if (in.prefixedDataAvailable(4, MAX_SIZE)) { + byte[] bs = getDataBytes(in); + MinaData minaCom = new MinaData() ; + minaCom.setCom(decoderState.com) ; + minaCom.setAttachment(bs) ; + out.write(minaCom); + + decoderState.com = null; + return true; + } else { + //鏁版嵁(鏂囦欢)鍖哄煙鏃犺冻澶熺殑鏁版嵁 + return false; + } + } + return false; + } + + /** + * 璇诲彇Command鍛戒护 + * @param in + * @return + * @throws IOException + */ + private Command readCommand(IoBuffer iob) throws IOException , Exception{ + int length = iob.getInt(); + byte[] bytes = new byte[length]; + iob.get(bytes); + Command com = new Command().toObject(bytes); + return com; + } + + /** + * 寰楀埌鏁版嵁鍩熸暟鎹殑瀛楄妭鏁扮粍 + * @param in + * @return + * @throws IOException + */ + private byte[] getDataBytes(IoBuffer iob) throws IOException { + int length = iob.getInt(); + if(length == 0){ + return null ; + } + byte[] bytes = new byte[length]; + iob.get(bytes); + return bytes ; + } + +} diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpConnect/LocalEncoder.java b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpConnect/LocalEncoder.java new file mode 100644 index 0000000..f895d68 --- /dev/null +++ b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpConnect/LocalEncoder.java @@ -0,0 +1,51 @@ +package com.dy.testClient.tcpConnect; + +import org.apache.mina.filter.codec.ProtocolEncoderOutput; +import org.apache.mina.filter.codec.ProtocolEncoderAdapter; +import org.apache.mina.core.buffer.IoBuffer; +import org.apache.mina.core.session.IoSession; + +import java.io.*; + +public class LocalEncoder extends ProtocolEncoderAdapter { + + /** + * 瀵规暟鎹繘琛岀紪鐮侊紝浠ュ缃戠粶浼犺緭 + */ + public void encode(IoSession session, Object message, ProtocolEncoderOutput out) throws IOException, Exception{ + MinaData minaData = null ; + if(message instanceof Command){ + minaData = new MinaData() ; + minaData.setCom((Command)message) ; + }else{ + minaData = (MinaData) message; + } + byte[] bytes1 = getCommandBytes(minaData.getCom()); + byte[] bytes2 = minaData.getAttachment() ; + int capacity = (bytes1==null?0:bytes1.length) + (bytes2==null?0:bytes2.length) + 8; + IoBuffer buffer = IoBuffer.allocate(capacity, false); + buffer.putInt(bytes1.length); + buffer.put(bytes1); + if(bytes2 == null){ + buffer.putInt(0); + }else{ + buffer.putInt(bytes2.length); + buffer.put(bytes2); + } + buffer.flip(); + out.write(buffer); + } + + /** + * 灏嗗懡浠よ浆鎹㈡垚瀛楄妭鏁扮粍 + * @param com + * @return + * @throws IOException + * @throws Exception + */ + private byte[] getCommandBytes(Command com) throws IOException, Exception { + String xml = com.toXml() ; + byte[] bytes = xml.getBytes() ; + return bytes ; + } +} diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpConnect/MinaConnect.java b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpConnect/MinaConnect.java new file mode 100644 index 0000000..2d85f19 --- /dev/null +++ b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpConnect/MinaConnect.java @@ -0,0 +1,55 @@ +package com.dy.testClient.tcpConnect; + +import org.apache.mina.core.future.ConnectFuture; +import org.apache.mina.core.session.IoSession; + +import org.apache.mina.filter.codec.ProtocolCodecFilter; +import org.apache.mina.transport.socket.SocketConnector; +import org.apache.mina.transport.socket.nio.NioSocketConnector; + +import java.net.InetSocketAddress; + +public class MinaConnect { + + /** + * 鍒ゆ柇浼氳瘽鏄惁鏈夋晥 + * @param se 缃戠粶浼氳瘽 + * @return 鏄惁杩炴帴 + */ + protected boolean isConnected(IoSession se) { + return (se != null && se.isConnected()); + } + + /** + * 鍒涘缓鏂颁細璇� + * @param host 鏈嶅姟鍣║RI + * @param port 鏈嶅姟鍣ㄧ鍙� + * @return 缃戠粶浼氳瘽 + */ + protected IoSession createSession(String host , int port , int connectTimeout , MinaHandler handler) throws Exception{ + SocketConnector connector = new NioSocketConnector(); + connector.getFilterChain().addLast("codec", new ProtocolCodecFilter(new LocalCodecFactory())); + connector.setHandler(handler); + ConnectFuture connectFuture = connector.connect(new InetSocketAddress(host, port)); + connectFuture.awaitUninterruptibly(connectTimeout); + IoSession se = connectFuture.getSession(); + return se ; + } + + + /** + * 鍏抽棴浼氳瘽鑱旀帴 + * @param se + * @param connectTimeout + */ + protected void disconnect(IoSession se , int connectTimeout) { + if (se != null) { + try{ + se.closeNow().awaitUninterruptibly(connectTimeout); + }catch(Exception e){ + }finally{ + se = null; + } + } + } +} diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpConnect/MinaConnectPool.java b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpConnect/MinaConnectPool.java new file mode 100644 index 0000000..0f3321f --- /dev/null +++ b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpConnect/MinaConnectPool.java @@ -0,0 +1,107 @@ +package com.dy.testClient.tcpConnect; + +import java.util.*; +import org.apache.mina.core.session.IoSession; + + +public class MinaConnectPool { + /** + * 绌洪棽浼氳瘽鐨勬睜(Hashtable鏄嚎绋嬪畨鍏ㄧ殑) + */ + private static Hashtable<String , Vector<IoSession>> freeSessions = new Hashtable<String ,Vector<IoSession>>(); + + /** + * 浠庝細璇濇睜涓緱鍒扮┖闂茬殑浼氳瘽锛屽鏋滄病鏈夌┖闂茬殑浼氳瘽锛屾湰鐫�蹇�熷弽搴旂殑鍘熷垯锛屾柊寤轰竴涓細璇濓紝涓嶅啀绛夊緟绻佸繖浼氳瘽鐨勯噴鏀� + * @param host + * @param port + * @return + * @throws Exception + */ + public static IoSession getSession(String host , int port , int connectTimeout) throws Exception{ + Vector<IoSession> vecter = freeSessions.get(getKey(host , port)) ; + if(vecter == null){ + vecter = new Vector<IoSession>() ; + freeSessions.put(getKey(host , port), vecter) ; + } + + MinaConnect con = new MinaConnect() ; + + IoSession se = popSession(vecter , con) ; + if(se == null){ + MinaHandler handler = new MinaHandler(connectTimeout) ; + se = createNewSession(host, port, connectTimeout, con, handler) ; + } + return se ; + } + + /** + * 灏嗕細璇濇斁鍥炴睜涓� + * @param host + * @param port + * @param se + */ + public static void freeSession(String host , int port , IoSession se){ + if(se == null){ + return ; + } + Vector<IoSession> vecter = freeSessions.get(getKey(host , port)) ; + if(vecter == null){ + vecter = new Vector<IoSession>() ; + freeSessions.put(getKey(host , port), vecter) ; + } + putSession(vecter, se) ; + } + + /** + * 浠庝細璇濇睜涓彇寰楃┖闂茬殑浼氳瘽 + * @param vecter + * @return + */ + private static IoSession popSession(Vector<IoSession> vecter , MinaConnect con){ + IoSession se = null ; + while(se == null && !vecter.isEmpty()){ + se = (IoSession)vecter.firstElement() ; + if(se != null){ + vecter.removeElementAt(0) ; + } + if(!con.isConnected(se)){ + se = null ; + } + } + return se ; + } + + /** + * 鏀炬柊浼氳瘽 + * @param vecter + * @param se + */ + private static void putSession(Vector<IoSession> vecter , IoSession se){ + vecter.addElement(se) ; + } + + /** + * 鍒涘缓鏂颁細璇� + * @param host + * @param port + * @param connectTimeout + * @param con + * @return + * @throws Exception + */ + private static IoSession createNewSession(String host , int port , int connectTimeout, MinaConnect con , MinaHandler handler) throws Exception{ + return con.createSession(host, port, connectTimeout , handler) ; + } + + /** + * 寰楀埌浼氳瘽姹犵殑key + * @param url + * @param port + * @return + */ + private static String getKey(String host , int port){ + return host + port ; + } + +} + diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpConnect/MinaHandler.java b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpConnect/MinaHandler.java new file mode 100644 index 0000000..8749cca --- /dev/null +++ b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpConnect/MinaHandler.java @@ -0,0 +1,94 @@ +package com.dy.testClient.tcpConnect; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.mina.core.service.IoHandlerAdapter; +import org.apache.mina.core.session.IdleStatus; +import org.apache.mina.core.session.IoSession; + +public class MinaHandler extends IoHandlerAdapter { + + private static Logger log = LogManager.getLogger(MinaHandler.class.getName()) ; + + private Object synObj ; + private int connectTimeout ; + private MinaData minaData ; + + public MinaHandler( int connectTimeout){ + this.connectTimeout = connectTimeout ; + this.synObj = new Object() ; + } + + /** + * 鍙戦�佸懡浠� + * @param session + * @param minaData + */ + public void sendCommand(IoSession session, MinaData minaData){ + session.write(minaData) ; + } + + /** + * 鍙栧緱鍛戒护缁撴灉 + * @param waitTimeout + */ + public MinaData getAnswer(int waitTimeout){ + synchronized (synObj) { + try { + synObj.wait(waitTimeout); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + return this.minaData; + } + + + + @Override + public void exceptionCaught(IoSession session, Throwable cause) throws Exception { + new MinaConnect().disconnect(session, this.connectTimeout) ; + log.error(cause.getMessage()) ; + } + + @Override + public void messageReceived(IoSession session, Object message) throws Exception { + this.minaData = (MinaData) message; + synchronized (synObj) { + if (synObj != null) { + synObj.notifyAll(); + } + } + } + + @Override + public void messageSent(IoSession session, Object message) throws Exception { + super.messageSent(session, message); + log.info("鍛戒护宸茬粡鍙戦�併��") ; + } + + @Override + public void sessionClosed(IoSession session) throws Exception { + super.sessionClosed(session); + log.info("缃戠粶浼氳瘽宸茬粡鍏抽棴銆�") ; + } + + @Override + public void sessionCreated(IoSession session) throws Exception { + super.sessionCreated(session); + log.info("缃戠粶浼氳瘽宸茬粡鍒涘缓銆�") ; + } + + @Override + public void sessionIdle(IoSession session, IdleStatus status) throws Exception { + super.sessionIdle(session, status); + } + + @Override + public void sessionOpened(IoSession session) throws Exception { + super.sessionOpened(session); + log.info("缃戠粶浼氳瘽宸茬粡鎵撳紑銆�") ; + } + + +} diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/resources/Config.xml b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/resources/Config.xml new file mode 100644 index 0000000..aec0502 --- /dev/null +++ b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/resources/Config.xml @@ -0,0 +1,48 @@ +<?xml version="1.0" encoding="UTF-8"?> +<config> + <server name="RTU娴嬭瘯瀹㈡埛绔�" showStartInfo="true" company="http://www.dyjs.com"/> + <!-- + 鏀寔妯″潡 + 鐭伐浣滄椂闀跨嚎绋嬫睜锛岀嚎绋嬭礋璐g敤鏃惰緝鐭殑宸ヤ綔浠诲姟 + short_maxThread锛� 姹犱腑鏈�澶х嚎绋嬫暟涓烘墍鏈塁PU鏍告暟+1锛坰hort姹犱笌long姹犲悇鍒嗕竴鍗婏級锛岃嫢涓�-1锛屼笉鍙楅檺鍒� 锛岃缃负0锛岃〃绀轰笉鍚姩绾跨▼姹� + short_minThread锛� 姹犱腑鏈�灏忕嚎绋嬫暟锛岃嫢涓�-1锛屼笉鍙楅檺鍒讹紝璁剧疆涓�0锛岃〃绀轰笉鍚姩绾跨▼姹� + short_freeTimeout锛� 绾跨▼鏁扮┖闂叉椂闀匡紝鑻ユ睜涓嚎绋嬫暟閲忓ぇ浜巑inThread锛屼笖鏈夌殑绾跨▼绌洪棽鏃堕暱瓒呰繃freeTimeout锛屽垯娓呴櫎璇ョ嚎绋嬶紝涓轰簡涓嶆竻闄わ紝鎶妋inThread涓巑axThread璁剧疆鐩哥瓑 + short_busyTimeout锛氱嚎绋嬩笉闂存柇宸ヤ綔鏃堕暱锛堝崟浣嶄负绉�)瓒呮椂闄愶紝璁や负绾跨▼宸茬粡浜嗗穿婧冿紝灏嗗己鍒舵竻闄わ紝鐭伐浣滄椂闀胯缃负5绉� + 闀垮伐浣滄椂闀跨嚎绋嬫睜锛岀嚎绋嬭礋璐g敤鏃惰緝闀跨殑宸ヤ綔浠诲姟锛屼緥濡傛暟鎹簱瀛樺彇鎿嶄綔 + long_maxThread锛� 姹犱腑鏈�澶х嚎绋嬫暟涓烘墍鏈塁PU鏍告暟+1锛坰hort姹犱笌long姹犲悇鍒嗕竴鍗婏級锛岃嫢涓�-1锛屼笉鍙楅檺鍒讹紝璁剧疆涓�0锛岃〃绀轰笉鍚姩绾跨▼姹� + long_minThread锛� 姹犱腑鏈�灏忕嚎绋嬫暟锛岃嫢涓�-1锛屼笉鍙楅檺鍒讹紝璁剧疆涓�0锛岃〃绀轰笉鍚姩绾跨▼姹� + long_freeTimeout锛� 绾跨▼鏁扮┖闂叉椂闀匡紝鑻ユ睜涓嚎绋嬫暟閲忓ぇ浜巑inThread锛屼笖鏈夌殑绾跨▼绌洪棽鏃堕暱瓒呰繃freeTimeout锛屽垯娓呴櫎璇ョ嚎绋� + long_busyTimeout锛氱嚎绋嬩笉闂存柇宸ヤ綔鏃堕暱锛堝崟浣嶄负绉�)瓒呮椂闄愶紝鑻ヤ负-1锛屼笉鍙楅檺鍒� + enableThreadPool锛氭槸鍚﹀惎鐢ㄧ嚎绋嬫睜 + --> + <!-- 褰撳墠瀹炵幇锛屽啓rtu鏃ュ織銆丷MI鏁版嵁澶勭悊鐢ㄥ埌浜嗙煭绾跨▼姹� --> + <!-- 褰撳墠瀹炵幇锛宺tu涓婅鏁版嵁澶勭悊锛堣鍐欐暟鎹級鐢ㄥ埌浜嗙绾跨▼姹� --> + <support + short_maxThread="0" + short_minThread="0" + short_freeTimeout="60" + short_busyTimeout="5" + long_maxThread="13" + long_minThread="13" + long_freeTimeout="60" + long_busyTimeout="-1" + /> + <!-- + rmi瀹㈡埛绔� + --> + <rmiCl + rmiSvUrl="127.0.0.1" + rmiSvContext="mwTestServer" + rmiSvPort="9898" + /> + <!-- + enable:鏄惁鍚姩 + heartbeatTimes:杩炵画閰嶇疆娆℃暟蹇冭烦鍚庡彂閫佷竴娆℃暟鎹� + sendInterval:鍙戦�佸績璺虫垨鏁版嵁鐨勬椂闂撮棿闅� + --> + <tcpCl + enable="true" + heartbeatTimes="3" + sendInterval="3" + /> +</config> \ No newline at end of file diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/resources/application.yml b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/resources/application.yml new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/resources/application.yml @@ -0,0 +1 @@ + diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/resources/log4j2.yml b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/resources/log4j2.yml new file mode 100644 index 0000000..375972f --- /dev/null +++ b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/resources/log4j2.yml @@ -0,0 +1,64 @@ +Configuration: + #status锛岃繖涓敤浜庤缃甽og4j2鑷韩鍐呴儴鐨勪俊鎭緭鍑猴紝鍙互涓嶈缃紝褰撹缃垚trace鏃讹紝浣犱細鐪嬪埌log4j2鍐呴儴鍚勭璇︾粏杈撳嚭锛涘彲浠ヨ缃垚Off(鍏抽棴)鎴朎rror(鍙緭鍑洪敊璇俊鎭�) + status: Error + + Properties: # 瀹氫箟鍏ㄥ眬鍙橀噺 + Property: + #鏃ュ織鏂囦欢瀛樺偍鐨勭洰褰� + - name: log.path + value: ./logs + #鏃ュ織鏂囦欢瀛樺偍鍚嶇О + - name: project.name + value: mwTestClient + + #瀹氫箟杈撳嚭鍣紝鍙互杈撳嚭鍒版帶鍒跺彴鍜屾枃浠�. + Appenders: + #杈撳嚭鍒版帶鍒跺彴 + Console: + #Appender鍛藉悕 + name: CONSOLE + target: SYSTEM_OUT + ThresholdFilter: + level: debug #杈撳嚭鏃ュ織绾у埆锛岃緭鍑烘棩蹇楁椂锛岄鍏堢敱Loggers.Root.level鎴朙oggers.Logger.level鍒ゆ柇鏄惁杈撳嚭锛岀劧鍚庡啀鐢辨湰level鍒ゆ柇鏄惁杈撳嚭 + onMatch: ACCEPT #onMatch=ACCEPT 澶т簬绛変簬 "level" 閰嶇疆鐨勭瓑绾у湴鏃ュ織杈撳嚭 + onMismatch: DENY #onMismatch=DENY 灏忎簬 "level" 閰嶇疆鐨勭瓑绾у湴鏃ュ織涓嶈緭鍑� + #鏃ュ織鍐呭鏍峰紡 + PatternLayout: + #%n-鎹㈣ + #%m-鏃ュ織鍐呭锛岃緭鍑轰唬鐮佷腑鎸囧畾鐨勬棩蹇椾俊鎭� + #%p-杈撳嚭浼樺厛绾э紝鍗矰EBUG,INFO,WARN,ERROR,FATAL + #%r-绋嬪簭鍚姩鍒扮幇鍦ㄧ殑姣鏁� + #%%- 杈撳嚭涓�涓�"%" 瀛楃 + #%t-褰撳墠绾跨▼鍚� + #%d-鏃ユ湡鍜屾椂闂�, 甯哥敤鐨勬牸寮忔湁%d{DATE},%d{ABSOLUTE},%d{HH:mm:ss,SSS},%d{ddMMyyyyHH:mm:ss,SSS} + #%l-鍚�%F%L%C%M + #%F-java婧愭枃浠跺悕 + #%L-java婧愮爜琛屾暟 + #%C-java绫诲悕,%C{1}杈撳嚭鏈�鍚庝竴涓厓绱� + #%M-java鏂规硶鍚� + pattern: "%d{yyyy-MM-dd HH:mm:ss,SSS}:%4p %t (%C.%M:%L) - %m%n" + # 杈撳嚭鍒版枃浠讹紝瓒呰繃10MB褰掓。 + RollingFile: + - name: ROLLING_FILE + ignoreExceptions: false + fileName: ${log.path}/${project.name}.log + filePattern: "${log.path}/$${date:yyyy-MM}/${project.name}-%d{yyyy-MM-dd}-%i.log.gz" + ThresholdFilter: + level: error #杈撳嚭鏃ュ織绾у埆锛岃緭鍑烘棩蹇楁椂锛岄鍏堢敱Loggers.Root.level鎴朙oggers.Logger.level鍒ゆ柇鏄惁杈撳嚭锛岀劧鍚庡啀鐢辨湰level鍒ゆ柇鏄惁杈撳嚭 + onMatch: ACCEPT #onMatch=ACCEPT 澶т簬绛変簬 "level" 閰嶇疆鐨勭瓑绾у湴鏃ュ織杈撳嚭 + onMismatch: DENY #onMismatch=DENY 灏忎簬 "level" 閰嶇疆鐨勭瓑绾у湴鏃ュ織涓嶈緭鍑� + #鏃ュ織鍐呭鏍峰紡 + PatternLayout: + pattern: "%d{yyyy-MM-dd HH:mm:ss,SSS}:%4p %t (%C.%M:%L) - %m%n" + Policies: + SizeBasedTriggeringPolicy: + size: "10 MB" + DefaultRolloverStrategy: + max: 1000 + + Loggers: + Root: + level: info #鏃ュ織杈撳嚭绾у埆锛屽叡鏈�8涓骇鍒紝鎸夌収浠庝綆鍒伴珮涓猴細all < trace < debug < info < warn < error < fatal < off + AppenderRef: #Root鐨勫瓙鑺傜偣锛岀敤鏉ユ寚瀹氳鏃ュ織杈撳嚭鍒板摢涓狝ppender. + - ref: CONSOLE #杈撳嚭鏃ュ織鏃讹紝棣栧厛鐢辨湰level鍒ゆ柇鏄惁杈撳嚭锛岀劧鍚庡啀鐢变笂闈㈢殑Appenders.Console.ThresholdFilter.level鍒ゆ柇鏄惁杈撳嚭 + - ref: ROLLING_FILE #杈撳嚭鏃ュ織鏃讹紝棣栧厛鐢辨湰level鍒ゆ柇鏄惁杈撳嚭锛岀劧鍚庡啀鐢变笂闈㈢殑Appenders.RollingFile.ThresholdFilter.level鍒ゆ柇鏄惁杈撳嚭 -- Gitblit v1.8.0