|  |  |  | 
|---|
|  |  |  | TcpSession tcpSe = sessionTable.get(rtuAddr) ; | 
|---|
|  |  |  | if(tcpSe == null){ | 
|---|
|  |  |  | tcpSe = new TcpSession() ; | 
|---|
|  |  |  | tcpSe.protocolName = protocolName ; | 
|---|
|  |  |  | tcpSe.ioSession = ioSession ; | 
|---|
|  |  |  | sessionTable.put(rtuAddr, tcpSe) ; | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | 
|---|
|  |  |  | return sessionTable.get(rtuAddr) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 得到Tcp通信协议名称 | 
|---|
|  |  |  | * @param rtuAddr | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public static String getTcpProtocolName(String rtuAddr){ | 
|---|
|  |  |  | TcpSession tcpSe = sessionTable.get(rtuAddr) ; | 
|---|
|  |  |  | if(tcpSe != null){ | 
|---|
|  |  |  | return tcpSe.protocolName ; | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | return null ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 得到所有在线情况 | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | 
|---|
|  |  |  | * 得到所有RTU连接状态情况 | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public static List<RtuSessionStatus> allConnectStatus(){ | 
|---|
|  |  |  | List<RtuSessionStatus> list = new ArrayList<RtuSessionStatus>(); | 
|---|
|  |  |  | Iterator<Entry<String, TcpSession>> it = sessionTable.entrySet().iterator() ; | 
|---|
|  |  |  | Entry<String, TcpSession> entry = null ; | 
|---|
|  |  |  | while(it.hasNext()){ | 
|---|
|  |  |  | entry = it.next() ; | 
|---|
|  |  |  | RtuSessionStatus vo = new RtuSessionStatus() ; | 
|---|
|  |  |  | vo.rtuAddr = entry.getKey() ; | 
|---|
|  |  |  | IoSession se = entry.getValue().ioSession ; | 
|---|
|  |  |  | vo.onTrueOffLine = se.isConnected() ; | 
|---|
|  |  |  | InetSocketAddress sa = (InetSocketAddress)se.getRemoteAddress() ; | 
|---|
|  |  |  | if(sa != null){ | 
|---|
|  |  |  | InetAddress inetAddr = sa.getAddress() ; | 
|---|
|  |  |  | if(inetAddr != null){ | 
|---|
|  |  |  | vo.ip = inetAddr.getHostAddress() ; | 
|---|
|  |  |  | vo.port = sa.getPort() ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | list.add(vo) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return list ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //   public static List<RtuSessionStatus> allConnectStatus(){ | 
|---|
|  |  |  | //      List<RtuSessionStatus> list = new ArrayList<RtuSessionStatus>(); | 
|---|
|  |  |  | //      Iterator<Entry<String, TcpSession>> it = sessionTable.entrySet().iterator() ; | 
|---|
|  |  |  | //      Entry<String, TcpSession> entry = null ; | 
|---|
|  |  |  | //      while(it.hasNext()){ | 
|---|
|  |  |  | //         entry = it.next() ; | 
|---|
|  |  |  | //         RtuSessionStatus vo = new RtuSessionStatus() ; | 
|---|
|  |  |  | //         vo.rtuAddr = entry.getKey() ; | 
|---|
|  |  |  | //         IoSession se = entry.getValue().ioSession ; | 
|---|
|  |  |  | //         vo.onTrueOffLine = se.isConnected() ; | 
|---|
|  |  |  | //         InetSocketAddress sa = (InetSocketAddress)se.getRemoteAddress() ; | 
|---|
|  |  |  | //         if(sa != null){ | 
|---|
|  |  |  | //            InetAddress inetAddr = sa.getAddress() ; | 
|---|
|  |  |  | //            if(inetAddr != null){ | 
|---|
|  |  |  | //               vo.ip = inetAddr.getHostAddress() ; | 
|---|
|  |  |  | //               vo.port = sa.getPort() ; | 
|---|
|  |  |  | //            } | 
|---|
|  |  |  | //         } | 
|---|
|  |  |  | //         list.add(vo) ; | 
|---|
|  |  |  | //      } | 
|---|
|  |  |  | //      return list ; | 
|---|
|  |  |  | //   } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|