From 7f5d914898c9d05942705ce7d80c0d14a8174df8 Mon Sep 17 00:00:00 2001 From: liurunyu <lry9898@163.com> Date: 星期二, 19 十二月 2023 15:57:14 +0800 Subject: [PATCH] 1、common模块优化代码; 2、通信中间件优化代码,队列遍历由递归调用改为while循环,原因是队列数据量大时递归调易产生栈溢出,HashTable多线程应用时仍有线程安全问题,改为HashMap+同步锁; 3、RTU模拟器和模拟器控制服务增加report命令 --- pipIrr-platform/pipIrr-mw/pipIrr-mw-accept/src/main/java/com/dy/aceMw/server/tasks/ToRtuConstantTask.java | 69 ++++++++++++++++++++++++++++------ 1 files changed, 56 insertions(+), 13 deletions(-) diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mw-accept/src/main/java/com/dy/aceMw/server/tasks/ToRtuConstantTask.java b/pipIrr-platform/pipIrr-mw/pipIrr-mw-accept/src/main/java/com/dy/aceMw/server/tasks/ToRtuConstantTask.java index 291184a..c9b84d6 100644 --- a/pipIrr-platform/pipIrr-mw/pipIrr-mw-accept/src/main/java/com/dy/aceMw/server/tasks/ToRtuConstantTask.java +++ b/pipIrr-platform/pipIrr-mw/pipIrr-mw-accept/src/main/java/com/dy/aceMw/server/tasks/ToRtuConstantTask.java @@ -7,7 +7,7 @@ import com.dy.common.mw.core.CoreTask; import com.dy.aceMw.server.forTcp.TcpDownCommandCache; import com.dy.aceMw.server.forTcp.TcpDownCommandObj; -import com.dy.aceMw.server.forTcp.TcpSessionCach; +import com.dy.aceMw.server.forTcp.TcpSessionCache; /** * 澶勭悊RTU涓嬭鍛戒护鏁版嵁鐨勬亽涔呬换鍔� @@ -19,26 +19,70 @@ * 鍦ㄥ崟绾跨▼鐜涓繍琛� */ @Override - public Integer excute() { + public Integer execute() { try{ - Long now = System.currentTimeMillis() ; - dealTcpSession(now) ; - return dealDownCommand(now) ; + dealTcpSession() ; + }catch(Exception e){ + log.error("鏇存柊RTU浼氳瘽涓婃姤鏁版嵁鏃跺埢鏃跺彂鐢熼泦鍚堟搷浣滃紓甯革紝姝ゅ紓甯稿苟涓嶅奖鍝嶇郴缁熸甯歌繍琛�", e); + } + try{ + dealDownCom() ; }catch(Exception e){ log.error(e); } - return null ; + return TcpDownCommandCache.size()>0?0:1 ; } /** * 澶勭悊TCP缂撳瓨涓殑鍚勪釜TCP Session鐨勪笂琛屾暟鎹椂鍒� */ - private void dealTcpSession(Long now){ - TcpSessionCach.updateUpDataTime(now) ; + private void dealTcpSession(){ + TcpSessionCache.updateUpDataTime(System.currentTimeMillis() ) ; } - + + /** * 澶勭悊涓嬭鍛戒护 */ + public void dealDownCom() { + Node first = TcpDownCommandCache.getFirstQueueNode() ; + if(first != null){ + Node last = TcpDownCommandCache.getLastQueueNode() ; + while (last != null){ + last = this.doDealDownComm(System.currentTimeMillis(), first, last); + } + } + } + /** + * 澶勭悊缂撳瓨鐨勪笅琛屽懡浠よ妭鐐� + * @param now 褰撳墠鏃跺埢 + * @param first 绗竴涓妭鐐� + * @param last 鏈�鍚庝竴涓妭鐐� + */ + private Node doDealDownComm(Long now, Node first, Node last){ + if(last != null){ + if(first != last){ + //鍦╠ealNode鏂规硶涓紝鍙兘瑕佹妸last浠庨槦鍒椾腑绉婚櫎锛岃繖鏃秎ast.pre涓虹┖锛屾墍浠ユ彁鍓嶆妸last.pre鍙栧嚭鏉� + Node pre = last.pre ; + dealNode(now, last) ; + return pre ; + }else{ + //鍋滄 + return null ; + } + }else{ + return null ; + } + } + + + + //////////////////////////////////////////////// + // + //浠ヤ笅瀹炵幇锛岄噰鐢ㄤ簡閫掑綊璋冪敤锛屽綋闃熷垪缂撳瓨缁撶偣寰堝鏃讹紝浼氫骇鐢熸爤婧㈠嚭寮傚父 + // + //////////////////////////////////////////////// + /** + * 澶勭悊涓嬭鍛戒护 public Integer dealDownCommand(Long now) { Node first = TcpDownCommandCache.getFirstQueueNode() ; if(first != null){ @@ -49,12 +93,12 @@ } return null ; } + */ /** * 澶勭悊缂撳瓨鐨勪笅琛屽懡浠よ妭鐐� * @param now 褰撳墠鏃跺埢 * @param first 绗竴涓妭鐐� * @param last 鏈�鍚庝竴涓妭鐐� - */ private void doDealDownCommand1(Long now, Node first, Node last){ if(first != null){ //鍦╠ealNode鏂规硶涓紝鍙兘瑕佹妸first浠庨槦鍒椾腑绉婚櫎锛岃繖鏃秄irst.next涓虹┖锛屾墍浠ユ彁鍓嶆妸first.next鍙栧嚭鏉� @@ -70,13 +114,12 @@ } } } - + */ /** * 澶勭悊缂撳瓨鐨勪笅琛屽懡浠よ妭鐐� * @param now 褰撳墠鏃跺埢 * @param first 绗竴涓妭鐐� * @param last 鏈�鍚庝竴涓妭鐐� - */ private void doDealDownCommand(Long now, Node first, Node last){ if(last != null){ //鍦╠ealNode鏂规硶涓紝鍙兘瑕佹妸last浠庨槦鍒椾腑绉婚櫎锛岃繖鏃秎ast.pre涓虹┖锛屾墍浠ユ彁鍓嶆妸last.pre鍙栧嚭鏉� @@ -92,7 +135,7 @@ } } } - + */ /** * 澶勭悊涓�涓妭鐐� * @param now 鐜板湪鏃跺埢 -- Gitblit v1.8.0