Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
熊鹏飞
/
xxljob220
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
f83346de
authored
Jul 28, 2017
by
xuxueli
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
调度中心API服务,Client端调用逻辑优化
parent
8e07d501
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
16 deletions
xxl-job-core/src/main/java/com/xxl/job/core/executor/XxlJobExecutor.java
xxl-job-core/src/main/java/com/xxl/job/core/thread/ExecutorRegistryThread.java
xxl-job-core/src/main/java/com/xxl/job/core/thread/TriggerCallbackThread.java
xxl-job-core/src/main/java/com/xxl/job/core/executor/XxlJobExecutor.java
View file @
f83346de
package
com
.
xxl
.
job
.
core
.
executor
;
import
com.xxl.job.core.biz.AdminBiz
;
import
com.xxl.job.core.biz.ExecutorBiz
;
import
com.xxl.job.core.biz.impl.ExecutorBizImpl
;
import
com.xxl.job.core.handler.IJobHandler
;
import
com.xxl.job.core.handler.annotation.JobHander
;
import
com.xxl.job.core.rpc.netcom.NetComClientProxy
;
import
com.xxl.job.core.rpc.netcom.NetComServerFactory
;
import
com.xxl.job.core.thread.ExecutorRegistryThread
;
import
com.xxl.job.core.thread.JobThread
;
...
...
@@ -17,6 +19,8 @@ import org.springframework.context.ApplicationEvent;
import
org.springframework.context.ApplicationListener
;
import
org.springframework.context.event.ContextClosedEvent
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.concurrent.ConcurrentHashMap
;
...
...
@@ -29,7 +33,7 @@ public class XxlJobExecutor implements ApplicationContextAware, ApplicationListe
private
String
ip
;
private
int
port
=
9999
;
private
String
appName
;
p
ublic
static
String
adminAddresses
;
p
rivate
String
adminAddresses
;
public
static
String
logPath
;
public
void
setIp
(
String
ip
)
{
...
...
@@ -48,9 +52,32 @@ public class XxlJobExecutor implements ApplicationContextAware, ApplicationListe
this
.
logPath
=
logPath
;
}
// ---------------------------------- admin-client ------------------------------------
private
static
List
<
AdminBiz
>
adminBizList
;
private
static
void
initAdminBizList
(
String
adminAddresses
)
throws
Exception
{
if
(
adminAddresses
!=
null
&&
adminAddresses
.
trim
().
length
()>
0
)
{
for
(
String
address:
adminAddresses
.
trim
().
split
(
","
))
{
if
(
address
!=
null
&&
address
.
trim
().
length
()>
0
)
{
String
addressUrl
=
address
.
concat
(
"/api"
);
AdminBiz
adminBiz
=
(
AdminBiz
)
new
NetComClientProxy
(
AdminBiz
.
class
,
addressUrl
).
getObject
();
if
(
adminBizList
==
null
)
{
adminBizList
=
new
ArrayList
<
AdminBiz
>();
}
adminBizList
.
add
(
adminBiz
);
}
}
}
}
public
static
List
<
AdminBiz
>
getAdminBizList
(){
return
adminBizList
;
}
// ---------------------------------- job server ------------------------------------
private
NetComServerFactory
serverFactory
=
new
NetComServerFactory
();
public
void
start
()
throws
Exception
{
// init admin-client
initAdminBizList
(
adminAddresses
);
// executor start
NetComServerFactory
.
putService
(
ExecutorBiz
.
class
,
new
ExecutorBizImpl
());
// rpc-service, base on jetty
serverFactory
.
start
(
port
,
ip
,
appName
);
...
...
xxl-job-core/src/main/java/com/xxl/job/core/thread/ExecutorRegistryThread.java
View file @
f83346de
...
...
@@ -5,7 +5,6 @@ import com.xxl.job.core.biz.model.RegistryParam;
import
com.xxl.job.core.biz.model.ReturnT
;
import
com.xxl.job.core.enums.RegistryConfig
;
import
com.xxl.job.core.executor.XxlJobExecutor
;
import
com.xxl.job.core.rpc.netcom.NetComClientProxy
;
import
com.xxl.job.core.util.IpUtil
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
...
...
@@ -32,7 +31,7 @@ public class ExecutorRegistryThread extends Thread {
logger
.
warn
(
">>>>>>>>>>>> xxl-job, executor registry config fail, appName is null."
);
return
;
}
if
(
XxlJobExecutor
.
adminAddresses
==
null
||
XxlJobExecutor
.
adminAddresses
.
trim
().
length
()==
0
)
{
if
(
XxlJobExecutor
.
getAdminBizList
()
==
null
)
{
logger
.
warn
(
">>>>>>>>>>>> xxl-job, executor registry config fail, adminAddresses is null."
);
return
;
}
...
...
@@ -49,15 +48,10 @@ public class ExecutorRegistryThread extends Thread {
@Override
public
void
run
()
{
while
(!
toStop
)
{
try
{
RegistryParam
registryParam
=
new
RegistryParam
(
RegistryConfig
.
RegistType
.
EXECUTOR
.
name
(),
appName
,
executorAddress
);
for
(
String
addressUrl:
XxlJobExecutor
.
adminAddresses
.
split
(
","
))
{
String
apiUrl
=
addressUrl
.
concat
(
"/api"
);
for
(
AdminBiz
adminBiz:
XxlJobExecutor
.
getAdminBizList
())
{
try
{
AdminBiz
adminBiz
=
(
AdminBiz
)
new
NetComClientProxy
(
AdminBiz
.
class
,
apiUrl
).
getObject
();
ReturnT
<
String
>
registryResult
=
adminBiz
.
registry
(
registryParam
);
if
(
registryResult
!=
null
&&
ReturnT
.
SUCCESS_CODE
==
registryResult
.
getCode
())
{
registryResult
=
ReturnT
.
SUCCESS
;
...
...
@@ -71,7 +65,6 @@ public class ExecutorRegistryThread extends Thread {
}
}
}
catch
(
Exception
e
)
{
logger
.
error
(
e
.
getMessage
(),
e
);
}
...
...
xxl-job-core/src/main/java/com/xxl/job/core/thread/TriggerCallbackThread.java
View file @
f83346de
...
...
@@ -4,7 +4,6 @@ import com.xxl.job.core.biz.AdminBiz;
import
com.xxl.job.core.biz.model.HandleCallbackParam
;
import
com.xxl.job.core.biz.model.ReturnT
;
import
com.xxl.job.core.executor.XxlJobExecutor
;
import
com.xxl.job.core.rpc.netcom.NetComClientProxy
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
...
...
@@ -43,17 +42,14 @@ public class TriggerCallbackThread {
callbackParamList
.
add
(
callback
);
// valid
if
(
XxlJobExecutor
.
adminAddresses
==
null
||
XxlJobExecutor
.
adminAddresses
.
trim
().
length
()==
0
)
{
if
(
XxlJobExecutor
.
getAdminBizList
()==
null
)
{
logger
.
warn
(
">>>>>>>>>>>> xxl-job callback fail, adminAddresses is null, callbackParamList:{}"
,
callbackParamList
);
continue
;
}
// callback, will retry if error
for
(
String
addressUrl:
XxlJobExecutor
.
adminAddresses
.
split
(
","
))
{
String
apiUrl
=
addressUrl
.
concat
(
"/api"
);
for
(
AdminBiz
adminBiz:
XxlJobExecutor
.
getAdminBizList
())
{
try
{
AdminBiz
adminBiz
=
(
AdminBiz
)
new
NetComClientProxy
(
AdminBiz
.
class
,
apiUrl
).
getObject
();
ReturnT
<
String
>
callbackResult
=
adminBiz
.
callback
(
callbackParamList
);
if
(
callbackResult
!=
null
&&
ReturnT
.
SUCCESS_CODE
==
callbackResult
.
getCode
())
{
callbackResult
=
ReturnT
.
SUCCESS
;
...
...
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