wuzeyu
2024-10-16 05c3f58d6561c89019532bdeb65365f8129504c3
pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/forTcp/TcpSessionCache.java
@@ -5,6 +5,7 @@
import java.util.*;
import java.util.Map.Entry;
import com.dy.common.mw.channel.tcp.TcpIoSessionAttrIdIsRtuAddr;
import com.dy.common.util.DateTime;
import org.apache.mina.core.session.IoSession;
@@ -121,6 +122,27 @@
         return tcpSe.protocolName ;
      }else{
         return null ;
      }
   }
   /**
    * 得到所有在线与离线数量统计
    * @return [0]=在线数量,[2]上线过,但当前离线的数量
    */
   public static Integer[] allOnLineStateStatistics(){
      synchronized (sessionTable){
         Integer[] arr = new Integer[]{0, 0} ;
         Iterator<Entry<String, TcpSession>> it = sessionTable.entrySet().iterator() ;
         Entry<String, TcpSession> entry = null ;
         while(it.hasNext()){
            entry = it.next() ;
            if(entry.getValue().ioSession.isConnected()){
               arr[0]++ ;
            }else{
               arr[1]++ ;
            }
         }
         return arr ;
      }
   }
   
@@ -250,6 +272,7 @@
               if(tcpSe.ioSession != null && tcpSe.ioSession.isConnected()){
                  if(now - tcpSe.lastUpDataTimeForOnlineCtrl > ServerProperties.disconnectedByNoUpDataMinutes){
                     tcpSe.ioSession.closeNow() ;
                     RtuLogDealer.log(entry.getKey(), "因较长时间未收上行数据,认为设备离线");
                  }
               }
            }