|
|
|
|
@ -83,9 +83,12 @@ public class Jtt1078Handler extends SimpleChannelInboundHandler<Packet> { |
|
|
|
|
@Override |
|
|
|
|
public void channelInactive(ChannelHandlerContext ctx) { |
|
|
|
|
try { |
|
|
|
|
logger.info(BusinessConstant.LOGGER_PREFIX + " : 连接断开触发 channelInactive : channelId = {} ", ctx.channel() == null ? "null" : ctx.channel().id().asLongText()); |
|
|
|
|
super.channelInactive(ctx); |
|
|
|
|
release(ctx.channel()); |
|
|
|
|
String tag = SessionManager.get(ctx.channel(), "tag"); |
|
|
|
|
if (tag != null) { |
|
|
|
|
logger.info(BusinessConstant.LOGGER_PREFIX + " : 连接断开触发 channelInactive : tag = {} : channelId = {} ", tag, ctx.channel().id().asLongText()); |
|
|
|
|
super.channelInactive(ctx); |
|
|
|
|
release(ctx.channel()); |
|
|
|
|
} |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
logger.error(e.getMessage()); |
|
|
|
|
} |
|
|
|
|
@ -100,11 +103,13 @@ public class Jtt1078Handler extends SimpleChannelInboundHandler<Packet> { |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { |
|
|
|
|
logger.info(BusinessConstant.LOGGER_PREFIX + " : 连接异常触发 exceptionCaught : channelId = {} ", ctx.channel() == null ? "null" : ctx.channel().id().asLongText()); |
|
|
|
|
|
|
|
|
|
cause.printStackTrace(); |
|
|
|
|
release(ctx.channel()); |
|
|
|
|
ctx.close(); |
|
|
|
|
String tag = SessionManager.get(ctx.channel(), "tag"); |
|
|
|
|
if (tag != null) { |
|
|
|
|
logger.info(BusinessConstant.LOGGER_PREFIX + " : 连接异常触发 exceptionCaught : tag = {} : channelId = {} ", tag, ctx.channel().id().asLongText()); |
|
|
|
|
cause.printStackTrace(); |
|
|
|
|
release(ctx.channel()); |
|
|
|
|
ctx.close(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
@ -116,7 +121,7 @@ public class Jtt1078Handler extends SimpleChannelInboundHandler<Packet> { |
|
|
|
|
|
|
|
|
|
// 只有当该超时的连接已存在时, 打印超时日志, 防止重复打印
|
|
|
|
|
if (tag != null) { |
|
|
|
|
logger.info(BusinessConstant.LOGGER_PREFIX + " : 连接超时 userEventTriggered : channelId = {} : tag = {}", ctx.channel() == null ? "null" : ctx.channel().id().asLongText(), tag); |
|
|
|
|
logger.info(BusinessConstant.LOGGER_PREFIX + " : 连接超时 userEventTriggered : tag = {} : channelId = {} ", ctx.channel() == null ? "null" : ctx.channel().id().asLongText(), tag); |
|
|
|
|
release(ctx.channel()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
@ -132,7 +137,7 @@ public class Jtt1078Handler extends SimpleChannelInboundHandler<Packet> { |
|
|
|
|
String tag = SessionManager.get(channel, "tag"); |
|
|
|
|
if (tag != null) { |
|
|
|
|
SessionManager.printMapping(); |
|
|
|
|
logger.info(BusinessConstant.LOGGER_PREFIX + " : release : channelId = {} : tag = {}, 调用close方法释放通道 ", channel.id(), tag); |
|
|
|
|
logger.info(BusinessConstant.LOGGER_PREFIX + " : release : tag = {} : channelId = {} : , 调用close方法释放通道 ", channel.id().asLongText(), tag); |
|
|
|
|
PublishManager.getInstance().close(tag); |
|
|
|
|
SessionManager.remove(channel); |
|
|
|
|
} |
|
|
|
|
|