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/rmiClient/Code.java | 8 pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpClient/TcpClUnitConfigVo.java | 2 pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpClient/LocalCodecFactory.java | 8 pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpClient/LocalEncoder.java | 22 ++ pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/AdapterImp_TcpClUnit.java | 0 pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/rmiClient/RmiClUnit.java | 33 ++ pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpClient/TcpHandler.java | 77 +++++++ pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/resources/Config.xml | 8 /dev/null | 64 ------ pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/Server.java | 28 ++ pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/rmiClient/ResConfigVo.java | 42 +++- pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/resources/log4j2.xml | 39 +++ pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpClient/LocalDecoder.java | 31 +++ pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpClient/MyThreadJob.java | 130 ++++++++++-- pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpClient/TcpConnect.java | 18 + pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/rmiClient/RmiResponseVo.java | 12 pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/ServerProperties.java | 8 pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpClient/TcpClUnit.java | 55 ++++- 18 files changed, 435 insertions(+), 150 deletions(-) diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/AdapterImp_HttpClUnit.java b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/AdapterImp_TcpClUnit.java similarity index 100% rename from pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/AdapterImp_HttpClUnit.java rename to pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/AdapterImp_TcpClUnit.java diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/Server.java b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/Server.java index 7aa1596..ef09342 100644 --- a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/Server.java +++ b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/Server.java @@ -68,20 +68,40 @@ //鏀寔妯″潡锛� springHibernate鍜� 绾跨▼姹� SupportUnitConfigVo supVo = new SupportUnitConfigVo() ; //鐭伐浣滄椂闀跨嚎绋嬫睜锛岀嚎绋嬭礋璐g敤鏃惰緝鐭殑宸ヤ綔浠诲姟 - supVo.short_maxThread = conf.getSetAttrPlusInt(doc, "config.support", "short_maxThread", null, 1, 1000, null) ;//姹犱腑鏈�澶х嚎绋嬫暟涓烘墍鏈塁PU鏍告暟+1 - supVo.short_minThread = conf.getSetAttrPlusInt(doc, "config.support", "short_minThread", null, 1, 5, null) ;//姹犱腑鏈�灏忕嚎绋嬫暟 + supVo.short_maxThread = conf.getSetAttrPlusInt(doc, "config.support", "short_maxThread", null, -1, 1000, null) ;//姹犱腑鏈�澶х嚎绋嬫暟涓烘墍鏈塁PU鏍告暟+1 + if(supVo.short_maxThread < 0){ + supVo.short_maxThread = -1 ; + } + supVo.short_minThread = conf.getSetAttrPlusInt(doc, "config.support", "short_minThread", null, -1, 100, null) ;//姹犱腑鏈�灏忕嚎绋嬫暟 + if(supVo.short_minThread < 0){ + supVo.short_minThread = -1 ; + } supVo.short_freeTimeout = conf.getSetAttrPlusInt(doc, "config.support", "short_freeTimeout", null, 1, 90, null) * 1000 ;//绾跨▼鏁扮┖闂叉椂闀匡紝鑻ユ睜涓嚎绋嬫暟閲忓ぇ浜巑inThread锛屼笖鏈夌殑绾跨▼绌洪棽鏃堕暱瓒呰繃freeTimeout锛屽垯娓呴櫎璇ョ嚎绋嬶紝涓轰簡涓嶆竻闄わ紝鎶妋inThread涓巑axThread璁剧疆鐩哥瓑 supVo.short_busyTimeout = conf.getSetAttrPlusInt(doc, "config.support", "short_busyTimeout", null, 1, 10, null) * 1000 ;//绾跨▼涓嶉棿鏂伐浣滄椂闀匡紙鍗曚綅涓虹)瓒呮椂闄愶紝璁や负绾跨▼宸茬粡浜嗗穿婧冿紝灏嗗己鍒舵竻闄わ紝鐭伐浣滄椂闀胯缃负5绉� + if(supVo.short_maxThread == 0 || supVo.short_minThread == 0){ + supVo.enableShortThreadPool = false ; + }else{ + supVo.enableShortThreadPool = true ; + } + //闀垮伐浣滄椂闀跨嚎绋嬫睜锛岀嚎绋嬭礋璐g敤鏃惰緝闀跨殑宸ヤ綔浠诲姟 supVo.long_maxThread = conf.getSetAttrInt(doc, "config.support", "long_maxThread", null, -1, 1000, null) ;//姹犱腑鏈�澶х嚎绋嬫暟,鑻ヤ负-1锛屼笉鍙楅檺鍒� if(supVo.long_maxThread < 0){ supVo.long_maxThread = -1 ; } - supVo.long_minThread = conf.getSetAttrPlusInt(doc, "config.support", "long_minThread", null, 0, 5, null) ;//姹犱腑鏈�灏忕嚎绋嬫暟 + supVo.long_minThread = conf.getSetAttrPlusInt(doc, "config.support", "long_minThread", null, -1, 100, null) ;//姹犱腑鏈�灏忕嚎绋嬫暟 + if(supVo.long_minThread < 0){ + supVo.long_minThread = -1 ; + } supVo.long_freeTimeout = conf.getSetAttrPlusInt(doc, "config.support", "long_freeTimeout", null, 1, 90, null) * 1000 ;//绾跨▼鏁扮┖闂叉椂闀匡紝鑻ユ睜涓嚎绋嬫暟閲忓ぇ浜巑inThread锛屼笖鏈夌殑绾跨▼绌洪棽鏃堕暱瓒呰繃freeTimeout锛屽垯娓呴櫎璇ョ嚎绋� supVo.long_busyTimeout = conf.getSetAttrInt(doc, "config.support", "long_busyTimeout", null, -1, 10, null) ;//绾跨▼涓嶉棿鏂伐浣滄椂闀匡紙鍗曚綅涓虹)瓒呮椂闄愶紝鑻ヤ负-1锛屼笉鍙楅檺鍒� if(supVo.long_busyTimeout < 0){ supVo.long_busyTimeout = -1 ; + } + if(supVo.long_maxThread == 0 || supVo.long_minThread == 0){ + supVo.enableLongThreadPool = false ; + }else{ + supVo.enableLongThreadPool = true ; } supVo.showStartInfo = showStartInfo ; @@ -113,8 +133,6 @@ // 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); diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/ServerProperties.java b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/ServerProperties.java index 7379686..a5f18cf 100644 --- a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/ServerProperties.java +++ b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/ServerProperties.java @@ -7,9 +7,13 @@ //RTU鎴鍦板潃 public static Long rtuAddrEnd = 0L ; //鏈嶅姟绔疘P - public static String serverIp = "" ; + public static String tcpServerIp = "" ; //鏈嶅姟绔笂涓嬫枃 - public static Integer serverPort = 0 ; + public static Integer tcpServerPort = 0 ; + //鍙戦�佹暟鎹暟鎹棿闅� + public static Integer sendInterval = 0 ;//绉� + //姣忎竴杞鍙戦�佹暟鎹紝鍏朵腑鍖呮嫭蹇冭烦鏁版嵁鐨勬鏁� + public static Integer heartbeatTimes = 3 ; //鍙戦�佹暟鎹鏁� public static Integer sendTimes = 0 ; diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/HttpClUnit.java b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/HttpClUnit.java deleted file mode 100644 index 9851e91..0000000 --- a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/HttpClUnit.java +++ /dev/null @@ -1,112 +0,0 @@ -package com.dy.testClient.httpCl; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import com.dy.testClient.rmiClient.RmiClUnit; -import com.dy.testClient.ServerProperties; -import com.dy.common.threadPool.ThreadPool; -import com.dy.common.threadPool.TreadPoolFactory; -import com.dy.common.mw.UnitAdapterInterface; -import com.dy.common.mw.UnitInterface; -import com.dy.common.mw.UnitStartedCallbackInterface; - -public class HttpClUnit implements UnitInterface { - - private static Logger log = LogManager.getLogger(HttpClUnit.class) ; - - private static HttpClUnit instance = new HttpClUnit() ; - - public static HttpClUnitAdapter adapter ; - public static HttpClUnitConfigVo confVo ; - - private static ThreadPool.Pool pool ; - - private static Integer totalRunedClientCount = 0; - private static Integer totalOverClientCount = 0; - - private static Long startTime = 0L ; - - private HttpClUnit(){} ; - - public static HttpClUnit getInstance(){ - return instance ; - } - - @Override - public void setAdapter(UnitAdapterInterface adapter) throws Exception { - if(adapter == null){ - throw new Exception("Http Client妯″潡閫傞厤鍣ㄥ璞′笉鑳戒负绌猴紒") ; - } - HttpClUnit.adapter = (HttpClUnitAdapter)adapter ; - HttpClUnit.confVo = HttpClUnit.adapter.getConfig() ; - if(HttpClUnit.confVo == null){ - throw new Exception("Http Client妯″潡閰嶇疆瀵硅薄涓嶈兘涓虹┖锛�") ; - } - } - - @Override - public void start(UnitStartedCallbackInterface callback) throws Exception { - pool = TreadPoolFactory.getThreadPoolLong() ; - System.out.println("Http Client妯″潡鎴愬姛鍚姩"); - this.doStart(); - callback.call(null) ; - } - - @Override - public void stop(UnitStartedCallbackInterface callback) throws Exception { - callback.call(null); - } - - private void doStart(){ - new Thread(new Runnable(){ - @Override - public void run() { - try { - while(true){ - if(!ServerProperties.startWork){ - Thread.sleep(100L); - }else{ - startTime = System.currentTimeMillis() ; - for(Long i = ServerProperties.rtuAddrStart ; i <= ServerProperties.rtuAddrEnd; i++){ - totalRunedClientCount++ ; - startClient(i) ; - } - while(true){ - if(totalOverClientCount.longValue() >= totalRunedClientCount.longValue()){ - Long seconds = (System.currentTimeMillis() - startTime)/1000 ; - RmiClUnit.getInstance().reportHadReportOver(seconds) ; - System.out.println("鍏辩敤鏃�" + seconds + "绉�"); - break ; - }else{ - Thread.sleep(100L); - } - } - break; - } - } - } catch (Exception e) { - e.printStackTrace(); - } - } - }).start(); - } - - private void startClient(Long imei){ - try { - pool.putJob(new MyThreadJob("" + imei)); - } catch (Exception e) { - log.error("HttpClUnit.startClient() ", e); - } - } - - - public static synchronized void clientOver(){ - totalOverClientCount++; - if(totalOverClientCount % 100 == 0){ - RmiClUnit.getInstance().reportHadReportCount(totalOverClientCount); - System.out.println("宸茬粡鍙戦��" + totalOverClientCount + "鏉℃暟鎹�"); - } - } - -} diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/HttpClUnitAdapter.java b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/HttpClUnitAdapter.java deleted file mode 100644 index 8f80484..0000000 --- a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/HttpClUnitAdapter.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.dy.testClient.httpCl; - -import com.dy.common.mw.UnitAdapterInterface; - -public interface HttpClUnitAdapter extends UnitAdapterInterface { - - public HttpClUnitConfigVo getConfig() ; - -} diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/HttpClUnitConfigVo.java b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/HttpClUnitConfigVo.java deleted file mode 100644 index 7b3513d..0000000 --- a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/HttpClUnitConfigVo.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.dy.testClient.httpCl; - -public class HttpClUnitConfigVo { - public boolean enable ; -} diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/HttpPost.java b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/HttpPost.java deleted file mode 100644 index 3b8e37b..0000000 --- a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/HttpPost.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.dy.testClient.httpCl; - -import com.dy.testClient.ServerProperties; -import com.dy.common.util.HttpUtils; - -public class HttpPost { - - public static synchronized void post(byte[] bytes) throws Exception{ - //HttpUtils.doPost(ServerProperties.serverUrl, ServerProperties.serverContext, null, null, bytes) ; - } -} diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/MyThreadJob.java b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/MyThreadJob.java deleted file mode 100644 index d3494c5..0000000 --- a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/MyThreadJob.java +++ /dev/null @@ -1,76 +0,0 @@ -package com.dy.testClient.httpCl; - -import java.util.Base64; - -import com.dy.common.threadPool.ThreadPool; - -public class MyThreadJob implements ThreadPool.Job { - - public String imei ; - - public MyThreadJob(){ - } - public MyThreadJob(String imei){ - this.imei = imei ; - } - - @Override - public void execute() throws Exception { - testMeterV1_0() ; - //testHAC_NBhV2_5() ; - } - - private void testMeterV1_0(){ - try{ - RtuData4MeterV1_0 rd = new RtuData4MeterV1_0() ; - byte[] bs = rd.create(imei) ; - bs = Base64.getEncoder().encode(bs) ; - - UpDataPayloadVo payloadVo = new UpDataPayloadVo() ; - payloadVo.APPdata = new String(bs, "UTF-8") ; - - UpDataVo vo = new UpDataVo(imei, "8086" + imei ) ; - vo.payload = payloadVo ; - String json = vo.toJson() ; - byte[] bytes = json.getBytes() ; - HttpPost.post(bytes); - }catch(Exception e){ - e.printStackTrace(); - }finally{ - HttpClUnit.clientOver() ; - } - } - - @SuppressWarnings("unused") - private void testHAC_NBhV2_5(){ - try{ - RtuData4HAC_NBhV2_5 rd = new RtuData4HAC_NBhV2_5() ; - byte[] bs = rd.create(imei) ; - bs = Base64.getEncoder().encode(bs) ; - - UpDataPayloadVo payloadVo = new UpDataPayloadVo() ; - payloadVo.APPdata = new String(bs, "UTF-8") ; - - UpDataVo vo = new UpDataVo(imei, "8086" + imei ) ; - vo.payload = payloadVo ; - String json = vo.toJson() ; - byte[] bytes = json.getBytes() ; - HttpPost.post(bytes); - }catch(Exception e){ - e.printStackTrace(); - }finally{ - HttpClUnit.clientOver() ; - } - } - - @Override - public void destroy() { - } - - @Override - public boolean isDestroy() { - return false; - } - - -} diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/RtuData4HAC_NBhV2_5.java b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/RtuData4HAC_NBhV2_5.java deleted file mode 100644 index 52c839f..0000000 --- a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/RtuData4HAC_NBhV2_5.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.dy.testClient.httpCl; - -import com.dy.common.util.ByteUtil; - -public class RtuData4HAC_NBhV2_5 { - public byte[] create(String imei) throws Exception{ - /* - * 0101 - * 00 - * 02 - * 4643 - * 3C - * 00BE - * FF - * 86AB62626E642F332F30026A313233343536373839300D1A64B8FCE60E655554432B3801634E42680719016E110112655056332E30136C56332E30345F32323034323214001701A762626E652F38302F3001020600101A00000000171A00000000181A1A00000000181F00A462626E652F38312F30030101000201A462626E652F38322F30000001000200A262626E652F38342F30001A00015180A462626E652F39392F30016F3836333331383036303136393235390D3903010E390013 - * EA77 - * - */ - String hex = "0101024570753C001AFFA30D1B000001898AB2E3160E655554432B3862626E642F332F303190" ; - //String hex = "0101000246433C00BEFF86AB62626E642F332F30026A313233343536373839300D1A64B8FCE60E655554432B3801634E42680719016E110112655056332E30136C56332E30345F32323034323214001701A762626E652F38302F3001020600101A00000000171A00000000181A1A00000000181F00A462626E652F38312F30030101000201A462626E652F38322F30000001000200A262626E652F38342F30001A00015180A462626E652F39392F30016F3836333331383036303136393235390D3903010E390013EA77" ; - return ByteUtil.hex2Bytes(hex) ; - } - /* - * -86AB62626E642F332F30 -026A3132333435363738 -39300D1A64B8FCE60E65 -5554432B3801634E4268 -0719016E110112655056 -332E30136C56332E3034 -5F323230343232140017 -01A762626E652F38302F -3001020600101A000000 -00171A00000000181A1A -00000000181F00A46262 -6E652F38312F30030101 -000201A462626E652F38 -322F30000001000200A2 -62626E652F38342F3000 -1A00015180A462626E65 -2F39392F30016F383633 -33313830363031363932 -35390D3903010E390013 - */ - -} diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/RtuData4MeterV1_0.java b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/RtuData4MeterV1_0.java deleted file mode 100644 index daf8340..0000000 --- a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/RtuData4MeterV1_0.java +++ /dev/null @@ -1,165 +0,0 @@ -package com.dy.testClient.httpCl; - -import com.dy.common.mw.protocol.pMeterV1_0_1.ProtocolConstantV1_0_1; -import com.dy.common.util.ByteUtil; -import com.dy.common.util.ByteUtilUnsigned; -import com.dy.common.util.CreateRadom; -import com.dy.common.util.DateTime; - -public class RtuData4MeterV1_0 { - public byte[] create(String imei) throws Exception{ - /* - * 68 - * 0051 - * 01 - * 0300000000000001 - * 12233445566778 - * 01 - * 221128152107 - * 0001E240 - * 000004D2 - * 24 - * 0129 - * 11 - * 002D - * 0035 - * 003D - * 006E - * 0038 - * 00C3 - * 00AC - * 004C - * 0028 - * 0081 - * 001B - * 005E - * 003D - * 0063 - * 00AB - * 0071 - * 00BB - * 0046 - * 004A - * 009B - * 0087 - * 00BE - * 0022 - * 00B0 - * DA - * 16 - */ - int len = 89 ; - byte[] bs = new byte[len] ; - bs[0] = ProtocolConstantV1_0_1.P_Head_Byte ; - ByteUtilUnsigned.short2Bytes_BE(bs, len, 1);//闀垮害 - bs[3] = (byte)101 ;//鍗忚鐗堟湰鍙� - while(true){ - if(imei.length() >= 16){ - break ; - }else{ - imei = "0" + imei ; - } - } - ByteUtil.string2BCD_BE(bs, imei, 4) ;//IMEI鍙� - - String meterNo = "" + (Long.valueOf(imei) + 1); - while(true){ - if(meterNo.length() >= 16){ - break ; - }else{ - meterNo = "0" + meterNo ; - } - } - ByteUtil.string2BCD_BE(bs, meterNo, 12) ;//姘磋〃鍙� - - bs[20] = 1 ;//鍔熻兘鐮� - - ByteUtil.string2BCD_BE(bs, DateTime.yyMMddhhmmss(), 21) ;//鏃堕棿 - - ByteUtilUnsigned.int2Bytes_BE(bs, 123456, 27);//瀹炴椂绱姘撮噺 - - ByteUtilUnsigned.int2Bytes_BE(bs, 54321, 31);//鏃ョ疮璁℃按閲� - - bs[35] = (byte)36;//鐢垫睜鐢靛帇 - - ByteUtilUnsigned.short2Bytes_BE(bs, 297, 36);//淇″彿寮哄害 - - byte sta = 0 ; - int num = CreateRadom.radom_4() ; - if(num%2 == 0){ - sta += 1 ;//闃�闂ㄧ姸鎬� - } - num = CreateRadom.radom_4() ; - if(num%2 == 0){ - sta += 4 ;//闃�闂ㄦ晠闅� - } - num = CreateRadom.radom_4() ; - if(num%2 == 0){ - sta += 8 ;//寮虹 - } - num = CreateRadom.radom_4() ; - if(num%2 == 0){ - sta += 16 ;//鐢垫睜娆犲帇 - } - bs[38] = sta;//琛ㄧ姸鎬� - - num = CreateRadom.radom(200, 10) ; - ByteUtilUnsigned.short2Bytes_BE(bs, num, 39);//1鐐瑰皬鏃剁敤姘撮噺 - num = CreateRadom.radom(200, 10) ; - ByteUtilUnsigned.short2Bytes_BE(bs, num, 41);//2鐐瑰皬鏃剁敤姘撮噺 - num = CreateRadom.radom(200, 10) ; - ByteUtilUnsigned.short2Bytes_BE(bs, num, 43);//3 - num = CreateRadom.radom(200, 10) ; - ByteUtilUnsigned.short2Bytes_BE(bs, num, 45);//4 - num = CreateRadom.radom(200, 10) ; - ByteUtilUnsigned.short2Bytes_BE(bs, num, 47);//5 - num = CreateRadom.radom(200, 10) ; - ByteUtilUnsigned.short2Bytes_BE(bs, num, 49);//6 - num = CreateRadom.radom(200, 10) ; - ByteUtilUnsigned.short2Bytes_BE(bs, num, 51);//7 - num = CreateRadom.radom(200, 10) ; - ByteUtilUnsigned.short2Bytes_BE(bs, num, 53);//8 - num = CreateRadom.radom(200, 10) ; - ByteUtilUnsigned.short2Bytes_BE(bs, num, 55);//9 - num = CreateRadom.radom(200, 10) ; - ByteUtilUnsigned.short2Bytes_BE(bs, num, 57);//10 - num = CreateRadom.radom(200, 10) ; - ByteUtilUnsigned.short2Bytes_BE(bs, num, 59);//11 - num = CreateRadom.radom(200, 10) ; - ByteUtilUnsigned.short2Bytes_BE(bs, num, 61);//12 - num = CreateRadom.radom(200, 10) ; - ByteUtilUnsigned.short2Bytes_BE(bs, num, 63);//13 - num = CreateRadom.radom(200, 10) ; - ByteUtilUnsigned.short2Bytes_BE(bs, num, 65);//14 - num = CreateRadom.radom(200, 10) ; - ByteUtilUnsigned.short2Bytes_BE(bs, num, 67);//15 - num = CreateRadom.radom(200, 10) ; - ByteUtilUnsigned.short2Bytes_BE(bs, num, 69);//16 - num = CreateRadom.radom(200, 10) ; - ByteUtilUnsigned.short2Bytes_BE(bs, num, 71);//17 - num = CreateRadom.radom(200, 10) ; - ByteUtilUnsigned.short2Bytes_BE(bs, num, 73);//18 - num = CreateRadom.radom(200, 10) ; - ByteUtilUnsigned.short2Bytes_BE(bs, num, 75);//19 - num = CreateRadom.radom(200, 10) ; - ByteUtilUnsigned.short2Bytes_BE(bs, num, 77);//20 - num = CreateRadom.radom(200, 10) ; - ByteUtilUnsigned.short2Bytes_BE(bs, num, 79);//21 - num = CreateRadom.radom(200, 10) ; - ByteUtilUnsigned.short2Bytes_BE(bs, num, 81);//22 - num = CreateRadom.radom(200, 10) ; - ByteUtilUnsigned.short2Bytes_BE(bs, num, 83);//23 - num = CreateRadom.radom(200, 10) ; - ByteUtilUnsigned.short2Bytes_BE(bs, num, 85);//24 - - byte he = 0 ; - for(byte i = 0 ; i <= 86; i++){ - he = (byte)(he + bs[i]) ; - } - ByteUtilUnsigned.byte2Byte(bs, he, 87) ; - bs[88] = ProtocolConstantV1_0_1.P_Tail_Byte ; - - return bs ; - } - -} diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/TestBase64.java b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/TestBase64.java deleted file mode 100644 index 8bdda86..0000000 --- a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/TestBase64.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.dy.testClient.httpCl; - -import java.io.UnsupportedEncodingException; -import java.util.Base64; - -import com.dy.common.util.ByteUtil; - -public class TestBase64 { - - public static void main(String[] args) throws UnsupportedEncodingException{ - String hex1 = "6838363235393230353934333439373000002002303231310000000000000032003005002E000000000001000000000200000000032101010012330400300521010100123306016907016908000009FF0000FC16" ; - System.out.println(hex1); - byte[] bs = ByteUtil.hex2Bytes(hex1) ; - bs = Base64.getEncoder().encode(bs) ; - String base64 = new String(bs, "UTF-8") ; - System.out.println(base64); - - bs = Base64.getDecoder().decode(base64); - String hex2 = ByteUtil.bytes2Hex(bs, false) ; - System.out.println(hex2); - - } -} diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/UpDataPayloadVo.java b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/UpDataPayloadVo.java deleted file mode 100644 index 8e1e7ff..0000000 --- a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/UpDataPayloadVo.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.dy.testClient.httpCl; - -public class UpDataPayloadVo { - - public String APPdata ; - - - public String getAPPdata() { - return APPdata; - } - - public void setAPPdata(String aPPdata) { - APPdata = aPPdata; - } - -} diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/UpDataVo.java b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/UpDataVo.java deleted file mode 100644 index 88f1e19..0000000 --- a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/httpCl/UpDataVo.java +++ /dev/null @@ -1,174 +0,0 @@ -package com.dy.testClient.httpCl; - - -import com.alibaba.fastjson2.JSON; - -public class UpDataVo { - - public Integer upPacketSN; //:-1, - public Integer upDataSN; //:-1, - public String topic; //:"v1/up/ad", - public Long timestamp; //:1667302244541, - public String tenantId; //:"2000114347", - public String serviceId; //:"", - public String protocol; //:"lwm2m", - public String productId; //:"15410798", - public UpDataPayloadVo payload; //:{"APPdata":"pQAYWhAGFQEmECIgETMgIQEBACASARckZFoAAFeq"}, - public String messageType; //:"dataReport", - public String deviceType; //:"", - public String deviceId; //:"59a4d90bf7a04aeea4d3523fe15d6f3f", - public String assocAssetId; //:"", - public String imsi; //:"undefined", - public String imei; //:"862592059434970" - - public UpDataVo(String imei, String deviceId){ - this.upPacketSN = - 1 ; - this.upDataSN = - 1 ; - this.topic = "v1/up/ad" ; - this.timestamp = System.currentTimeMillis() ; - this.tenantId = "2000114347" ; - this.serviceId = "" ; - this.protocol = "lwm2m" ; - this.productId = "15410798" ; - this.messageType = "dataReport" ; - this.deviceType = "" ; - this.deviceId = deviceId ; - this.assocAssetId = "" ; - this.imsi = "" ; - this.imei = imei ; - } - - public String toString(){ - StringBuffer sb = new StringBuffer() ; - sb.append("\nproductId锛�" + productId + "\n") ; - sb.append("deviceId锛�" + deviceId + "\n") ; - sb.append("imei锛�" + imei + "\n") ; - sb.append("payload锛�" + (payload==null?"":payload.APPdata) + "\n") ; - sb.append("timestamp锛�" + timestamp + "\n") ; - return sb.toString() ; - } - - /** - * 瀵硅薄杞垚json - * @return json - * @throws Exception 寮傚父 - */ - public String toJson()throws Exception{ - try{ - return JSON.toJSONString(this) ; - //return new JSONSerializer().exclude(new String[]{"class", "*.class"}).deepSerialize(this); - }catch(Exception e){ - throw new Exception(e.getMessage() , e ) ; - } - } - /** - * json杞垚瀵硅薄 - * @param json json - * @return 瀵硅薄 - * @throws Exception 寮傚父 - */ - public static UpDataVo jsonToObject(String json)throws Exception{ - try{ - return JSON.parseObject(json, UpDataVo.class) ; - //return new JSONDeserializer<UpDataVo>() - // .use("payload", UpDataPayloadVo.class) - // .deserialize(json, UpDataVo.class) ; - }catch(Exception e){ - throw new Exception(e.getMessage() , e ) ; - } - } - - - public Integer getUpPacketSN() { - return upPacketSN; - } - public void setUpPacketSN(Integer upPacketSN) { - this.upPacketSN = upPacketSN; - } - public Integer getUpDataSN() { - return upDataSN; - } - public void setUpDataSN(Integer upDataSN) { - this.upDataSN = upDataSN; - } - public String getTopic() { - return topic; - } - public void setTopic(String topic) { - this.topic = topic; - } - public Long getTimestamp() { - return timestamp; - } - public void setTimestamp(Long timestamp) { - this.timestamp = timestamp; - } - public String getTenantId() { - return tenantId; - } - public void setTenantId(String tenantId) { - this.tenantId = tenantId; - } - public String getServiceId() { - return serviceId; - } - public void setServiceId(String serviceId) { - this.serviceId = serviceId; - } - public String getProtocol() { - return protocol; - } - public void setProtocol(String protocol) { - this.protocol = protocol; - } - public String getProductId() { - return productId; - } - public void setProductId(String productId) { - this.productId = productId; - } - public UpDataPayloadVo getPayload() { - return payload; - } - public void setPayload(UpDataPayloadVo payload) { - this.payload = payload; - } - public String getMessageType() { - return messageType; - } - public void setMessageType(String messageType) { - this.messageType = messageType; - } - public String getDeviceType() { - return deviceType; - } - public void setDeviceType(String deviceType) { - this.deviceType = deviceType; - } - public String getDeviceId() { - return deviceId; - } - public void setDeviceId(String deviceId) { - this.deviceId = deviceId; - } - public String getAssocAssetId() { - return assocAssetId; - } - public void setAssocAssetId(String assocAssetId) { - this.assocAssetId = assocAssetId; - } - public String getIMSI() { - return imsi; - } - public void setIMSI(String iMSI) { - imsi = iMSI; - } - public String getIMEI() { - return imei; - } - public void setIMEI(String iMEI) { - imei = iMEI; - } - - -} diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/rmiClient/Code.java b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/rmiClient/Code.java index 4fcd76b..9dc631e 100644 --- a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/rmiClient/Code.java +++ b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/rmiClient/Code.java @@ -9,7 +9,9 @@ public static String cd3 = "003" ;//璇锋眰寮�濮嬪伐浣� public static String cd4 = "004" ;//鍚戞湇鍔$涓婃姤淇℃伅 - - public static String cd5 = "005" ;//鍚戞湇鍔$涓婃姤 鏁版嵁涓婃姤宸ヤ綔宸茬粡瀹屾垚 - + + public static String cd5 = "005" ;//鍚戞湇鍔$涓婃姤 瀹屾垚浠诲姟鐨勬暟閲� + + public static String cd6 = "006" ;//鍚戞湇鍔$涓婃姤 鍏ㄩ儴浠诲姟瀹屾垚 + } diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/rmiClient/ResConfigVo.java b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/rmiClient/ResConfigVo.java index c3affa5..59df2ce 100644 --- a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/rmiClient/ResConfigVo.java +++ b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/rmiClient/ResConfigVo.java @@ -8,12 +8,16 @@ //妯℃嫙瀹㈡埛鐨処MEI鍙锋埅姝㈠彿 public Long rtuAddrEnd = 0L ; //鏈嶅姟绔疘P - public String serverIp = "" ; + public String tcpServerIp = "" ; //鏈嶅姟绔笂涓嬫枃 - public Integer serverPort = 0 ; + public Integer tcpServerPort = 0 ; + //鍙戦�佹暟鎹棿闅� + public Integer sendInterval = 2 ;//绉� + //姣忎竴杞鍙戦�佹暟鎹紝鍏朵腑鍖呮嫭蹇冭烦鍙戦�佹鏁� + public Integer heartbeatTimes = 3 ; //鍙戦�佹暟鎹鏁� public Integer sendTimes = 0 ; - + /** * 瀵硅薄杞垚json * @return 瀵硅薄json @@ -58,20 +62,36 @@ this.rtuAddrEnd = rtuAddrEnd; } - public String getServerIp() { - return serverIp; + public String getTcpServerIp() { + return tcpServerIp; } - public void setServerIp(String serverIp) { - this.serverIp = serverIp; + public void setTcpServerIp(String tcpServerIp) { + this.tcpServerIp = tcpServerIp; } - public Integer getServerPort() { - return serverPort; + public Integer getTcpServerPort() { + return tcpServerPort; } - public void setServerPort(Integer serverPort) { - this.serverPort = serverPort; + public void setTcpServerPort(Integer tcpServerPort) { + this.tcpServerPort = tcpServerPort; + } + + public Integer getSendInterval() { + return sendInterval; + } + + public void setSendInterval(Integer sendInterval) { + this.sendInterval = sendInterval; + } + + public Integer getHeartbeatTimes() { + return heartbeatTimes; + } + + public void setHeartbeatTimes(Integer heartbeatTimes) { + this.heartbeatTimes = heartbeatTimes; } public Integer getSendTimes() { diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/rmiClient/RmiClUnit.java b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/rmiClient/RmiClUnit.java index 8d30bb8..008ed2a 100644 --- a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/rmiClient/RmiClUnit.java +++ b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/rmiClient/RmiClUnit.java @@ -94,13 +94,30 @@ } //鎶婃暟鎹笂鎶ュ畬鎴愭儏鍐� 涓婃姤缁檓wTestServer - public void reportHadReportOver(Long seconds){ + public void reportHadReportOver(Integer count){ try { Thread.sleep(100L); RmiRequestVo rqVo = new RmiRequestVo() ; rqVo.id = id ; rqVo.token = token ; rqVo.code = Code.cd5 ; + rqVo.count = count ; + String json = rqVo.toJson() ; + frmWork.syncRequest(json) ; + } catch (Exception e) { + log.error("鎶婃暟鎹笂鎶ュ畬鎴愭儏鍐� 涓婃姤缁檓wTestServer澶辫触" + e.getMessage()); + } + } + + + //鎶婃暟鎹笂鎶ュ畬鎴愭儏鍐� 涓婃姤缁檓wTestServer + public void allOver(Long seconds){ + try { + Thread.sleep(100L); + RmiRequestVo rqVo = new RmiRequestVo() ; + rqVo.id = id ; + rqVo.token = token ; + rqVo.code = Code.cd6 ; rqVo.over = true ; rqVo.seconds = seconds ; String json = rqVo.toJson() ; @@ -178,15 +195,19 @@ if(rVo != null){ ServerProperties.rtuAddrStart = rVo.rtuAddrStart; ServerProperties.rtuAddrEnd = rVo.rtuAddrEnd; - ServerProperties.serverIp = rVo.serverIp; - ServerProperties.serverPort = rVo.serverPort; + ServerProperties.tcpServerIp = rVo.tcpServerIp; + ServerProperties.tcpServerPort = rVo.tcpServerPort; + ServerProperties.sendInterval = rVo.sendInterval ; + ServerProperties.heartbeatTimes = rVo.heartbeatTimes ; ServerProperties.sendTimes = rVo.sendTimes ; log.info("寰楀埌閰嶇疆鎴愬姛"); log.info(" 寮�濮婻tuAddr=" + ServerProperties.rtuAddrStart); log.info(" 鎴RtuAddr=" + ServerProperties.rtuAddrEnd); - log.info(" mwAccept鏈嶅姟IP=" + ServerProperties.serverIp); - log.info(" mwAccept鏈嶅姟绔彛=" + ServerProperties.serverPort); - log.info(" 姣廼mei涓婃姤鏁版嵁娆℃暟=" + ServerProperties.sendTimes); + log.info(" mwAccept鏈嶅姟IP=" + ServerProperties.tcpServerIp); + log.info(" mwAccept鏈嶅姟绔彛=" + ServerProperties.tcpServerPort); + log.info(" 鍙戦�佹暟鎹棿闅�=" + ServerProperties.sendTimes); + log.info(" 姣忚疆娆″彂閫佸績璺虫鏁�=" + ServerProperties.heartbeatTimes); + log.info(" 姣廟TU涓婃姤鏁版嵁杞=" + ServerProperties.sendTimes); break ; }else{ log.error("rmi寰楀埌閰嶇疆澶辫触锛歫son杞琑esConfigVo涓簄ull"); diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/rmiClient/RmiResponseVo.java b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/rmiClient/RmiResponseVo.java index 658591a..8d952a7 100644 --- a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/rmiClient/RmiResponseVo.java +++ b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/rmiClient/RmiResponseVo.java @@ -1,6 +1,7 @@ package com.dy.testClient.rmiClient; import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONObject; public class RmiResponseVo { @@ -9,7 +10,7 @@ public String errorInfo ; public String code ; - + public Object obj ; /** @@ -33,11 +34,10 @@ */ 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 ; + JSONObject jsonObject = JSON.parseObject(json); + RmiResponseVo vo = jsonObject.to(RmiResponseVo.class) ; + vo.obj = jsonObject.getObject("obj", clazz); + return vo ; }catch(Exception e){ throw new Exception(e.getMessage() , e ) ; } diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpConnect/LocalCodecFactory.java b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpClient/LocalCodecFactory.java similarity index 95% rename from pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpConnect/LocalCodecFactory.java rename to pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpClient/LocalCodecFactory.java index 9f59b93..0251296 100644 --- a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpConnect/LocalCodecFactory.java +++ b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpClient/LocalCodecFactory.java @@ -1,9 +1,9 @@ -package com.dy.testClient.tcpConnect; +package com.dy.testClient.tcpClient; -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; +import org.apache.mina.filter.codec.ProtocolCodecFactory; +import org.apache.mina.filter.codec.ProtocolDecoder; +import org.apache.mina.filter.codec.ProtocolEncoder; public class LocalCodecFactory implements ProtocolCodecFactory { private ProtocolEncoder encoder; diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpClient/LocalDecoder.java b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpClient/LocalDecoder.java new file mode 100644 index 0000000..16ea1df --- /dev/null +++ b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpClient/LocalDecoder.java @@ -0,0 +1,31 @@ +package com.dy.testClient.tcpClient; + +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 java.io.IOException; + +public class LocalDecoder extends CumulativeProtocolDecoder { + + private static final String DECODER_STATE_KEY = LocalDecoder.class.getName() + ".STATE"; + + public static final int MAX_SIZE = 2147483647 ; + + + /** + * 瀵圭綉缁滀紶杈撴潵鐨勬暟鎹繘琛岃В鐮� + */ + protected boolean doDecode(IoSession session, IoBuffer in, ProtocolDecoderOutput out) throws IOException, Exception{ + int remain = in.remaining() ; + if(remain > 0){ + byte[] preByte = new byte[remain]; + in.get(preByte) ; + in.position(0) ; + } + return true; + } + + +} diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpClient/LocalEncoder.java b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpClient/LocalEncoder.java new file mode 100644 index 0000000..fdf716e --- /dev/null +++ b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpClient/LocalEncoder.java @@ -0,0 +1,22 @@ +package com.dy.testClient.tcpClient; + +import org.apache.mina.core.buffer.IoBuffer; +import org.apache.mina.core.session.IoSession; +import org.apache.mina.filter.codec.ProtocolEncoderAdapter; +import org.apache.mina.filter.codec.ProtocolEncoderOutput; + +import java.io.IOException; + +public class LocalEncoder extends ProtocolEncoderAdapter { + + /** + * 瀵规暟鎹繘琛岀紪鐮侊紝浠ュ缃戠粶浼犺緭 + */ + public void encode(IoSession session, Object message, ProtocolEncoderOutput out) throws IOException, Exception{ + byte[] data = (byte[])message; + //log.info("涓嬭鏁版嵁锛�" + ByteUtil.bytes2Hex(data, true)); + + out.write(IoBuffer.allocate((data==null?0:data.length), false).put(data).flip()); + } + +} diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpClient/MyThreadJob.java b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpClient/MyThreadJob.java index eee927c..0a07ff7 100644 --- a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpClient/MyThreadJob.java +++ b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpClient/MyThreadJob.java @@ -1,46 +1,126 @@ package com.dy.testClient.tcpClient; +import com.dy.common.mw.protocol.p206V1_0_0.CommonV1_0_1; +import com.dy.common.mw.protocol.p206V1_0_0.ProtocolConstantV206V1_0_0; +import com.dy.common.mw.protocol.p206V1_0_0.parse.global.GlCreate; import com.dy.common.threadPool.ThreadPool; -import com.dy.testClient.httpCl.*; - -import java.util.Base64; +import com.dy.common.util.ByteUtil; +import com.dy.testClient.ServerProperties; +import org.apache.mina.core.future.CloseFuture; +import org.apache.mina.core.session.IoSession; public class MyThreadJob implements ThreadPool.Job { public String rtuAddr; + public String serverIp; + public Integer serverPort; + + public IoSession session ; + + public static final int connectTimeout = 3000 ; + + public int sendTimes = 0 ;//鍙戦�佹暟鎹鏁� + public int heartbeatTimes = 0 ;//涓婃姤蹇冭烦娆℃暟 + + public boolean isOver = false ; public MyThreadJob(){ } - public MyThreadJob(String rtuAddr){ + public MyThreadJob(String rtuAddr, String serverIp, Integer serverPort){ this.rtuAddr = rtuAddr ; + this.serverIp = serverIp ; + this.serverPort = serverPort ; } @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() ; + if(session == null){ + IoSession se = new TcpConnect().createSession(this.rtuAddr, this, this.serverIp, this.serverPort, connectTimeout, new TcpHandler()) ; + if(se != null){ + this.session = se ; + } + }else{ + if(sendTimes <= ServerProperties.sendTimes){ + sendDataOfP206V1_0_0() ; + }else{ + this.jobOver() ; + } } } + private void sendDataOfP206V1_0_0(){ + try{ + if(heartbeatTimes >= ServerProperties.heartbeatTimes){ + heartbeatTimes = 0 ; + this.sendReportData() ; + sendTimes++ ; + }else{ + this.sendHeartbeat() ; + heartbeatTimes++ ; + } + }catch(Exception e){ + e.printStackTrace(); + } + } + private void sendHeartbeat(){ + try{ + byte[] bs = this.createHeartbeat() ; + this.session.write(bs) ; + }catch (Exception e){ + e.printStackTrace(); + } + } + + private void sendReportData(){ + TcpClUnit.clientSendData(); + } + + private void jobOver(){ + CloseFuture closeFuture = session.closeOnFlush() ; + this.isOver = true ; + TcpClUnit.clientOver() ; + } + + /** + * 鏋勯�犱笅琛屾暟鎹� + * @return 瀛楄妭鏁扮粍 + * @throws Exception 寮傚父 + */ + public byte[] createHeartbeat( ) throws Exception { + CommonV1_0_1 commonV1_0_1 = new CommonV1_0_1() ; + byte[] bytes ; + byte[] bsHead = new byte[ProtocolConstantV206V1_0_0.lenHead2Code] ; + byte index = 0 ; + bsHead[index] = ProtocolConstantV206V1_0_0.P_Head_Byte ; + + index++ ; + bsHead[index] = 0 ;//甯ч暱搴� + + index++ ; + bsHead[index] = ProtocolConstantV206V1_0_0.P_Head_Byte ; + + index++ ; + bsHead[index] = commonV1_0_1.createCtrl((byte)0) ; + + index++ ; + GlCreate.createRtuAddr(this.rtuAddr, bsHead, index); + index += 5 ; + + ByteUtil.hex2Bytes("02", bsHead, index) ; + + byte[] bs = new byte[1] ; + bs[0] = (byte)0xF2 ;//鏁版嵁鍩燂細 1 涓瓧鑺傦紝F0 鐧诲綍锛� F1 閫�鍑虹櫥褰曪紝F2 鍦ㄧ嚎淇濇寔銆� + + bytes = ByteUtil.bytesMerge(bsHead, bs) ; + + GlCreate.createLen(bytes);//闀垮害鏀惧瓧鑺傛暟缁勪腑 + + bytes = GlCreate.createCrcTail(bytes) ;//CRC鍜屽熬鍙犲姞瀛楄妭鏁扮粍涓� + + return bytes ; + } + + @Override public void destroy() { 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 + "瀹屾垚浜嗕换鍔�"); } } } diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpClient/TcpClUnitConfigVo.java b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpClient/TcpClUnitConfigVo.java index 0cc19ba..972b18e 100644 --- a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpClient/TcpClUnitConfigVo.java +++ b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpClient/TcpClUnitConfigVo.java @@ -2,6 +2,4 @@ public class TcpClUnitConfigVo { public boolean enable ; - public int heartbeatTimes ; - public int sendInterval ; } diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpConnect/MinaConnect.java b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpClient/TcpConnect.java similarity index 69% rename from pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpConnect/MinaConnect.java rename to pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpClient/TcpConnect.java index 2d85f19..cdf2c8e 100644 --- a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpConnect/MinaConnect.java +++ b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpClient/TcpConnect.java @@ -1,38 +1,44 @@ -package com.dy.testClient.tcpConnect; +package com.dy.testClient.tcpClient; 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 { +public class TcpConnect { + + public static final String rtuAddrKey = "rtuAddr" ; + public static final String threadJobKey = "threadJob" ; /** * 鍒ゆ柇浼氳瘽鏄惁鏈夋晥 * @param se 缃戠粶浼氳瘽 * @return 鏄惁杩炴帴 */ - protected boolean isConnected(IoSession se) { + public boolean isConnected(IoSession se) { return (se != null && se.isConnected()); } /** * 鍒涘缓鏂颁細璇� + * @param rtuAddr rtu鍦板潃 + * @param job rtu宸ヤ綔绫� * @param host 鏈嶅姟鍣║RI * @param port 鏈嶅姟鍣ㄧ鍙� * @return 缃戠粶浼氳瘽 */ - protected IoSession createSession(String host , int port , int connectTimeout , MinaHandler handler) throws Exception{ + public IoSession createSession(String rtuAddr, MyThreadJob job, String host , int port , int connectTimeout , TcpHandler 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(); + se.setAttribute(rtuAddrKey, rtuAddr) ; + se.setAttribute(threadJobKey, job) ; return se ; } @@ -42,7 +48,7 @@ * @param se * @param connectTimeout */ - protected void disconnect(IoSession se , int connectTimeout) { + public void disconnect(IoSession se , int connectTimeout) { if (se != null) { try{ se.closeNow().awaitUninterruptibly(connectTimeout); diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpClient/TcpHandler.java b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpClient/TcpHandler.java new file mode 100644 index 0000000..fbd9ed7 --- /dev/null +++ b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpClient/TcpHandler.java @@ -0,0 +1,77 @@ +package com.dy.testClient.tcpClient; + +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; +import org.apache.mina.filter.FilterEvent; + +public class TcpHandler extends IoHandlerAdapter { + + private static Logger log = LogManager.getLogger(TcpHandler.class.getName()) ; + + /** + * {@inheritDoc} + */ + @Override + public void sessionCreated(IoSession session) throws Exception { + } + + /** + * {@inheritDoc} + */ + @Override + public void sessionOpened(IoSession session) throws Exception { + } + + /** + * {@inheritDoc} + */ + @Override + public void sessionClosed(IoSession session) throws Exception { + } + + /** + * {@inheritDoc} + */ + @Override + public void sessionIdle(IoSession session, IdleStatus status) throws Exception { + } + + /** + * {@inheritDoc} + */ + @Override + public void exceptionCaught(IoSession session, Throwable cause) throws Exception { + } + + /** + * {@inheritDoc} + */ + @Override + public void messageReceived(IoSession session, Object message) throws Exception { + } + + /** + * {@inheritDoc} + */ + @Override + public void messageSent(IoSession session, Object message) throws Exception { + } + + /** + * {@inheritDoc} + */ + @Override + public void inputClosed(IoSession session) throws Exception { + session.closeNow(); + } + + /** + * {@inheritDoc} + */ + @Override + public void event(IoSession session, FilterEvent event) throws Exception { + } +} diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpConnect/LocalDecoder.java b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpConnect/LocalDecoder.java deleted file mode 100644 index 05aad53..0000000 --- a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpConnect/LocalDecoder.java +++ /dev/null @@ -1,91 +0,0 @@ -package com.dy.testClient.tcpConnect; -import java.io.*; - -import org.apache.mina.core.buffer.IoBuffer; -import org.apache.mina.core.session.IoSession; -import org.apache.mina.filter.codec.CumulativeProtocolDecoder; -import org.apache.mina.filter.codec.ProtocolDecoderOutput; - -import com.am.cs12.command.*; - -public class LocalDecoder extends CumulativeProtocolDecoder { - - private static final String DECODER_STATE_KEY = LocalDecoder.class.getName() + ".STATE"; - - public static final int MAX_SIZE = 2147483647 ; - - private class DecoderState { - Command com; - } - - /** - * 瀵圭綉缁滀紶杈撴潵鐨勬暟鎹繘琛岃В鐮� - */ - protected boolean doDecode(IoSession session, IoBuffer in, ProtocolDecoderOutput out) throws IOException, Exception{ - //浠庝細璇濅腑寰楀埌宸茬粡瑙g爜鐨勬暟鎹� - DecoderState decoderState = (DecoderState) session.getAttribute(DECODER_STATE_KEY); - if (decoderState == null) { - decoderState = new DecoderState(); - session.setAttribute(DECODER_STATE_KEY, decoderState); - } - if (decoderState.com == null) { - //璇曠潃璇诲彇鍛戒护鍖哄煙鏁版嵁 - //MAX_IMAGE_SIZE 鐩殑鏄槻姝㈠ぇ鏁版嵁閲忔敾鍑� - if (in.prefixedDataAvailable(4, MAX_SIZE)) { - decoderState.com = readCommand(in); - } else { - //鍛戒护鍖哄煙鏃犺冻澶熺殑鏁版嵁 - return false; - } - } - if (decoderState.com != null) { - //璇曠潃璇诲彇鏁版嵁(鏂囦欢)鍖哄煙鏁版嵁 - //MAX_IMAGE_SIZE 鐩殑鏄槻姝㈠ぇ鏁版嵁閲忔敾鍑� - if (in.prefixedDataAvailable(4, MAX_SIZE)) { - byte[] bs = getDataBytes(in); - MinaData minaCom = new MinaData() ; - minaCom.setCom(decoderState.com) ; - minaCom.setAttachment(bs) ; - out.write(minaCom); - - decoderState.com = null; - return true; - } else { - //鏁版嵁(鏂囦欢)鍖哄煙鏃犺冻澶熺殑鏁版嵁 - return false; - } - } - return false; - } - - /** - * 璇诲彇Command鍛戒护 - * @param in - * @return - * @throws IOException - */ - private Command readCommand(IoBuffer iob) throws IOException , Exception{ - int length = iob.getInt(); - byte[] bytes = new byte[length]; - iob.get(bytes); - Command com = new Command().toObject(bytes); - return com; - } - - /** - * 寰楀埌鏁版嵁鍩熸暟鎹殑瀛楄妭鏁扮粍 - * @param in - * @return - * @throws IOException - */ - private byte[] getDataBytes(IoBuffer iob) throws IOException { - int length = iob.getInt(); - if(length == 0){ - return null ; - } - byte[] bytes = new byte[length]; - iob.get(bytes); - return bytes ; - } - -} diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpConnect/LocalEncoder.java b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpConnect/LocalEncoder.java deleted file mode 100644 index f895d68..0000000 --- a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpConnect/LocalEncoder.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.dy.testClient.tcpConnect; - -import org.apache.mina.filter.codec.ProtocolEncoderOutput; -import org.apache.mina.filter.codec.ProtocolEncoderAdapter; -import org.apache.mina.core.buffer.IoBuffer; -import org.apache.mina.core.session.IoSession; - -import java.io.*; - -public class LocalEncoder extends ProtocolEncoderAdapter { - - /** - * 瀵规暟鎹繘琛岀紪鐮侊紝浠ュ缃戠粶浼犺緭 - */ - public void encode(IoSession session, Object message, ProtocolEncoderOutput out) throws IOException, Exception{ - MinaData minaData = null ; - if(message instanceof Command){ - minaData = new MinaData() ; - minaData.setCom((Command)message) ; - }else{ - minaData = (MinaData) message; - } - byte[] bytes1 = getCommandBytes(minaData.getCom()); - byte[] bytes2 = minaData.getAttachment() ; - int capacity = (bytes1==null?0:bytes1.length) + (bytes2==null?0:bytes2.length) + 8; - IoBuffer buffer = IoBuffer.allocate(capacity, false); - buffer.putInt(bytes1.length); - buffer.put(bytes1); - if(bytes2 == null){ - buffer.putInt(0); - }else{ - buffer.putInt(bytes2.length); - buffer.put(bytes2); - } - buffer.flip(); - out.write(buffer); - } - - /** - * 灏嗗懡浠よ浆鎹㈡垚瀛楄妭鏁扮粍 - * @param com - * @return - * @throws IOException - * @throws Exception - */ - private byte[] getCommandBytes(Command com) throws IOException, Exception { - String xml = com.toXml() ; - byte[] bytes = xml.getBytes() ; - return bytes ; - } -} diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpConnect/MinaConnectPool.java b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpConnect/MinaConnectPool.java deleted file mode 100644 index 0f3321f..0000000 --- a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpConnect/MinaConnectPool.java +++ /dev/null @@ -1,107 +0,0 @@ -package com.dy.testClient.tcpConnect; - -import java.util.*; -import org.apache.mina.core.session.IoSession; - - -public class MinaConnectPool { - /** - * 绌洪棽浼氳瘽鐨勬睜(Hashtable鏄嚎绋嬪畨鍏ㄧ殑) - */ - private static Hashtable<String , Vector<IoSession>> freeSessions = new Hashtable<String ,Vector<IoSession>>(); - - /** - * 浠庝細璇濇睜涓緱鍒扮┖闂茬殑浼氳瘽锛屽鏋滄病鏈夌┖闂茬殑浼氳瘽锛屾湰鐫�蹇�熷弽搴旂殑鍘熷垯锛屾柊寤轰竴涓細璇濓紝涓嶅啀绛夊緟绻佸繖浼氳瘽鐨勯噴鏀� - * @param host - * @param port - * @return - * @throws Exception - */ - public static IoSession getSession(String host , int port , int connectTimeout) throws Exception{ - Vector<IoSession> vecter = freeSessions.get(getKey(host , port)) ; - if(vecter == null){ - vecter = new Vector<IoSession>() ; - freeSessions.put(getKey(host , port), vecter) ; - } - - MinaConnect con = new MinaConnect() ; - - IoSession se = popSession(vecter , con) ; - if(se == null){ - MinaHandler handler = new MinaHandler(connectTimeout) ; - se = createNewSession(host, port, connectTimeout, con, handler) ; - } - return se ; - } - - /** - * 灏嗕細璇濇斁鍥炴睜涓� - * @param host - * @param port - * @param se - */ - public static void freeSession(String host , int port , IoSession se){ - if(se == null){ - return ; - } - Vector<IoSession> vecter = freeSessions.get(getKey(host , port)) ; - if(vecter == null){ - vecter = new Vector<IoSession>() ; - freeSessions.put(getKey(host , port), vecter) ; - } - putSession(vecter, se) ; - } - - /** - * 浠庝細璇濇睜涓彇寰楃┖闂茬殑浼氳瘽 - * @param vecter - * @return - */ - private static IoSession popSession(Vector<IoSession> vecter , MinaConnect con){ - IoSession se = null ; - while(se == null && !vecter.isEmpty()){ - se = (IoSession)vecter.firstElement() ; - if(se != null){ - vecter.removeElementAt(0) ; - } - if(!con.isConnected(se)){ - se = null ; - } - } - return se ; - } - - /** - * 鏀炬柊浼氳瘽 - * @param vecter - * @param se - */ - private static void putSession(Vector<IoSession> vecter , IoSession se){ - vecter.addElement(se) ; - } - - /** - * 鍒涘缓鏂颁細璇� - * @param host - * @param port - * @param connectTimeout - * @param con - * @return - * @throws Exception - */ - private static IoSession createNewSession(String host , int port , int connectTimeout, MinaConnect con , MinaHandler handler) throws Exception{ - return con.createSession(host, port, connectTimeout , handler) ; - } - - /** - * 寰楀埌浼氳瘽姹犵殑key - * @param url - * @param port - * @return - */ - private static String getKey(String host , int port){ - return host + port ; - } - -} - diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpConnect/MinaHandler.java b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpConnect/MinaHandler.java deleted file mode 100644 index 8749cca..0000000 --- a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/java/com/dy/testClient/tcpConnect/MinaHandler.java +++ /dev/null @@ -1,94 +0,0 @@ -package com.dy.testClient.tcpConnect; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.apache.mina.core.service.IoHandlerAdapter; -import org.apache.mina.core.session.IdleStatus; -import org.apache.mina.core.session.IoSession; - -public class MinaHandler extends IoHandlerAdapter { - - private static Logger log = LogManager.getLogger(MinaHandler.class.getName()) ; - - private Object synObj ; - private int connectTimeout ; - private MinaData minaData ; - - public MinaHandler( int connectTimeout){ - this.connectTimeout = connectTimeout ; - this.synObj = new Object() ; - } - - /** - * 鍙戦�佸懡浠� - * @param session - * @param minaData - */ - public void sendCommand(IoSession session, MinaData minaData){ - session.write(minaData) ; - } - - /** - * 鍙栧緱鍛戒护缁撴灉 - * @param waitTimeout - */ - public MinaData getAnswer(int waitTimeout){ - synchronized (synObj) { - try { - synObj.wait(waitTimeout); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - return this.minaData; - } - - - - @Override - public void exceptionCaught(IoSession session, Throwable cause) throws Exception { - new MinaConnect().disconnect(session, this.connectTimeout) ; - log.error(cause.getMessage()) ; - } - - @Override - public void messageReceived(IoSession session, Object message) throws Exception { - this.minaData = (MinaData) message; - synchronized (synObj) { - if (synObj != null) { - synObj.notifyAll(); - } - } - } - - @Override - public void messageSent(IoSession session, Object message) throws Exception { - super.messageSent(session, message); - log.info("鍛戒护宸茬粡鍙戦�併��") ; - } - - @Override - public void sessionClosed(IoSession session) throws Exception { - super.sessionClosed(session); - log.info("缃戠粶浼氳瘽宸茬粡鍏抽棴銆�") ; - } - - @Override - public void sessionCreated(IoSession session) throws Exception { - super.sessionCreated(session); - log.info("缃戠粶浼氳瘽宸茬粡鍒涘缓銆�") ; - } - - @Override - public void sessionIdle(IoSession session, IdleStatus status) throws Exception { - super.sessionIdle(session, status); - } - - @Override - public void sessionOpened(IoSession session) throws Exception { - super.sessionOpened(session); - log.info("缃戠粶浼氳瘽宸茬粡鎵撳紑銆�") ; - } - - -} diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/resources/Config.xml b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/resources/Config.xml index aec0502..7ac7aec 100644 --- a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/resources/Config.xml +++ b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/resources/Config.xml @@ -32,17 +32,13 @@ --> <rmiCl rmiSvUrl="127.0.0.1" - rmiSvContext="mwTestServer" - rmiSvPort="9898" + rmiSvContext="mwTestSv" + rmiSvPort="12345" /> <!-- enable:鏄惁鍚姩 - heartbeatTimes:杩炵画閰嶇疆娆℃暟蹇冭烦鍚庡彂閫佷竴娆℃暟鎹� - sendInterval:鍙戦�佸績璺虫垨鏁版嵁鐨勬椂闂撮棿闅� --> <tcpCl enable="true" - heartbeatTimes="3" - sendInterval="3" /> </config> \ No newline at end of file diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/resources/application.yml b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/resources/application.yml deleted file mode 100644 index 8b13789..0000000 --- a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/resources/application.yml +++ /dev/null @@ -1 +0,0 @@ - diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/resources/log4j2.xml b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/resources/log4j2.xml new file mode 100644 index 0000000..104ed67 --- /dev/null +++ b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/resources/log4j2.xml @@ -0,0 +1,39 @@ +<?xml version="1.0" encoding="UTF-8"?> +<Configuration status="OFF"> + <Appenders> + <Console name="Console" target="SYSTEM_OUT"> + <PatternLayout charset="GBK" pattern="%d %-5p [%t] (%F:%L) - %m%n%throwable"/> + </Console> + <!-- + fileName="${sys:user.home}/logs/aepTest.log" filePattern="${sys:user.home}/logs/aepTest-%d{yyyy-MM}-%i.log.gz" + fileName="/logs/testJgroups.log" filePattern="/logs/testJgroups-%d{yyyyMMdd}-%i.log.gz" + fileName="logs/testJgroups.log" filePattern="logs/testJgroups-%d{yyyyMMdd}-%i.log.gz" + sys:user.home褰撳墠鐢ㄦ埛鍦ㄦ搷浣滅郴缁熶腑鐨勬枃妗g洰褰� + /logs/testJgroups.log褰撳墠杞欢鎵�鍦ㄧ‖鐩樻牴鐩綍 + logs/testJgroups.log褰撳墠杞欢鎵�鍦ㄧ洰褰� + --> + <RollingFile name="File" fileName="logs/mwTestCl.log" filePattern="logs/aepTest-%d{yyyyMMdd}-%i.log"> + <PatternLayout charset="UTF-8" pattern="%d %-5p [%t] (%class.%method:%L) - %m%n%throwable"/> + <Policies> + <TimeBasedTriggeringPolicy interval="7" /> + <SizeBasedTriggeringPolicy size="10MB"/> + </Policies> + <DefaultRolloverStrategy max="50" /> + </RollingFile> + </Appenders> + <Loggers> + <!-- + <Logger name="com.zhzc.jgTest" level="debug"> + <AppenderRef ref="Console"/> + </Logger> + <Logger name="org.jgroups" level="info"> + <AppenderRef ref="File"/> + </Logger> + --> + <!-- Root涓庡悇涓狶ogger鍚屾椂璧蜂綔鐢� --> + <Root level="info"> + <AppenderRef ref="Console"/> + <AppenderRef ref="File"/> + </Root> + </Loggers> +</Configuration> diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/resources/log4j2.yml b/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/resources/log4j2.yml deleted file mode 100644 index 375972f..0000000 --- a/pipIrr-platform/pipIrr-mw/pipIrr-mwTest-client/src/main/resources/log4j2.yml +++ /dev/null @@ -1,64 +0,0 @@ -Configuration: - #status锛岃繖涓敤浜庤缃甽og4j2鑷韩鍐呴儴鐨勪俊鎭緭鍑猴紝鍙互涓嶈缃紝褰撹缃垚trace鏃讹紝浣犱細鐪嬪埌log4j2鍐呴儴鍚勭璇︾粏杈撳嚭锛涘彲浠ヨ缃垚Off(鍏抽棴)鎴朎rror(鍙緭鍑洪敊璇俊鎭�) - status: Error - - Properties: # 瀹氫箟鍏ㄥ眬鍙橀噺 - Property: - #鏃ュ織鏂囦欢瀛樺偍鐨勭洰褰� - - name: log.path - value: ./logs - #鏃ュ織鏂囦欢瀛樺偍鍚嶇О - - name: project.name - value: mwTestClient - - #瀹氫箟杈撳嚭鍣紝鍙互杈撳嚭鍒版帶鍒跺彴鍜屾枃浠�. - Appenders: - #杈撳嚭鍒版帶鍒跺彴 - Console: - #Appender鍛藉悕 - name: CONSOLE - target: SYSTEM_OUT - ThresholdFilter: - level: debug #杈撳嚭鏃ュ織绾у埆锛岃緭鍑烘棩蹇楁椂锛岄鍏堢敱Loggers.Root.level鎴朙oggers.Logger.level鍒ゆ柇鏄惁杈撳嚭锛岀劧鍚庡啀鐢辨湰level鍒ゆ柇鏄惁杈撳嚭 - onMatch: ACCEPT #onMatch=ACCEPT 澶т簬绛変簬 "level" 閰嶇疆鐨勭瓑绾у湴鏃ュ織杈撳嚭 - onMismatch: DENY #onMismatch=DENY 灏忎簬 "level" 閰嶇疆鐨勭瓑绾у湴鏃ュ織涓嶈緭鍑� - #鏃ュ織鍐呭鏍峰紡 - PatternLayout: - #%n-鎹㈣ - #%m-鏃ュ織鍐呭锛岃緭鍑轰唬鐮佷腑鎸囧畾鐨勬棩蹇椾俊鎭� - #%p-杈撳嚭浼樺厛绾э紝鍗矰EBUG,INFO,WARN,ERROR,FATAL - #%r-绋嬪簭鍚姩鍒扮幇鍦ㄧ殑姣鏁� - #%%- 杈撳嚭涓�涓�"%" 瀛楃 - #%t-褰撳墠绾跨▼鍚� - #%d-鏃ユ湡鍜屾椂闂�, 甯哥敤鐨勬牸寮忔湁%d{DATE},%d{ABSOLUTE},%d{HH:mm:ss,SSS},%d{ddMMyyyyHH:mm:ss,SSS} - #%l-鍚�%F%L%C%M - #%F-java婧愭枃浠跺悕 - #%L-java婧愮爜琛屾暟 - #%C-java绫诲悕,%C{1}杈撳嚭鏈�鍚庝竴涓厓绱� - #%M-java鏂规硶鍚� - pattern: "%d{yyyy-MM-dd HH:mm:ss,SSS}:%4p %t (%C.%M:%L) - %m%n" - # 杈撳嚭鍒版枃浠讹紝瓒呰繃10MB褰掓。 - RollingFile: - - name: ROLLING_FILE - ignoreExceptions: false - fileName: ${log.path}/${project.name}.log - filePattern: "${log.path}/$${date:yyyy-MM}/${project.name}-%d{yyyy-MM-dd}-%i.log.gz" - ThresholdFilter: - level: error #杈撳嚭鏃ュ織绾у埆锛岃緭鍑烘棩蹇楁椂锛岄鍏堢敱Loggers.Root.level鎴朙oggers.Logger.level鍒ゆ柇鏄惁杈撳嚭锛岀劧鍚庡啀鐢辨湰level鍒ゆ柇鏄惁杈撳嚭 - onMatch: ACCEPT #onMatch=ACCEPT 澶т簬绛変簬 "level" 閰嶇疆鐨勭瓑绾у湴鏃ュ織杈撳嚭 - onMismatch: DENY #onMismatch=DENY 灏忎簬 "level" 閰嶇疆鐨勭瓑绾у湴鏃ュ織涓嶈緭鍑� - #鏃ュ織鍐呭鏍峰紡 - PatternLayout: - pattern: "%d{yyyy-MM-dd HH:mm:ss,SSS}:%4p %t (%C.%M:%L) - %m%n" - Policies: - SizeBasedTriggeringPolicy: - size: "10 MB" - DefaultRolloverStrategy: - max: 1000 - - Loggers: - Root: - level: info #鏃ュ織杈撳嚭绾у埆锛屽叡鏈�8涓骇鍒紝鎸夌収浠庝綆鍒伴珮涓猴細all < trace < debug < info < warn < error < fatal < off - AppenderRef: #Root鐨勫瓙鑺傜偣锛岀敤鏉ユ寚瀹氳鏃ュ織杈撳嚭鍒板摢涓狝ppender. - - ref: CONSOLE #杈撳嚭鏃ュ織鏃讹紝棣栧厛鐢辨湰level鍒ゆ柇鏄惁杈撳嚭锛岀劧鍚庡啀鐢变笂闈㈢殑Appenders.Console.ThresholdFilter.level鍒ゆ柇鏄惁杈撳嚭 - - ref: ROLLING_FILE #杈撳嚭鏃ュ織鏃讹紝棣栧厛鐢辨湰level鍒ゆ柇鏄惁杈撳嚭锛岀劧鍚庡啀鐢变笂闈㈢殑Appenders.RollingFile.ThresholdFilter.level鍒ゆ柇鏄惁杈撳嚭 -- Gitblit v1.8.0