| | |
| | | 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下行命令数据的恒久任务 |
| | |
| | | * 在单线程环境中运行 |
| | | */ |
| | | @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){ |
| | | //在dealNode方法中,可能要把last从队列中移除,这时last.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){ |
| | |
| | | } |
| | | return null ; |
| | | } |
| | | */ |
| | | /** |
| | | * 处理缓存的下行命令节点 |
| | | * @param now 当前时刻 |
| | | * @param first 第一个节点 |
| | | * @param last 最后一个节点 |
| | | */ |
| | | private void doDealDownCommand1(Long now, Node first, Node last){ |
| | | if(first != null){ |
| | | //在dealNode方法中,可能要把first从队列中移除,这时first.next为空,所以提前把first.next取出来 |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | */ |
| | | /** |
| | | * 处理缓存的下行命令节点 |
| | | * @param now 当前时刻 |
| | | * @param first 第一个节点 |
| | | * @param last 最后一个节点 |
| | | */ |
| | | private void doDealDownCommand(Long now, Node first, Node last){ |
| | | if(last != null){ |
| | | //在dealNode方法中,可能要把last从队列中移除,这时last.pre为空,所以提前把last.pre取出来 |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | */ |
| | | /** |
| | | * 处理一个节点 |
| | | * @param now 现在时刻 |