Merge branch 'master' of http://8.140.179.55:20000/r/pipIrr-SV
Conflicts:
pipIrr-platform/pipIrr-mw/pipIrr-mwTest-server/src/main/java/com/dy/testServer/forRmi/RmiResponseVo.java
pipIrr-platform/pipIrr-mw/pom.xml
| | |
| | | target/ |
| | | /pipIrr-platform.iml |
| | | /ææ¡£/~$pIrræ¥å£.docx |
| | |
| | | package com.dy.pipIrrGlobal.util; |
| | | |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.baomidou.mybatisplus.annotation.EnumValue; |
| | | import com.dy.common.mybatis.envm.IEnum; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | |
| | | } |
| | | |
| | | //ç¨æ¥è½¬json |
| | | public static Map<Byte, DistrictLevel> ObjMap = new HashMap<Byte, DistrictLevel>(); |
| | | public static List<Map> LevelList = new ArrayList<>(); |
| | | static { |
| | | DistrictLevel[] all = DistrictLevel.values(); |
| | | for (DistrictLevel one : all) { |
| | | ObjMap.put(one.code, one); |
| | | Map<String, Object> objMap = new HashMap<>(); |
| | | objMap.put("code", one.code); |
| | | objMap.put("name", one.name); |
| | | LevelList.add(objMap) ; |
| | | } |
| | | } |
| | | |
| | |
| | | import com.alibaba.fastjson2.annotation.JSONField; |
| | | import com.baomidou.mybatisplus.annotation.EnumValue; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | public enum Org { |
| | |
| | | this.name = name ; |
| | | } |
| | | //ç¨æ¥è½¬json |
| | | public static Map<String, Org> ObjMap = new HashMap<String, Org>(); |
| | | public static List<Map> OrgList = new ArrayList<>(); |
| | | static { |
| | | Org[] all = Org.values(); |
| | | for (Org one : all) { |
| | | ObjMap.put(one.tag, one); |
| | | Map<String, String> objMap = new HashMap<>(); |
| | | objMap.put("tag", one.tag); |
| | | objMap.put("name", one.name); |
| | | OrgList.add(objMap) ; |
| | | } |
| | | } |
| | | |
New file |
| | |
| | | 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/ |
New file |
| | |
| | | <?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> |
| | | <!-- çæçjarä¸ï¼ä¸è¦å
å«pom.xmlåpom.propertiesè¿ä¸¤ä¸ªæä»¶ --> |
| | | <addMavenDescriptor>false</addMavenDescriptor> |
| | | <!-- è¿é¨å坿坿 ,å ä¸çè¯åç´æ¥çæå¯è¿è¡jarå
--> |
| | | <manifest> |
| | | <mainClass>com.dy.testClient.Server</mainClass> |
| | | <useUniqueVersions>false</useUniqueVersions> |
| | | <addClasspath>true</addClasspath> |
| | | <classpathPrefix>lib/</classpathPrefix> |
| | | </manifest> |
| | | <!-- manifestEntriesçä½ç¨æ¯æå®æ¬å°ï¼èªå·±ä¸è½½çlibä¸çï¼jarå
æ·»å å°MANIFEST.MFæä»¶ä¸å» |
| | | <manifestEntries> |
| | | <Class-Path>.lib/alipay-sdk.java.jar</Class-Path> |
| | | </manifestEntries> |
| | | --> |
| | | </archive> |
| | | <!-- æé¤æä¸ªæä»¶ |
| | | <excludes> |
| | | <exclude>com/dy/App.class</exclude> |
| | | </excludes> |
| | | --> |
| | | <!-- 坿§è¡jarè¿è¡å½åãè¿æ ·ä¼æå
æä¸¤ä¸ªjarå
ï¼ä¸ä¼å¯¹æ®éjaréæ°å½åã |
| | | <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ï¼ ç®æ å¹³å°ç¼è¯çæ¬ï¼encodingï¼ å符éç¼ç ã --> |
| | | <configuration> |
| | | <source>${java.version}</source> |
| | | <target>${java.version}</target> |
| | | <encoding>${encoding}</encoding> |
| | | </configuration> |
| | | </plugin> |
| | | <plugin> |
| | | <!-- è§£å³èµæºæä»¶çç¼ç é®é¢ --> |
| | | <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> |
New file |
| | |
| | | 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 ; |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | 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 ; |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | 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; |
| | | } |
| | | |
| | | |
| | | } |
New file |
| | |
| | | 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("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 &@@@@@@@@") ; |
| | | |
| | | }catch(Exception e){ |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | private void startUnits(){ |
| | | try { |
| | | //////////////////////////////////////////////////////// |
| | | //æ¯ææ¨¡åï¼ springHibernateå çº¿ç¨æ± |
| | | SupportUnitConfigVo supVo = new SupportUnitConfigVo() ; |
| | | //ç工使¶é¿çº¿ç¨æ± ï¼çº¿ç¨è´è´£ç¨æ¶è¾ççå·¥ä½ä»»å¡ |
| | | supVo.short_maxThread = conf.getSetAttrPlusInt(doc, "config.support", "short_maxThread", null, 1, 1000, null) ;//æ± ä¸æå¤§çº¿ç¨æ°ä¸ºææCPUæ ¸æ°+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 ;//çº¿ç¨æ°ç©ºé²æ¶é¿ï¼è¥æ± ä¸çº¿ç¨æ°é大äºminThreadï¼ä¸æç线ç¨ç©ºé²æ¶é¿è¶
è¿freeTimeoutï¼åæ¸
é¤è¯¥çº¿ç¨ï¼ä¸ºäºä¸æ¸
é¤ï¼æminThreadä¸maxThread设置ç¸ç |
| | | supVo.short_busyTimeout = conf.getSetAttrPlusInt(doc, "config.support", "short_busyTimeout", null, 1, 10, null) * 1000 ;//线ç¨ä¸é´æå·¥ä½æ¶é¿ï¼åä½ä¸ºç§)è¶
æ¶éï¼è®¤ä¸ºçº¿ç¨å·²ç»äºå´©æºï¼å°å¼ºå¶æ¸
é¤ï¼ç工使¶é¿è®¾ç½®ä¸º5ç§ |
| | | //é¿å·¥ä½æ¶é¿çº¿ç¨æ± ï¼çº¿ç¨è´è´£ç¨æ¶è¾é¿çå·¥ä½ä»»å¡ |
| | | 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 ;//çº¿ç¨æ°ç©ºé²æ¶é¿ï¼è¥æ± ä¸çº¿ç¨æ°é大äºminThreadï¼ä¸æç线ç¨ç©ºé²æ¶é¿è¶
è¿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(); |
| | | } |
| | | } |
| | | } |
| | | |
New file |
| | |
| | | package com.dy.testClient; |
| | | |
| | | public class ServerProperties { |
| | | |
| | | //RTUå¼å§å°å |
| | | public static Long rtuAddrStart = 0L ; |
| | | //RTUæªæ¢å°å |
| | | public static Long rtuAddrEnd = 0L ; |
| | | //æå¡ç«¯IP |
| | | public static String serverIp = "" ; |
| | | //æå¡ç«¯ä¸ä¸æ |
| | | public static Integer serverPort = 0 ; |
| | | //åéæ°æ®æ¬¡æ° |
| | | public static Integer sendTimes = 0 ; |
| | | |
| | | //mwTestServeræ§å¶æ¯å¦å¯å¨ |
| | | public static boolean startWork = false ; |
| | | } |
New file |
| | |
| | | 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 + "æ¡æ°æ®"); |
| | | } |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.dy.testClient.httpCl; |
| | | |
| | | import com.dy.common.mw.UnitAdapterInterface; |
| | | |
| | | public interface HttpClUnitAdapter extends UnitAdapterInterface { |
| | | |
| | | public HttpClUnitConfigVo getConfig() ; |
| | | |
| | | } |
New file |
| | |
| | | package com.dy.testClient.httpCl; |
| | | |
| | | public class HttpClUnitConfigVo { |
| | | public boolean enable ; |
| | | } |
New file |
| | |
| | | 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) ; |
| | | } |
| | | } |
New file |
| | |
| | | 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; |
| | | } |
| | | |
| | | |
| | | } |
New file |
| | |
| | | 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 |
| | | */ |
| | | |
| | | } |
New file |
| | |
| | | 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 ; |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | 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); |
| | | |
| | | } |
| | | } |
New file |
| | |
| | | package com.dy.testClient.httpCl; |
| | | |
| | | public class UpDataPayloadVo { |
| | | |
| | | public String APPdata ; |
| | | |
| | | |
| | | public String getAPPdata() { |
| | | return APPdata; |
| | | } |
| | | |
| | | public void setAPPdata(String aPPdata) { |
| | | APPdata = aPPdata; |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | 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; |
| | | } |
| | | |
| | | |
| | | } |
New file |
| | |
| | | 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" ;//åæå¡ç«¯ä¸æ¥ æ°æ®ä¸æ¥å·¥ä½å·²ç»å®æ |
| | | |
| | | } |
New file |
| | |
| | | package com.dy.testClient.rmiClient; |
| | | |
| | | import com.alibaba.fastjson2.JSON; |
| | | |
| | | public class ResConfigVo { |
| | | //模æå®¢æ·çRtuAddrèµ·å§å· |
| | | public Long rtuAddrStart = 0L ; |
| | | //模æå®¢æ·çIMEIå·æªæ¢å· |
| | | public Long rtuAddrEnd = 0L ; |
| | | //æå¡ç«¯IP |
| | | 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; |
| | | } |
| | | } |
New file |
| | |
| | | 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; |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | 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; |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | 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() ;//èªå·±çid |
| | | |
| | | public static String token ;//æå¡ç«¯åçtoken |
| | | |
| | | 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() ; |
| | | } |
| | | |
| | | //æä¸æ¥æ°æ®çæ°é䏿¥ç»mwTestServer |
| | | 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("æä¸æ¥æ°æ®çæ°é䏿¥ç»mwTestServer失败" + e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | //ææ°æ®ä¸æ¥å®ææ
åµ ä¸æ¥ç»mwTestServer |
| | | 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("ææ°æ®ä¸æ¥å®ææ
åµ ä¸æ¥ç»mwTestServer失败" + e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | //åmwTestServer注å |
| | | 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("注åæåï¼å¾å°token=" + token); |
| | | break ; |
| | | }else{ |
| | | log.error("rmi注åå¤±è´¥ï¼æå¡ç«¯è¿åResRegisterVo为null"); |
| | | error = true ; |
| | | } |
| | | }else{ |
| | | log.error("rmi注åå¤±è´¥ï¼æå¡ç«¯è¿åé误ï¼" + rspVo.errorInfo); |
| | | error = true ; |
| | | } |
| | | }else{ |
| | | log.error("rmi注åå¤±è´¥ï¼æå¡ç«¯è¿åçRmiResponseVo为null"); |
| | | error = true ; |
| | | } |
| | | }else{ |
| | | log.error("rmi注åå¤±è´¥ï¼æå¡ç«¯è¿åjson为null"); |
| | | error = true ; |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("rmi注å失败" + e.getMessage()); |
| | | error = true ; |
| | | continue ; |
| | | } |
| | | } |
| | | if(!error){ |
| | | getConfig(frmWork) ; |
| | | } |
| | | } |
| | | |
| | | //ä»mwTestServerå¾å°é
ç½® |
| | | 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(" å¼å§RtuAddr=" + ServerProperties.rtuAddrStart); |
| | | log.info(" æªæ¢RtuAddr=" + ServerProperties.rtuAddrEnd); |
| | | log.info(" mwAcceptæå¡IP=" + ServerProperties.serverIp); |
| | | log.info(" mwAcceptæå¡ç«¯å£=" + ServerProperties.serverPort); |
| | | log.info(" æ¯imei䏿¥æ°æ®æ¬¡æ°=" + ServerProperties.sendTimes); |
| | | break ; |
| | | }else{ |
| | | log.error("rmiå¾å°é
置失败ï¼json转ResConfigVo为null"); |
| | | error = true ; |
| | | } |
| | | }else{ |
| | | log.error("rmiå¾å°é
ç½®å¤±è´¥ï¼æå¡ç«¯è¿åResConfigVo为null"); |
| | | error = true ; |
| | | } |
| | | }else{ |
| | | log.error("rmiå¾å°é
ç½®å¤±è´¥ï¼æå¡ç«¯è¿åé误ï¼" + rspVo.errorInfo); |
| | | error = true ; |
| | | } |
| | | }else{ |
| | | log.error("rmiå¾å°é
ç½®å¤±è´¥ï¼æå¡ç«¯è¿åçRmiResponseVo为null"); |
| | | error = true ; |
| | | } |
| | | }else{ |
| | | log.error("rmiå¾å°é
ç½®å¤±è´¥ï¼æå¡ç«¯è¿åjson为null"); |
| | | error = true ; |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("rmiå¾å°é
置失败" + e.getMessage()); |
| | | error = true ; |
| | | continue ; |
| | | } |
| | | } |
| | | if(!error){ |
| | | getStart(frmWork) ; |
| | | } |
| | | } |
| | | |
| | | //ä»mwTestServerå¾å°å¼å§ä¸æ¥æ°æ®ç请å
许 |
| | | 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请æ±å¯å¨å¤±è´¥ï¼json转ResStartVo为null"); |
| | | } |
| | | }else{ |
| | | log.error("rmi请æ±å¯å¨å¤±è´¥ï¼æå¡ç«¯è¿åResStartVo为null"); |
| | | } |
| | | }else{ |
| | | log.error("rmi请æ±å¯å¨å¤±è´¥ï¼æå¡ç«¯è¿åé误ï¼" + rspVo.errorInfo); |
| | | } |
| | | }else{ |
| | | log.error("rmi请æ±å¯å¨å¤±è´¥ï¼æå¡ç«¯è¿åçRmiResponseVo为null"); |
| | | } |
| | | }else{ |
| | | log.error("rmi请æ±å¯å¨å¤±è´¥ï¼æå¡ç«¯è¿åjson为null"); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("rmi请æ±å¯å¨å¤±è´¥" + e.getMessage()); |
| | | continue ; |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.dy.testClient.rmiClient; |
| | | |
| | | import com.dy.common.mw.UnitAdapterInterface; |
| | | |
| | | public interface RmiClUnitAdapter extends UnitAdapterInterface { |
| | | |
| | | public RmiClUnitConfigVo getConfig() ; |
| | | |
| | | } |
| | | |
New file |
| | |
| | | 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; |
| | | } |
| | | |
| | | |
| | | } |
New file |
| | |
| | | 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 ; |
| | | } |
| | | |
| | | /** |
| | | * å¾å°ä¸é´ä»¶RMI |
| | | * @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; |
| | | } |
| | | } |
| | | } |
New file |
| | |
| | | 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; |
| | | } |
| | | } |
New file |
| | |
| | | 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; |
| | | } |
| | | } |
New file |
| | |
| | | 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; |
| | | } |
| | | |
| | | |
| | | } |
New file |
| | |
| | | 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 + "æ¡æ°æ®"); |
| | | } |
| | | } |
| | | } |
New file |
| | |
| | | package com.dy.testClient.tcpClient; |
| | | |
| | | import com.dy.common.mw.UnitAdapterInterface; |
| | | |
| | | public interface TcpClUnitAdapter extends UnitAdapterInterface { |
| | | public TcpClUnitConfigVo getConfig() ; |
| | | } |
New file |
| | |
| | | package com.dy.testClient.tcpClient; |
| | | |
| | | public class TcpClUnitConfigVo { |
| | | public boolean enable ; |
| | | public int heartbeatTimes ; |
| | | public int sendInterval ; |
| | | } |
New file |
| | |
| | | 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; |
| | | } |
| | | /** |
| | | * å¾å°å议解ç å¨ |
| | | * @param ioSession ç½ç»ä¼è¯ |
| | | * @return å议解ç å¨ |
| | | */ |
| | | @Override |
| | | public ProtocolDecoder getDecoder(IoSession ioSession) { |
| | | return decoder; |
| | | } |
| | | } |
New file |
| | |
| | | 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{ |
| | | //ä»ä¼è¯ä¸å¾å°å·²ç»è§£ç çæ°æ® |
| | | 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 ; |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | 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 ; |
| | | } |
| | | } |
New file |
| | |
| | | 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 æå¡å¨URI |
| | | * @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; |
| | | } |
| | | } |
| | | } |
| | | } |
New file |
| | |
| | | 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 ; |
| | | } |
| | | |
| | | } |
| | | |
New file |
| | |
| | | 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("ç½ç»ä¼è¯å·²ç»æå¼ã") ; |
| | | } |
| | | |
| | | |
| | | } |
New file |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <config> |
| | | <server name="RTUæµè¯å®¢æ·ç«¯" showStartInfo="true" company="http://www.dyjs.com"/> |
| | | <!-- |
| | | æ¯ææ¨¡å |
| | | ç工使¶é¿çº¿ç¨æ± ï¼çº¿ç¨è´è´£ç¨æ¶è¾ççå·¥ä½ä»»å¡ |
| | | short_maxThreadï¼ æ± ä¸æå¤§çº¿ç¨æ°ä¸ºææCPUæ ¸æ°+1ï¼shortæ± ä¸longæ± ååä¸åï¼ï¼è¥ä¸º-1ï¼ä¸åéå¶ ï¼è®¾ç½®ä¸º0ï¼è¡¨ç¤ºä¸å¯å¨çº¿ç¨æ± |
| | | short_minThreadï¼ æ± ä¸æå°çº¿ç¨æ°ï¼è¥ä¸º-1ï¼ä¸åéå¶ï¼è®¾ç½®ä¸º0ï¼è¡¨ç¤ºä¸å¯å¨çº¿ç¨æ± |
| | | short_freeTimeoutï¼ çº¿ç¨æ°ç©ºé²æ¶é¿ï¼è¥æ± ä¸çº¿ç¨æ°é大äºminThreadï¼ä¸æç线ç¨ç©ºé²æ¶é¿è¶
è¿freeTimeoutï¼åæ¸
é¤è¯¥çº¿ç¨ï¼ä¸ºäºä¸æ¸
é¤ï¼æminThreadä¸maxThread设置ç¸ç |
| | | short_busyTimeoutï¼çº¿ç¨ä¸é´æå·¥ä½æ¶é¿ï¼åä½ä¸ºç§)è¶
æ¶éï¼è®¤ä¸ºçº¿ç¨å·²ç»äºå´©æºï¼å°å¼ºå¶æ¸
é¤ï¼ç工使¶é¿è®¾ç½®ä¸º5ç§ |
| | | é¿å·¥ä½æ¶é¿çº¿ç¨æ± ï¼çº¿ç¨è´è´£ç¨æ¶è¾é¿çå·¥ä½ä»»å¡ï¼ä¾å¦æ°æ®åºååæä½ |
| | | long_maxThreadï¼ æ± ä¸æå¤§çº¿ç¨æ°ä¸ºææCPUæ ¸æ°+1ï¼shortæ± ä¸longæ± ååä¸åï¼ï¼è¥ä¸º-1ï¼ä¸åéå¶ï¼è®¾ç½®ä¸º0ï¼è¡¨ç¤ºä¸å¯å¨çº¿ç¨æ± |
| | | long_minThreadï¼ æ± ä¸æå°çº¿ç¨æ°ï¼è¥ä¸º-1ï¼ä¸åéå¶ï¼è®¾ç½®ä¸º0ï¼è¡¨ç¤ºä¸å¯å¨çº¿ç¨æ± |
| | | long_freeTimeoutï¼ çº¿ç¨æ°ç©ºé²æ¶é¿ï¼è¥æ± ä¸çº¿ç¨æ°é大äºminThreadï¼ä¸æç线ç¨ç©ºé²æ¶é¿è¶
è¿freeTimeoutï¼åæ¸
é¤è¯¥çº¿ç¨ |
| | | long_busyTimeoutï¼çº¿ç¨ä¸é´æå·¥ä½æ¶é¿ï¼åä½ä¸ºç§)è¶
æ¶éï¼è¥ä¸º-1ï¼ä¸åéå¶ |
| | | enableThreadPoolï¼æ¯å¦å¯ç¨çº¿ç¨æ± |
| | | --> |
| | | <!-- å½åå®ç°ï¼årtuæ¥å¿ãRMIæ°æ®å¤çç¨å°äºççº¿ç¨æ± --> |
| | | <!-- å½åå®ç°ï¼rtuä¸è¡æ°æ®å¤çï¼è¯»åæ°æ®ï¼ç¨å°äºç¬¬çº¿ç¨æ± --> |
| | | <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> |
New file |
| | |
| | | Configuration: |
| | | #statusï¼è¿ä¸ªç¨äºè®¾ç½®log4j2èªèº«å
é¨çä¿¡æ¯è¾åºï¼å¯ä»¥ä¸è®¾ç½®ï¼å½è®¾ç½®ætraceæ¶ï¼ä½ ä¼çå°log4j2å
é¨åç§è¯¦ç»è¾åºï¼å¯ä»¥è®¾ç½®æOff(å
³é)æError(åªè¾åºé误信æ¯) |
| | | 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æLoggers.Logger.level夿æ¯å¦è¾åºï¼ç¶ååç±æ¬level夿æ¯å¦è¾åº |
| | | onMatch: ACCEPT #onMatch=ACCEPT 大äºçäº "level" é
ç½®çççº§å°æ¥å¿è¾åº |
| | | onMismatch: DENY #onMismatch=DENY å°äº "level" é
ç½®çççº§å°æ¥å¿ä¸è¾åº |
| | | #æ¥å¿å
å®¹æ ·å¼ |
| | | PatternLayout: |
| | | #%n-æ¢è¡ |
| | | #%m-æ¥å¿å
容ï¼è¾åºä»£ç 䏿å®çæ¥å¿ä¿¡æ¯ |
| | | #%p-è¾åºä¼å
级ï¼å³DEBUG,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æLoggers.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çåèç¹ï¼ç¨æ¥æå®è¯¥æ¥å¿è¾åºå°åªä¸ªAppender. |
| | | - ref: CONSOLE #è¾åºæ¥å¿æ¶ï¼é¦å
ç±æ¬level夿æ¯å¦è¾åºï¼ç¶ååç±ä¸é¢çAppenders.Console.ThresholdFilter.level夿æ¯å¦è¾åº |
| | | - ref: ROLLING_FILE #è¾åºæ¥å¿æ¶ï¼é¦å
ç±æ¬level夿æ¯å¦è¾åºï¼ç¶ååç±ä¸é¢çAppenders.RollingFile.ThresholdFilter.level夿æ¯å¦è¾åº |
New file |
| | |
| | | package com.dy.testServer.forRmi; |
| | | |
| | | 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 |
| | | * @param clazz |
| | | * @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<>() ; |
| | | //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; |
| | | } |
| | | } |
| | |
| | | |
| | | <modules> |
| | | <module>pipIrr-mw-accept</module> |
| | | <module>pipIrr-mwTest-server</module> |
| | | <module>pipIrr-mwTest-client</module> |
| | | </modules> |
| | | |
| | | <dependencies> |
| | |
| | | <groupId>com.dy</groupId> |
| | | <artifactId>pipIrr-common</artifactId> |
| | | <version>1.0.0</version> |
| | | <scope>provided</scope> |
| | | <optional>true</optional> |
| | | <exclusions> |
| | | <exclusion> |
| | | <!-- æé¤æpipIrr-commonçææä¾èµï¼æ¬æ¨¡åèªå·±å®ä¹ä¾èµ --> |
| | | <groupId>*</groupId> |
| | | <artifactId>*</artifactId> |
| | | </exclusion> |
| | | </exclusions> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>com.dy</groupId> |
| | | <artifactId>pipIrr-global</artifactId> |
| | | <version>1.0.0</version> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>org.springframework.boot</groupId> |
| | | <artifactId>spring-boot-starter-web</artifactId> |
| | | <scope>provided</scope> |
| | | <optional>true</optional> |
| | | <exclusions> |
| | | <exclusion> |
| | | <groupId>org.springframework.boot</groupId> |
| | | <artifactId>spring-boot-starter-json</artifactId> |
| | | </exclusion> |
| | | <exclusion> |
| | | <groupId>org.springframework.boot</groupId> |
| | | <artifactId>spring-boot-starter-logging</artifactId> |
| | | <!-- æé¤æpipIrr-commonçææä¾èµï¼æ¬æ¨¡åèªå·±å®ä¹ä¾èµ --> |
| | | <groupId>*</groupId> |
| | | <artifactId>*</artifactId> |
| | | </exclusion> |
| | | </exclusions> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>org.springframework.boot</groupId> |
| | | <artifactId>spring-boot-devtools</artifactId> |
| | | <scope>runtime</scope> |
| | | </dependency> |
| | | |
| | | <!-- lombok --> |
| | | <dependency> |
| | | <groupId>org.projectlombok</groupId> |
| | | <artifactId>lombok</artifactId> |
| | | </dependency> |
| | | <!-- @Aspect @Pointcut @Aroundçåºç¨ --> |
| | | <dependency> |
| | | <groupId>org.aspectj</groupId> |
| | | <artifactId>aspectjweaver</artifactId> |
| | | </dependency> |
| | | <!--log4j2æ¥å¿--> |
| | | <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-log4j2</artifactId> |
| | |
| | | <dependency> |
| | | <groupId>com.fasterxml.jackson.dataformat</groupId> |
| | | <artifactId>jackson-dataformat-yaml</artifactId> |
| | | </dependency> |
| | | |
| | | <!-- ç³»ç»ç管 --> |
| | | <dependency> |
| | | <groupId>org.springframework.boot</groupId> |
| | | <artifactId>spring-boot-starter-actuator</artifactId> |
| | | </dependency> |
| | | |
| | | <!-- apiå¨çº¿ææ¡£ https://springdoc.org/#modules--> |
| | | <dependency> |
| | | <groupId>org.springdoc</groupId> |
| | | <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>org.springdoc</groupId> |
| | | <artifactId>springdoc-openapi-starter-webmvc-api</artifactId> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>org.springdoc</groupId> |
| | | <artifactId>springdoc-openapi-security</artifactId> |
| | | </dependency> |
| | | |
| | | |
| | | <!--mysql驱å¨--> |
| | | <dependency> |
| | | <groupId>com.mysql</groupId> |
| | | <artifactId>mysql-connector-j</artifactId> |
| | | <version>8.0.33</version> |
| | | </dependency> |
| | | <!--druid-spring-bootè¿æ¥æ± --> |
| | | <dependency> |
| | | <groupId>com.alibaba</groupId> |
| | | <artifactId>druid-spring-boot-starter</artifactId> |
| | | <version>1.2.20</version> |
| | | </dependency> |
| | | <!--mybatis-plus-spring-boot--> |
| | | <dependency> |
| | | <groupId>com.baomidou</groupId> |
| | | <artifactId>mybatis-plus-boot-starter</artifactId> |
| | | <version>3.5.3.2</version> |
| | | <exclusions> |
| | | <exclusion> |
| | | <!-- æé¤æä¾èµ --> |
| | | <groupId>com.fasterxml.jackson.core</groupId> |
| | | <artifactId>jackson-databind</artifactId> |
| | | </exclusion> |
| | | </exclusions> |
| | | </dependency> |
| | | |
| | | <!-- é¿éfastjson --> |
| | | <dependency> |
| | | <groupId>cglib</groupId> |
| | | <artifactId>cglib</artifactId> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>com.alibaba.fastjson2</groupId> |
| | | <artifactId>fastjson2</artifactId> |
| | |
| | | <artifactId>jdom2</artifactId> |
| | | </dependency> |
| | | |
| | | <!-- beanåmapäºè½¬æ¢ --> |
| | | <dependency> |
| | | <groupId>org.apache.dubbo</groupId> |
| | | <artifactId>dubbo</artifactId> |
| | | <version>3.2.7</version> |
| | | <exclusions> |
| | | <exclusion> |
| | | <groupId>io.netty</groupId> |
| | | <artifactId>netty-all</artifactId> |
| | | </exclusion> |
| | | <exclusion> |
| | | <groupId>org.yaml</groupId> |
| | | <artifactId>snakeyaml</artifactId> |
| | | </exclusion> |
| | | <exclusion> |
| | | <groupId>org.springframework</groupId> |
| | | <artifactId>spring-context</artifactId> |
| | | </exclusion> |
| | | <exclusion> |
| | | <groupId>com.alibaba.spring</groupId> |
| | | <artifactId>spring-context-support</artifactId> |
| | | </exclusion> |
| | | <exclusion> |
| | | <groupId>com.alibaba.fastjson2</groupId> |
| | | <artifactId>fastjson2</artifactId> |
| | | </exclusion> |
| | | <exclusion> |
| | | <groupId>com.alibaba</groupId> |
| | | <artifactId>hessian-lite</artifactId> |
| | | </exclusion> |
| | | <exclusion> |
| | | <groupId>org.javassist</groupId> |
| | | <artifactId>javassist</artifactId> |
| | | </exclusion> |
| | | </exclusions> |
| | | </dependency> |
| | | |
| | | <!-- æµè¯ --> |
| | | <dependency> |
| | | <groupId>org.springframework.boot</groupId> |
| | | <artifactId>spring-boot-starter-test</artifactId> |
| | | <scope>test</scope> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>junit</groupId> |
| | | <artifactId>junit</artifactId> |
| | |
| | | @GetMapping(path = "allLevel") |
| | | public BaseResponse<List<DistrictLevel>> allDistrictLevels(){ |
| | | //List<DistrictLevel> list = Arrays.asList(DistrictLevel.City, DistrictLevel.County, DistrictLevel.Town, DistrictLevel.Village) ; |
| | | return BaseResponseUtils.buildSuccess(DistrictLevel.ObjMap); |
| | | return BaseResponseUtils.buildSuccess(DistrictLevel.LevelList); |
| | | } |
| | | |
| | | /** |
| | |
| | | @GetMapping(path = "allOrg") |
| | | public BaseResponse<List<Org>> allOrg(){ |
| | | //List<Org> list = Arrays.asList(Org.Ym, Org.Pj) ; |
| | | return BaseResponseUtils.buildSuccess(Org.ObjMap); |
| | | return BaseResponseUtils.buildSuccess(Org.OrgList); |
| | | } |
| | | |
| | | /** |