From f2df44d7b3865cafe86baa48e19d1df0c0723702 Mon Sep 17 00:00:00 2001
From: liurunyu <lry9898@163.com>
Date: 星期三, 29 十一月 2023 19:46:46 +0800
Subject: [PATCH] pipIrr-mwTest-client阶段提交

---
 pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpClient/TcpClUnit.java |   55 +++++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 45 insertions(+), 10 deletions(-)

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
index 1189f3b..167adde 100644
--- 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
@@ -10,6 +10,10 @@
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
 public class TcpClUnit  implements UnitInterface {
 
     private static final Logger log = LogManager.getLogger(TcpClUnit.class) ;
@@ -20,8 +24,10 @@
     public static TcpClUnitConfigVo confVo ;
 
     private static ThreadPool.Pool pool ;
+    private static Map<String, MyThreadJob> jobMap = new HashMap<>() ;
 
     private static Integer totalRunedClientCount = 0;
+    private static Integer totalSendDataCount = 0;
     private static Integer totalOverClientCount = 0;
 
     private static Long startTime = 0L ;
@@ -69,12 +75,13 @@
                             startTime = System.currentTimeMillis() ;
                             for(Long addr = ServerProperties.rtuAddrStart; addr <= ServerProperties.rtuAddrEnd; addr++){
                                 totalRunedClientCount++ ;
-                                startClient(addr) ;
+                                createImitate(addr) ;
                             }
+                            startJob() ;
                             while(true){
                                 if(totalOverClientCount.longValue() >= totalRunedClientCount.longValue()){
                                     Long seconds = (System.currentTimeMillis() - startTime)/1000 ;
-                                    RmiClUnit.getInstance().reportHadReportOver(seconds) ;
+                                    RmiClUnit.getInstance().allOver(seconds) ;
                                     System.out.println("鍏辩敤鏃�" + seconds + "绉�");
                                     break ;
                                 }else{
@@ -91,20 +98,48 @@
         }).start();
     }
 
-    private void startClient(Long rtuAddr){
-        try {
-            pool.putJob(new MyThreadJob("" + rtuAddr));
-        } catch (Exception e) {
-            log.error("TcpClUnit.startClient() ", e);
-        }
+    /**
+     * 鍒涘缓RTU妯℃嫙MyThreadJob
+     * @param rtuAddr rtu鍦板潃
+     */
+    private void createImitate(Long rtuAddr){
+        jobMap.put("" + rtuAddr, new MyThreadJob("" + rtuAddr, ServerProperties.tcpServerIp, ServerProperties.tcpServerPort)) ;
     }
 
+    private void startJob(){
+        new Thread(new Runnable(){
+            @Override
+            public void run() {
+                try {
+                    Thread.sleep(1000L);
+                    while(true){
+                        Collection<MyThreadJob> collection = jobMap.values() ;
+                        for(MyThreadJob job : collection){
+                            pool.putJob(job);
+                        }
+                        Thread.sleep(ServerProperties.sendInterval * 1000);
+                    }
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
+            }
+        }).start();
+    }
+
+
+    public static synchronized void clientSendData(){
+        totalSendDataCount++;
+        if(totalSendDataCount % 100 == 0){
+            RmiClUnit.getInstance().reportHadReportCount(totalSendDataCount);
+            System.out.println("宸茬粡鍙戦��" + totalSendDataCount + "鏉℃暟鎹�");
+        }
+    }
 
     public static synchronized void clientOver(){
         totalOverClientCount++;
         if(totalOverClientCount % 100 == 0){
-            RmiClUnit.getInstance().reportHadReportCount(totalOverClientCount);
-            System.out.println("宸茬粡鍙戦��" + totalOverClientCount + "鏉℃暟鎹�");
+            RmiClUnit.getInstance().reportHadReportOver(totalOverClientCount);
+            System.out.println("宸叉湁" + totalOverClientCount + "瀹屾垚浜嗕换鍔�");
         }
     }
 }

--
Gitblit v1.8.0