Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
tool
/
xxl-job
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit a466a6cf
authored
May 21, 2022
by
许雪里
Committed by
GitHub
May 21, 2022
Browse Files
Options
Browse Files
Tag
Download
Plain Diff
Merge pull request #2833 from cszxyang/polish_20220419
异常处理、日志处理及部分代码简单美化
2 parents
fbc02e57
d55068a5
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
28 deletions
xxl-job-core/src/main/java/com/xxl/job/core/executor/XxlJobExecutor.java
xxl-job-core/src/main/java/com/xxl/job/core/server/EmbedServer.java
xxl-job-core/src/main/java/com/xxl/job/core/executor/XxlJobExecutor.java
View file @
a466a6c
...
@@ -83,6 +83,7 @@ public class XxlJobExecutor {
...
@@ -83,6 +83,7 @@ public class XxlJobExecutor {
// init executor-server
// init executor-server
initEmbedServer
(
address
,
ip
,
port
,
appname
,
accessToken
);
initEmbedServer
(
address
,
ip
,
port
,
appname
,
accessToken
);
}
}
public
void
destroy
(){
public
void
destroy
(){
// destroy executor-server
// destroy executor-server
stopEmbedServer
();
stopEmbedServer
();
...
@@ -131,6 +132,7 @@ public class XxlJobExecutor {
...
@@ -131,6 +132,7 @@ public class XxlJobExecutor {
}
}
}
}
}
}
public
static
List
<
AdminBiz
>
getAdminBizList
(){
public
static
List
<
AdminBiz
>
getAdminBizList
(){
return
adminBizList
;
return
adminBizList
;
}
}
...
@@ -251,6 +253,7 @@ public class XxlJobExecutor {
...
@@ -251,6 +253,7 @@ public class XxlJobExecutor {
return
newJobThread
;
return
newJobThread
;
}
}
public
static
JobThread
removeJobThread
(
int
jobId
,
String
removeOldReason
){
public
static
JobThread
removeJobThread
(
int
jobId
,
String
removeOldReason
){
JobThread
oldJobThread
=
jobThreadRepository
.
remove
(
jobId
);
JobThread
oldJobThread
=
jobThreadRepository
.
remove
(
jobId
);
if
(
oldJobThread
!=
null
)
{
if
(
oldJobThread
!=
null
)
{
...
@@ -261,9 +264,8 @@ public class XxlJobExecutor {
...
@@ -261,9 +264,8 @@ public class XxlJobExecutor {
}
}
return
null
;
return
null
;
}
}
public
static
JobThread
loadJobThread
(
int
jobId
){
public
static
JobThread
loadJobThread
(
int
jobId
){
JobThread
jobThread
=
jobThreadRepository
.
get
(
jobId
);
return
jobThreadRepository
.
get
(
jobId
);
return
jobThread
;
}
}
}
}
xxl-job-core/src/main/java/com/xxl/job/core/server/EmbedServer.java
View file @
a466a6c
...
@@ -36,10 +36,8 @@ public class EmbedServer {
...
@@ -36,10 +36,8 @@ public class EmbedServer {
public
void
start
(
final
String
address
,
final
int
port
,
final
String
appname
,
final
String
accessToken
)
{
public
void
start
(
final
String
address
,
final
int
port
,
final
String
appname
,
final
String
accessToken
)
{
executorBiz
=
new
ExecutorBizImpl
();
executorBiz
=
new
ExecutorBizImpl
();
thread
=
new
Thread
(
new
Runnable
()
{
thread
=
new
Thread
(
new
Runnable
()
{
@Override
@Override
public
void
run
()
{
public
void
run
()
{
// param
// param
EventLoopGroup
bossGroup
=
new
NioEventLoopGroup
();
EventLoopGroup
bossGroup
=
new
NioEventLoopGroup
();
EventLoopGroup
workerGroup
=
new
NioEventLoopGroup
();
EventLoopGroup
workerGroup
=
new
NioEventLoopGroup
();
...
@@ -61,8 +59,6 @@ public class EmbedServer {
...
@@ -61,8 +59,6 @@ public class EmbedServer {
throw
new
RuntimeException
(
"xxl-job, EmbedServer bizThreadPool is EXHAUSTED!"
);
throw
new
RuntimeException
(
"xxl-job, EmbedServer bizThreadPool is EXHAUSTED!"
);
}
}
});
});
try
{
try
{
// start server
// start server
ServerBootstrap
bootstrap
=
new
ServerBootstrap
();
ServerBootstrap
bootstrap
=
new
ServerBootstrap
();
...
@@ -92,11 +88,9 @@ public class EmbedServer {
...
@@ -92,11 +88,9 @@ public class EmbedServer {
future
.
channel
().
closeFuture
().
sync
();
future
.
channel
().
closeFuture
().
sync
();
}
catch
(
InterruptedException
e
)
{
}
catch
(
InterruptedException
e
)
{
if
(
e
instanceof
InterruptedException
)
{
logger
.
info
(
">>>>>>>>>>> xxl-job remoting server stop."
);
logger
.
info
(
">>>>>>>>>>> xxl-job remoting server stop."
);
}
else
{
}
catch
(
Exception
e
)
{
logger
.
error
(
">>>>>>>>>>> xxl-job remoting server error."
,
e
);
logger
.
error
(
">>>>>>>>>>> xxl-job remoting server error."
,
e
);
}
}
finally
{
}
finally
{
// stop
// stop
try
{
try
{
...
@@ -106,9 +100,7 @@ public class EmbedServer {
...
@@ -106,9 +100,7 @@ public class EmbedServer {
logger
.
error
(
e
.
getMessage
(),
e
);
logger
.
error
(
e
.
getMessage
(),
e
);
}
}
}
}
}
}
});
});
thread
.
setDaemon
(
true
);
// daemon, service jvm, user thread leave >>> daemon leave >>> jvm leave
thread
.
setDaemon
(
true
);
// daemon, service jvm, user thread leave >>> daemon leave >>> jvm leave
thread
.
start
();
thread
.
start
();
...
@@ -116,7 +108,7 @@ public class EmbedServer {
...
@@ -116,7 +108,7 @@ public class EmbedServer {
public
void
stop
()
throws
Exception
{
public
void
stop
()
throws
Exception
{
// destroy server thread
// destroy server thread
if
(
thread
!=
null
&&
thread
.
isAlive
())
{
if
(
thread
!=
null
&&
thread
.
isAlive
())
{
thread
.
interrupt
();
thread
.
interrupt
();
}
}
...
@@ -130,7 +122,7 @@ public class EmbedServer {
...
@@ -130,7 +122,7 @@ public class EmbedServer {
/**
/**
* netty_http
* netty_http
*
*
<p>
* Copy from : https://github.com/xuxueli/xxl-rpc
* Copy from : https://github.com/xuxueli/xxl-rpc
*
*
* @author xuxueli 2015-11-24 22:25:15
* @author xuxueli 2015-11-24 22:25:15
...
@@ -141,6 +133,7 @@ public class EmbedServer {
...
@@ -141,6 +133,7 @@ public class EmbedServer {
private
ExecutorBiz
executorBiz
;
private
ExecutorBiz
executorBiz
;
private
String
accessToken
;
private
String
accessToken
;
private
ThreadPoolExecutor
bizThreadPool
;
private
ThreadPoolExecutor
bizThreadPool
;
public
EmbedHttpServerHandler
(
ExecutorBiz
executorBiz
,
String
accessToken
,
ThreadPoolExecutor
bizThreadPool
)
{
public
EmbedHttpServerHandler
(
ExecutorBiz
executorBiz
,
String
accessToken
,
ThreadPoolExecutor
bizThreadPool
)
{
this
.
executorBiz
=
executorBiz
;
this
.
executorBiz
=
executorBiz
;
this
.
accessToken
=
accessToken
;
this
.
accessToken
=
accessToken
;
...
@@ -149,7 +142,6 @@ public class EmbedServer {
...
@@ -149,7 +142,6 @@ public class EmbedServer {
@Override
@Override
protected
void
channelRead0
(
final
ChannelHandlerContext
ctx
,
FullHttpRequest
msg
)
throws
Exception
{
protected
void
channelRead0
(
final
ChannelHandlerContext
ctx
,
FullHttpRequest
msg
)
throws
Exception
{
// request parse
// request parse
//final byte[] requestBytes = ByteBufUtil.getBytes(msg.content()); // byteBuf.toString(io.netty.util.CharsetUtil.UTF_8);
//final byte[] requestBytes = ByteBufUtil.getBytes(msg.content()); // byteBuf.toString(io.netty.util.CharsetUtil.UTF_8);
String
requestData
=
msg
.
content
().
toString
(
CharsetUtil
.
UTF_8
);
String
requestData
=
msg
.
content
().
toString
(
CharsetUtil
.
UTF_8
);
...
@@ -175,38 +167,38 @@ public class EmbedServer {
...
@@ -175,38 +167,38 @@ public class EmbedServer {
}
}
private
Object
process
(
HttpMethod
httpMethod
,
String
uri
,
String
requestData
,
String
accessTokenReq
)
{
private
Object
process
(
HttpMethod
httpMethod
,
String
uri
,
String
requestData
,
String
accessTokenReq
)
{
// valid
// valid
if
(
HttpMethod
.
POST
!=
httpMethod
)
{
if
(
HttpMethod
.
POST
!=
httpMethod
)
{
return
new
ReturnT
<
String
>(
ReturnT
.
FAIL_CODE
,
"invalid request, HttpMethod not support."
);
return
new
ReturnT
<
String
>(
ReturnT
.
FAIL_CODE
,
"invalid request, HttpMethod not support."
);
}
}
if
(
uri
==
null
||
uri
.
trim
().
length
()==
0
)
{
if
(
uri
==
null
||
uri
.
trim
().
length
()
==
0
)
{
return
new
ReturnT
<
String
>(
ReturnT
.
FAIL_CODE
,
"invalid request, uri-mapping empty."
);
return
new
ReturnT
<
String
>(
ReturnT
.
FAIL_CODE
,
"invalid request, uri-mapping empty."
);
}
}
if
(
accessToken
!=
null
if
(
accessToken
!=
null
&&
accessToken
.
trim
().
length
()
>
0
&&
accessToken
.
trim
().
length
()
>
0
&&
!
accessToken
.
equals
(
accessTokenReq
))
{
&&
!
accessToken
.
equals
(
accessTokenReq
))
{
return
new
ReturnT
<
String
>(
ReturnT
.
FAIL_CODE
,
"The access token is wrong."
);
return
new
ReturnT
<
String
>(
ReturnT
.
FAIL_CODE
,
"The access token is wrong."
);
}
}
// services mapping
// services mapping
try
{
try
{
if
(
"/beat"
.
equals
(
uri
))
{
switch
(
uri
)
{
case
"/beat"
:
return
executorBiz
.
beat
();
return
executorBiz
.
beat
();
}
else
if
(
"/idleBeat"
.
equals
(
uri
))
{
case
"/idleBeat"
:
IdleBeatParam
idleBeatParam
=
GsonTool
.
fromJson
(
requestData
,
IdleBeatParam
.
class
);
IdleBeatParam
idleBeatParam
=
GsonTool
.
fromJson
(
requestData
,
IdleBeatParam
.
class
);
return
executorBiz
.
idleBeat
(
idleBeatParam
);
return
executorBiz
.
idleBeat
(
idleBeatParam
);
}
else
if
(
"/run"
.
equals
(
uri
))
{
case
"/run"
:
TriggerParam
triggerParam
=
GsonTool
.
fromJson
(
requestData
,
TriggerParam
.
class
);
TriggerParam
triggerParam
=
GsonTool
.
fromJson
(
requestData
,
TriggerParam
.
class
);
return
executorBiz
.
run
(
triggerParam
);
return
executorBiz
.
run
(
triggerParam
);
}
else
if
(
"/kill"
.
equals
(
uri
))
{
case
"/kill"
:
KillParam
killParam
=
GsonTool
.
fromJson
(
requestData
,
KillParam
.
class
);
KillParam
killParam
=
GsonTool
.
fromJson
(
requestData
,
KillParam
.
class
);
return
executorBiz
.
kill
(
killParam
);
return
executorBiz
.
kill
(
killParam
);
}
else
if
(
"/log"
.
equals
(
uri
))
{
case
"/log"
:
LogParam
logParam
=
GsonTool
.
fromJson
(
requestData
,
LogParam
.
class
);
LogParam
logParam
=
GsonTool
.
fromJson
(
requestData
,
LogParam
.
class
);
return
executorBiz
.
log
(
logParam
);
return
executorBiz
.
log
(
logParam
);
}
else
{
default
:
return
new
ReturnT
<
String
>(
ReturnT
.
FAIL_CODE
,
"invalid request, uri-mapping("
+
uri
+
") not found."
);
return
new
ReturnT
<
String
>(
ReturnT
.
FAIL_CODE
,
"invalid request, uri-mapping("
+
uri
+
") not found."
);
}
}
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
logger
.
error
(
e
.
getMessage
(),
e
);
logger
.
error
(
e
.
getMessage
(),
e
);
...
@@ -261,6 +253,4 @@ public class EmbedServer {
...
@@ -261,6 +253,4 @@ public class EmbedServer {
// stop registry
// stop registry
ExecutorRegistryThread
.
getInstance
().
toStop
();
ExecutorRegistryThread
.
getInstance
().
toStop
();
}
}
}
}
Write
Preview
Markdown
is supported
Attach a file
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 post a comment