Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
byit-myth-job
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
liyuan
byit-myth-job
Commits
36112506
Commit
36112506
authored
Apr 03, 2020
by
huangfusuper
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Netty服务端 异步实现修改
parent
d24f878a
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
74 additions
and
26 deletions
+74
-26
NettyPluginServer.java
...rver/src/main/java/com/byit/server/NettyPluginServer.java
+0
-26
NettyPluginServerHandler.java
...m/byit/server/netty/handler/NettyPluginServerHandler.java
+74
-0
No files found.
byit-plugin-core/myth-plugin-rpc-server/src/main/java/com/byit/server/NettyPluginServer.java
deleted
100644 → 0
View file @
d24f878a
package
com
.
byit
.
server
;
import
com.byit.factory.PluginServerFactory
;
/**
* Netty服务启动
* @author huangfu
*/
public
class
NettyPluginServer
extends
PluginServer
{
private
Thread
serverThread
;
@Override
public
void
start
(
PluginServerFactory
pluginServerFactory
)
{
serverThread
=
new
Thread
(()
->{
System
.
out
.
println
(
"-----com.byit.server.NettyPluginServer.start----"
);
});
serverThread
.
setName
(
"【com.byit.server.NettyPluginServer#start thread run】"
+
serverThread
.
hashCode
());
serverThread
.
setDaemon
(
true
);
serverThread
.
start
();
super
.
onStart
();
}
@Override
public
void
stop
()
{
System
.
out
.
println
(
"-----com.byit.server.NettyPluginServer.stop-----"
);
}
}
byit-plugin-core/myth-plugin-rpc-server/src/main/java/com/byit/server/netty/handler/NettyPluginServerHandler.java
0 → 100644
View file @
36112506
package
com
.
byit
.
server
.
netty
.
handler
;
import
com.byit.dto.web.ReturnResult
;
import
com.byit.enums.ResponseTyEnum
;
import
com.byit.executor.handler.interfaces.IJobHandler
;
import
com.byit.factory.PluginServerFactory
;
import
com.byit.packet.request.PluginRpcRequestPacket
;
import
com.byit.packet.response.PluginRpcResponsePacket
;
import
io.netty.channel.ChannelHandlerContext
;
import
io.netty.channel.SimpleChannelInboundHandler
;
import
java.util.Map
;
import
java.util.concurrent.ThreadPoolExecutor
;
/**
* netty rpc服务器的业务处理
* @author huangfu
*/
public
class
NettyPluginServerHandler
extends
SimpleChannelInboundHandler
<
PluginRpcRequestPacket
>
{
private
PluginServerFactory
pluginServerFactory
;
private
ThreadPoolExecutor
threadPoolExecutor
;
public
NettyPluginServerHandler
(
PluginServerFactory
pluginServerFactory
,
ThreadPoolExecutor
threadPoolExecutor
)
{
this
.
pluginServerFactory
=
pluginServerFactory
;
this
.
threadPoolExecutor
=
threadPoolExecutor
;
}
@Override
protected
void
channelRead0
(
ChannelHandlerContext
ctx
,
PluginRpcRequestPacket
msg
)
throws
Exception
{
PluginRpcResponsePacket
transferPluginRpcResponse
=
new
PluginRpcResponsePacket
();
threadPoolExecutor
.
execute
(()->{
PluginRpcResponsePacket
rpcResponsePacket
=
new
PluginRpcResponsePacket
();
try
{
Map
<
String
,
Object
>
serverPoll
=
pluginServerFactory
.
getServerPoll
();
String
jobName
=
msg
.
getJobName
();
Object
bean
=
serverPoll
.
get
(
jobName
);
IJobHandler
iJobHandler
=
(
IJobHandler
)
bean
;
ReturnResult
<
String
>
execute
=
iJobHandler
.
execute
(
msg
.
getParam
());
rpcResponsePacket
.
setResult
(
execute
);
rpcResponsePacket
.
setCode
(
"000000"
);
rpcResponsePacket
.
setMsg
(
"SUCCESS"
);
rpcResponsePacket
.
setStatus
(
true
);
rpcResponsePacket
.
setExtension
(
msg
.
getExtension
());
}
catch
(
Exception
e
){
rpcResponsePacket
.
setCode
(
"500000"
);
rpcResponsePacket
.
setMsg
(
e
.
getMessage
());
rpcResponsePacket
.
setStatus
(
false
);
rpcResponsePacket
.
setExtension
(
msg
.
getExtension
());
}
rpcResponsePacket
.
setType
(
ResponseTyEnum
.
RESPONSE
.
getType
());
ctx
.
channel
().
writeAndFlush
(
rpcResponsePacket
);
});
transferPluginRpcResponse
.
setStatus
(
true
);
transferPluginRpcResponse
.
setMsg
(
"调用成功"
);
transferPluginRpcResponse
.
setExtension
(
msg
.
getExtension
());
transferPluginRpcResponse
.
setType
(
ResponseTyEnum
.
TRANSFER
.
getType
());
ctx
.
channel
().
writeAndFlush
(
transferPluginRpcResponse
);
}
/**
* 异常处理
* @param ctx 上下文对象
* @param cause 异常对象
* @throws Exception 异常信息
*/
@Override
public
void
exceptionCaught
(
ChannelHandlerContext
ctx
,
Throwable
cause
)
throws
Exception
{
cause
.
printStackTrace
();
ctx
.
close
();
}
//TODO 心跳检测功能暂时不添加
}
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