| | |
| | | import java.util.*; |
| | | import java.util.Map.Entry; |
| | | |
| | | import com.dy.common.mw.channel.tcp.TcpIoSessionAttrIdIsRtuAddr; |
| | | import org.apache.mina.core.session.IoSession; |
| | | |
| | | import com.dy.rtuMw.server.ServerProperties; |
| | |
| | | /** |
| | | * 加入新的IoSession |
| | | * @param rtuAddr |
| | | * @param protocolName |
| | | * @param ioSession |
| | | */ |
| | | public static void putNewTcpSession(String rtuAddr, String protocolName, Short protocolVersion, IoSession ioSession){ |
| | | //public static void putNewTcpSession(String rtuAddr, String protocolName, Short protocolVersion, IoSession ioSession){ |
| | | public static void putNewTcpSession(String rtuAddr, IoSession ioSession){ |
| | | synchronized (map){ |
| | | TcpSession tcpSe = map.get(rtuAddr) ; |
| | | if(tcpSe == null){ |
| | | tcpSe = new TcpSession() ; |
| | | tcpSe.protocolName = protocolName ; |
| | | tcpSe.protocolVersion = protocolVersion ; |
| | | //tcpSe.protocolName = protocolName ; |
| | | //tcpSe.protocolVersion = protocolVersion ; |
| | | tcpSe.ioSession = ioSession ; |
| | | map.put(rtuAddr, tcpSe) ; |
| | | }else{ |
| | |
| | | * 更新IoSession对应的rtuAddr |
| | | * @param oldRtuAddr |
| | | * @param newRtuAddr |
| | | * @param protocolName |
| | | * @param protocolVersion |
| | | * @param ioSession |
| | | */ |
| | | public static void changeRtuAddr(String oldRtuAddr, String newRtuAddr, String protocolName, Short protocolVersion, IoSession ioSession){ |
| | | //public static void changeRtuAddr(String oldRtuAddr, String newRtuAddr, String protocolName, Short protocolVersion, IoSession ioSession){ |
| | | public static void changeRtuAddr(String oldRtuAddr, String newRtuAddr, IoSession ioSession){ |
| | | if(oldRtuAddr != null && newRtuAddr != null && !oldRtuAddr.equals(newRtuAddr)){ |
| | | synchronized (map){ |
| | | TcpSession tcpSe = map.get(oldRtuAddr) ; |
| | | if(tcpSe == null){ |
| | | putNewTcpSession(newRtuAddr, protocolName, protocolVersion, ioSession) ; |
| | | putNewTcpSession(newRtuAddr, ioSession) ; |
| | | }else{ |
| | | map.remove(oldRtuAddr) ; |
| | | map.put(newRtuAddr, tcpSe) ; |
| | |
| | | * 得到Tcp通信协议名称 |
| | | * @param rtuAddr |
| | | * @return |
| | | |
| | | public static String getTcpProtocolName(String rtuAddr){ |
| | | TcpSession tcpSe = sessionTable.get(rtuAddr) ; |
| | | if(tcpSe != null){ |
| | |
| | | * 得到Tcp通信协议名称 |
| | | * @param rtuAddr |
| | | * @return |
| | | */ |
| | | * */ |
| | | public static Object[] getTcpProtocolNameVersion(String rtuAddr){ |
| | | TcpSession tcpSe = map.get(rtuAddr) ; |
| | | if(tcpSe != null){ |
| | | return new Object[]{tcpSe.protocolName, tcpSe.protocolVersion}; |
| | | return new Object[]{ |
| | | tcpSe.ioSession.getAttribute(TcpIoSessionAttrIdIsRtuAddr.sessionArrProtocolName), |
| | | tcpSe.ioSession.getAttribute(TcpIoSessionAttrIdIsRtuAddr.sessionArrProtocolVersion)}; |
| | | }else{ |
| | | return null ; |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 得到所有在线与离线数量统计 |
| | | * @return [0]=在线数量,[2]上线过,但当前离线的数量 |