作者 crossoverJie

:sparkles: Introducing new features.服务端下线逻辑优化

... ... @@ -34,9 +34,11 @@ public class RouteHandler {
* @throws IOException
*/
public void userOffLine(CIMUserInfo userInfo, NioSocketChannel channel) throws IOException {
LOGGER.info("用户[{}]下线", userInfo.getUserName());
if (userInfo != null){
LOGGER.info("用户[{}]下线", userInfo.getUserName());
SessionSocketHolder.removeSession(userInfo.getUserId());
}
SessionSocketHolder.remove(channel);
SessionSocketHolder.removeSession(userInfo.getUserId());
//清除路由关系
clearRouteInfo(userInfo);
... ...
... ... @@ -39,7 +39,9 @@ public class ServerHeartBeatHandlerImpl implements HeartBeatHandler {
long now = System.currentTimeMillis();
if (lastReadTime != null && now - lastReadTime > heartBeatTime){
CIMUserInfo userInfo = SessionSocketHolder.getUserId((NioSocketChannel) ctx.channel());
LOGGER.warn("客户端[{}]心跳超时[{}]ms,需要关闭连接!",userInfo.getUserName(),now - lastReadTime);
if (userInfo != null){
LOGGER.warn("客户端[{}]心跳超时[{}]ms,需要关闭连接!",userInfo.getUserName(),now - lastReadTime);
}
routeHandler.userOffLine(userInfo, (NioSocketChannel) ctx.channel());
ctx.channel().close();
}
... ...