作者 crossoverJie

:sparkles: Introducing new features.心跳完善

@@ -41,10 +41,14 @@ public class CIMServerHandle extends SimpleChannelInboundHandler<CIMRequestProto @@ -41,10 +41,14 @@ public class CIMServerHandle extends SimpleChannelInboundHandler<CIMRequestProto
41 */ 41 */
42 @Override 42 @Override
43 public void channelInactive(ChannelHandlerContext ctx) throws Exception { 43 public void channelInactive(ChannelHandlerContext ctx) throws Exception {
  44 + //可能出现业务判断离线后再次触发 channelInactive
44 CIMUserInfo userInfo = SessionSocketHolder.getUserId((NioSocketChannel) ctx.channel()); 45 CIMUserInfo userInfo = SessionSocketHolder.getUserId((NioSocketChannel) ctx.channel());
  46 + if (userInfo != null){
  47 + LOGGER.warn("[{}]触发 channelInactive 掉线!",userInfo.getUserName());
45 userOffLine(userInfo, (NioSocketChannel) ctx.channel()); 48 userOffLine(userInfo, (NioSocketChannel) ctx.channel());
46 ctx.channel().close(); 49 ctx.channel().close();
47 } 50 }
  51 + }
48 52
49 @Override 53 @Override
50 public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { 54 public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
@@ -64,7 +68,7 @@ public class CIMServerHandle extends SimpleChannelInboundHandler<CIMRequestProto @@ -64,7 +68,7 @@ public class CIMServerHandle extends SimpleChannelInboundHandler<CIMRequestProto
64 long now = System.currentTimeMillis(); 68 long now = System.currentTimeMillis();
65 if (lastReadTime != null && now - lastReadTime > heartBeatTime){ 69 if (lastReadTime != null && now - lastReadTime > heartBeatTime){
66 CIMUserInfo userInfo = SessionSocketHolder.getUserId((NioSocketChannel) ctx.channel()); 70 CIMUserInfo userInfo = SessionSocketHolder.getUserId((NioSocketChannel) ctx.channel());
67 - LOGGER.warn("客户端[{}]心跳超时,需要关闭连接",userInfo.getUserName()); 71 + LOGGER.warn("客户端[{}]心跳超时[{}]ms,需要关闭连接!",userInfo.getUserName(),now - lastReadTime);
68 userOffLine(userInfo, (NioSocketChannel) ctx.channel()); 72 userOffLine(userInfo, (NioSocketChannel) ctx.channel());
69 ctx.channel().close(); 73 ctx.channel().close();
70 } 74 }