|  |  | 
 |  |  |  | 
 |  |  | import java.net.InetAddress; | 
 |  |  | import java.net.InetSocketAddress; | 
 |  |  | import java.util.ArrayList; | 
 |  |  | import java.util.HashMap; | 
 |  |  | import java.util.Iterator; | 
 |  |  | import java.util.List; | 
 |  |  | import java.util.*; | 
 |  |  | import java.util.Map.Entry; | 
 |  |  |  | 
 |  |  | import com.dy.common.util.DateTime; | 
 |  |  | import org.apache.mina.core.session.IoSession; | 
 |  |  |  | 
 |  |  | import com.dy.rtuMw.server.ServerProperties; | 
 |  |  | 
 |  |  |       TcpSession tcpSe = sessionTable.get(rtuAddr) ; | 
 |  |  |       if(tcpSe != null){ | 
 |  |  |          tcpSe.lastUpDataTime = System.currentTimeMillis() ; | 
 |  |  |          tcpSe.lastUpDataTimeForOnlineCtrl = System.currentTimeMillis() ; | 
 |  |  |       } | 
 |  |  |    } | 
 |  |  |     | 
 |  |  |    /** | 
 |  |  |     * 更新上行数据时刻 | 
 |  |  |     * 当上行数据时刻已经过去一定时长,上行数据时刻清空 | 
 |  |  |     * 当一定时间内没有上行数据,则认为RTU离线 | 
 |  |  |     */ | 
 |  |  |    public static void updateUpDataTime(Long now){ | 
 |  |  |    public static void updateRtuStatus(Long now){ | 
 |  |  |       synchronized (sessionTable){ | 
 |  |  |          Iterator<TcpSession> it = sessionTable.values().iterator() ; | 
 |  |  |          Set<Map.Entry<String, TcpSession>> entrySet = sessionTable.entrySet() ; | 
 |  |  |          Iterator<Map.Entry<String, TcpSession>> it = entrySet.iterator() ; | 
 |  |  |          Map.Entry<String, TcpSession> entry ; | 
 |  |  |          TcpSession tcpSe ; | 
 |  |  |          while(it.hasNext()){ | 
 |  |  |             tcpSe = it.next() ; | 
 |  |  |             entry = it.next() ; | 
 |  |  |             tcpSe = entry.getValue(); | 
 |  |  |             if(tcpSe.lastUpDataTime != null){ | 
 |  |  |                if(now - tcpSe.lastUpDataTime > ServerProperties.lastUpDataTimeLive){ | 
 |  |  |                   tcpSe.lastUpDataTime = null ; | 
 |  |  |                } | 
 |  |  |             } | 
 |  |  |             if(tcpSe.lastUpDataTimeForOnlineCtrl != null){ | 
 |  |  |                if(tcpSe.ioSession != null && tcpSe.ioSession.isConnected()){ | 
 |  |  |                   if(now - tcpSe.lastUpDataTimeForOnlineCtrl > ServerProperties.disconnectedByNoUpDataMinutes){ | 
 |  |  |                      tcpSe.ioSession.closeNow() ; | 
 |  |  |                   } | 
 |  |  |                } | 
 |  |  |             } | 
 |  |  |          } | 
 |  |  |       } | 
 |  |  |    } | 
 |  |  |  | 
 |  |  | //   public static void updateRtuStatus(Long now){ | 
 |  |  | //      synchronized (sessionTable){ | 
 |  |  | //         Iterator<TcpSession> it = sessionTable.values().iterator() ; | 
 |  |  | //         TcpSession tcpSe ; | 
 |  |  | //         while(it.hasNext()){ | 
 |  |  | //            tcpSe = it.next() ; | 
 |  |  | //            if(tcpSe.lastUpDataTime != null){ | 
 |  |  | //               if(now - tcpSe.lastUpDataTime > ServerProperties.lastUpDataTimeLive){ | 
 |  |  | //                  tcpSe.lastUpDataTime = null ; | 
 |  |  | //               } | 
 |  |  | //            } | 
 |  |  | //         } | 
 |  |  | //      } | 
 |  |  | //   } | 
 |  |  |  | 
 |  |  |  | 
 |  |  | } |