Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wecloud_im_server
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hewei
wecloud_im_server
Commits
548b4514
Commit
548b4514
authored
Oct 18, 2021
by
giaogiao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化WsReadHandler
parent
fab8dc3d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
11 deletions
+10
-11
common/src/main/java/com/wecloud/im/netty/core/WsReadHandler.java
+10
-11
No files found.
common/src/main/java/com/wecloud/im/netty/core/WsReadHandler.java
View file @
548b4514
...
@@ -46,9 +46,9 @@ public class WsReadHandler extends SimpleChannelInboundHandler<TextWebSocketFram
...
@@ -46,9 +46,9 @@ public class WsReadHandler extends SimpleChannelInboundHandler<TextWebSocketFram
* io密集型任务配置尽可能多的线程数量
* io密集型任务配置尽可能多的线程数量
*/
*/
private
final
static
ExecutorService
TASK_THREAD_POOL_EXECUTOR
=
private
final
static
ExecutorService
TASK_THREAD_POOL_EXECUTOR
=
new
ThreadPoolExecutor
(
WsConstants
.
CPU_PROCESSORS
*
5
,
WsConstants
.
CPU_PROCESSORS
*
5
0
,
new
ThreadPoolExecutor
(
WsConstants
.
CPU_PROCESSORS
*
5
,
WsConstants
.
CPU_PROCESSORS
*
1
0
,
3
L
,
TimeUnit
.
MILLISECONDS
,
10
L
,
TimeUnit
.
MILLISECONDS
,
new
LinkedBlockingQueue
<
Runnable
>(
1
),
NAMED_THREAD_FACTORY
,
new
ThreadPoolExecutor
.
CallerRunsPolicy
());
new
LinkedBlockingQueue
<
Runnable
>(
1
0
),
NAMED_THREAD_FACTORY
,
new
ThreadPoolExecutor
.
CallerRunsPolicy
());
@Override
@Override
protected
void
channelRead0
(
ChannelHandlerContext
ctx
,
TextWebSocketFrame
msg
)
{
protected
void
channelRead0
(
ChannelHandlerContext
ctx
,
TextWebSocketFrame
msg
)
{
...
@@ -92,7 +92,7 @@ public class WsReadHandler extends SimpleChannelInboundHandler<TextWebSocketFram
...
@@ -92,7 +92,7 @@ public class WsReadHandler extends SimpleChannelInboundHandler<TextWebSocketFram
readWsData
.
convertModel
(
data
,
ctx
,
appKey
,
clientId
);
readWsData
.
convertModel
(
data
,
ctx
,
appKey
,
clientId
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
error
(
"系统繁忙data:"
+
data
+
",appKey:"
+
appKey
+
",clientId:"
+
clientId
+
log
.
error
(
"系统繁忙data:"
+
data
+
",appKey:"
+
appKey
+
",clientId:"
+
clientId
+
",channelId:"
+
ctx
.
channel
().
id
().
as
Short
Text
(),
e
);
",channelId:"
+
ctx
.
channel
().
id
().
as
Long
Text
(),
e
);
}
}
}
}
...
@@ -126,9 +126,8 @@ public class WsReadHandler extends SimpleChannelInboundHandler<TextWebSocketFram
...
@@ -126,9 +126,8 @@ public class WsReadHandler extends SimpleChannelInboundHandler<TextWebSocketFram
break
;
break
;
}
}
log
.
info
(
clientId
+
"超时事件:"
+
eventType
);
log
.
info
(
clientId
+
"超时事件:"
+
eventType
);
if
(
readIdleTimes
>
5
)
{
if
(
readIdleTimes
>=
5
)
{
log
.
info
(
clientId
+
". [server]读空闲超过3次,关闭连接"
);
log
.
info
(
clientId
+
".读空闲超过5次关闭连接"
);
// ctx.channel().writeAndFlush("you are out");
ctx
.
channel
().
close
();
ctx
.
channel
().
close
();
}
}
}
}
...
@@ -144,13 +143,13 @@ public class WsReadHandler extends SimpleChannelInboundHandler<TextWebSocketFram
...
@@ -144,13 +143,13 @@ public class WsReadHandler extends SimpleChannelInboundHandler<TextWebSocketFram
// @Override
// @Override
// public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
// public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
// String userIdByChannel = mangerChannelService.getInfoByChannel(ctx);
// String userIdByChannel = mangerChannelService.getInfoByChannel(ctx);
// log.info("uid:" + userIdByChannel + ",ws异常,channelId:" + ctx.channel().id().as
Short
Text(), cause);
// log.info("uid:" + userIdByChannel + ",ws异常,channelId:" + ctx.channel().id().as
Long
Text(), cause);
// }
// }
@Override
@Override
public
void
handlerAdded
(
ChannelHandlerContext
ctx
)
{
public
void
handlerAdded
(
ChannelHandlerContext
ctx
)
{
String
userIdByChannel
=
mangerChannelService
.
getInfoByChannel
(
ctx
);
String
userIdByChannel
=
mangerChannelService
.
getInfoByChannel
(
ctx
);
log
.
info
(
"连接WS成功handlerAdded,uid:"
+
userIdByChannel
+
","
+
",channelId:"
+
ctx
.
channel
().
id
().
as
Short
Text
());
log
.
info
(
"连接WS成功handlerAdded,uid:"
+
userIdByChannel
+
","
+
",channelId:"
+
ctx
.
channel
().
id
().
as
Long
Text
());
}
}
...
@@ -163,7 +162,7 @@ public class WsReadHandler extends SimpleChannelInboundHandler<TextWebSocketFram
...
@@ -163,7 +162,7 @@ public class WsReadHandler extends SimpleChannelInboundHandler<TextWebSocketFram
// @Override
// @Override
// public void channelInactive(ChannelHandlerContext ctx) {
// public void channelInactive(ChannelHandlerContext ctx) {
// String userIdByChannel = mangerChannelService.getInfoByChannel(ctx);
// String userIdByChannel = mangerChannelService.getInfoByChannel(ctx);
// log.info("uid:" + userIdByChannel + "," + "channelInactive" + ",channelId:" + ctx.channel().id().as
Short
Text());
// log.info("uid:" + userIdByChannel + "," + "channelInactive" + ",channelId:" + ctx.channel().id().as
Long
Text());
// }
// }
/**
/**
...
@@ -172,7 +171,7 @@ public class WsReadHandler extends SimpleChannelInboundHandler<TextWebSocketFram
...
@@ -172,7 +171,7 @@ public class WsReadHandler extends SimpleChannelInboundHandler<TextWebSocketFram
@Override
@Override
public
void
handlerRemoved
(
ChannelHandlerContext
ctx
)
{
public
void
handlerRemoved
(
ChannelHandlerContext
ctx
)
{
String
userIdByChannel
=
mangerChannelService
.
getInfoByChannel
(
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
();
ctx
.
close
();
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment