From bb921522b934f30aac37cc5881a15d5142573d7c Mon Sep 17 00:00:00 2001
From: wuzeyu <1223318623@qq.com>
Date: 星期二, 28 十一月 2023 08:50:01 +0800
Subject: [PATCH] Merge branch 'master' of http://8.140.179.55:20000/r/pipIrr-SV
---
pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpClient/TcpClUnit.java | 110 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 110 insertions(+), 0 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
new file mode 100644
index 0000000..1189f3b
--- /dev/null
+++ b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpClient/TcpClUnit.java
@@ -0,0 +1,110 @@
+package com.dy.testClient.tcpClient;
+
+import com.dy.common.mw.UnitAdapterInterface;
+import com.dy.common.mw.UnitInterface;
+import com.dy.common.mw.UnitStartedCallbackInterface;
+import com.dy.common.threadPool.ThreadPool;
+import com.dy.common.threadPool.TreadPoolFactory;
+import com.dy.testClient.ServerProperties;
+import com.dy.testClient.rmiClient.RmiClUnit;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+public class TcpClUnit implements UnitInterface {
+
+ private static final Logger log = LogManager.getLogger(TcpClUnit.class) ;
+
+ private static TcpClUnit instance = new TcpClUnit() ;
+
+ public static TcpClUnitAdapter adapter ;
+ public static TcpClUnitConfigVo confVo ;
+
+ private static ThreadPool.Pool pool ;
+
+ private static Integer totalRunedClientCount = 0;
+ private static Integer totalOverClientCount = 0;
+
+ private static Long startTime = 0L ;
+
+ private TcpClUnit(){} ;
+
+ public static TcpClUnit getInstance(){
+ return instance ;
+ }
+
+ @Override
+ public void setAdapter(UnitAdapterInterface adapter) throws Exception {
+ if(adapter == null){
+ throw new Exception("Tcp Client妯″潡閫傞厤鍣ㄥ璞′笉鑳戒负绌猴紒") ;
+ }
+ TcpClUnit.adapter = (TcpClUnitAdapter)adapter ;
+ TcpClUnit.confVo = TcpClUnit.adapter.getConfig() ;
+ if(TcpClUnit.confVo == null){
+ throw new Exception("Tcp Client妯″潡閰嶇疆瀵硅薄涓嶈兘涓虹┖锛�") ;
+ }
+ }
+
+ @Override
+ public void start(UnitStartedCallbackInterface callback) throws Exception {
+ pool = TreadPoolFactory.getThreadPoolLong() ;
+ System.out.println("Tcp Client妯″潡鎴愬姛鍚姩");
+ this.doStart();
+ callback.call(null) ;
+ }
+
+ @Override
+ public void stop(UnitStartedCallbackInterface callback) throws Exception {
+ callback.call(null);
+ }
+
+ private void doStart(){
+ new Thread(new Runnable(){
+ @Override
+ public void run() {
+ try {
+ while(true){
+ if(!ServerProperties.startWork){
+ Thread.sleep(100L);
+ }else{
+ startTime = System.currentTimeMillis() ;
+ for(Long addr = ServerProperties.rtuAddrStart; addr <= ServerProperties.rtuAddrEnd; addr++){
+ totalRunedClientCount++ ;
+ startClient(addr) ;
+ }
+ while(true){
+ if(totalOverClientCount.longValue() >= totalRunedClientCount.longValue()){
+ Long seconds = (System.currentTimeMillis() - startTime)/1000 ;
+ RmiClUnit.getInstance().reportHadReportOver(seconds) ;
+ System.out.println("鍏辩敤鏃�" + seconds + "绉�");
+ break ;
+ }else{
+ Thread.sleep(100L);
+ }
+ }
+ break;
+ }
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }).start();
+ }
+
+ private void startClient(Long rtuAddr){
+ try {
+ pool.putJob(new MyThreadJob("" + rtuAddr));
+ } catch (Exception e) {
+ log.error("TcpClUnit.startClient() ", e);
+ }
+ }
+
+
+ public static synchronized void clientOver(){
+ totalOverClientCount++;
+ if(totalOverClientCount % 100 == 0){
+ RmiClUnit.getInstance().reportHadReportCount(totalOverClientCount);
+ System.out.println("宸茬粡鍙戦��" + totalOverClientCount + "鏉℃暟鎹�");
+ }
+ }
+}
--
Gitblit v1.8.0