Commit 548b4514 by giaogiao

优化WsReadHandler

parent fab8dc3d
......@@ -46,9 +46,9 @@ public class WsReadHandler extends SimpleChannelInboundHandler<TextWebSocketFram
* io密集型任务配置尽可能多的线程数量
*/
private final static ExecutorService TASK_THREAD_POOL_EXECUTOR =
new ThreadPoolExecutor(WsConstants.CPU_PROCESSORS * 5, WsConstants.CPU_PROCESSORS * 50,
3L, TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<Runnable>(1), NAMED_THREAD_FACTORY, new ThreadPoolExecutor.CallerRunsPolicy());
new ThreadPoolExecutor(WsConstants.CPU_PROCESSORS * 5, WsConstants.CPU_PROCESSORS * 10,
10L, TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<Runnable>(10), NAMED_THREAD_FACTORY, new ThreadPoolExecutor.CallerRunsPolicy());
@Override
protected void channelRead0(ChannelHandlerContext ctx, TextWebSocketFrame msg) {
......@@ -92,7 +92,7 @@ public class WsReadHandler extends SimpleChannelInboundHandler<TextWebSocketFram
readWsData.convertModel(data, ctx, appKey, clientId);
} catch (Exception e) {
log.error("系统繁忙data:" + data + ",appKey:" + appKey + ",clientId:" + clientId +
",channelId:" + ctx.channel().id().asShortText(), e);
",channelId:" + ctx.channel().id().asLongText(), e);
}
}
......@@ -126,9 +126,8 @@ public class WsReadHandler extends SimpleChannelInboundHandler<TextWebSocketFram
break;
}
log.info(clientId + "超时事件:" + eventType);
if (readIdleTimes > 5) {
log.info(clientId + ". [server]读空闲超过3次,关闭连接");
// ctx.channel().writeAndFlush("you are out");
if (readIdleTimes >= 5) {
log.info(clientId + ".读空闲超过5次关闭连接");
ctx.channel().close();
}
}
......@@ -144,13 +143,13 @@ public class WsReadHandler extends SimpleChannelInboundHandler<TextWebSocketFram
// @Override
// public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
// String userIdByChannel = mangerChannelService.getInfoByChannel(ctx);
// log.info("uid:" + userIdByChannel + ",ws异常,channelId:" + ctx.channel().id().asShortText(), cause);
// log.info("uid:" + userIdByChannel + ",ws异常,channelId:" + ctx.channel().id().asLongText(), cause);
// }
@Override
public void handlerAdded(ChannelHandlerContext ctx) {
String userIdByChannel = mangerChannelService.getInfoByChannel(ctx);
log.info("连接WS成功handlerAdded,uid:" + userIdByChannel + "," + ",channelId:" + ctx.channel().id().asShortText());
log.info("连接WS成功handlerAdded,uid:" + userIdByChannel + "," + ",channelId:" + ctx.channel().id().asLongText());
}
......@@ -163,7 +162,7 @@ public class WsReadHandler extends SimpleChannelInboundHandler<TextWebSocketFram
// @Override
// public void channelInactive(ChannelHandlerContext ctx) {
// String userIdByChannel = mangerChannelService.getInfoByChannel(ctx);
// log.info("uid:" + userIdByChannel + "," + "channelInactive" + ",channelId:" + ctx.channel().id().asShortText());
// log.info("uid:" + userIdByChannel + "," + "channelInactive" + ",channelId:" + ctx.channel().id().asLongText());
// }
/**
......@@ -172,7 +171,7 @@ public class WsReadHandler extends SimpleChannelInboundHandler<TextWebSocketFram
@Override
public void handlerRemoved(ChannelHandlerContext ctx) {
String userIdByChannel = mangerChannelService.getInfoByChannel(ctx);
log.info("uid:" + userIdByChannel + "," + "handlerRemoved" + ",channelId:" + ctx.channel().id());
log.info("uid:" + userIdByChannel + "," + "handlerRemoved" + ",channelId:" + ctx.channel().id().asLongText());
// 关掉连接
ctx.close();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment