|
@@ -1,9 +1,11 @@
|
1
|
1
|
package com.xxl.job.core.executor;
|
2
|
2
|
|
|
3
|
+import com.xxl.job.core.biz.AdminBiz;
|
3
|
4
|
import com.xxl.job.core.biz.ExecutorBiz;
|
4
|
5
|
import com.xxl.job.core.biz.impl.ExecutorBizImpl;
|
5
|
6
|
import com.xxl.job.core.handler.IJobHandler;
|
6
|
7
|
import com.xxl.job.core.handler.annotation.JobHander;
|
|
8
|
+import com.xxl.job.core.rpc.netcom.NetComClientProxy;
|
7
|
9
|
import com.xxl.job.core.rpc.netcom.NetComServerFactory;
|
8
|
10
|
import com.xxl.job.core.thread.ExecutorRegistryThread;
|
9
|
11
|
import com.xxl.job.core.thread.JobThread;
|
|
@@ -17,6 +19,8 @@ import org.springframework.context.ApplicationEvent;
|
17
|
19
|
import org.springframework.context.ApplicationListener;
|
18
|
20
|
import org.springframework.context.event.ContextClosedEvent;
|
19
|
21
|
|
|
22
|
+import java.util.ArrayList;
|
|
23
|
+import java.util.List;
|
20
|
24
|
import java.util.Map;
|
21
|
25
|
import java.util.concurrent.ConcurrentHashMap;
|
22
|
26
|
|
|
@@ -29,7 +33,7 @@ public class XxlJobExecutor implements ApplicationContextAware, ApplicationListe
|
29
|
33
|
private String ip;
|
30
|
34
|
private int port = 9999;
|
31
|
35
|
private String appName;
|
32
|
|
- public static String adminAddresses;
|
|
36
|
+ private String adminAddresses;
|
33
|
37
|
public static String logPath;
|
34
|
38
|
|
35
|
39
|
public void setIp(String ip) {
|
|
@@ -48,9 +52,32 @@ public class XxlJobExecutor implements ApplicationContextAware, ApplicationListe
|
48
|
52
|
this.logPath = logPath;
|
49
|
53
|
}
|
50
|
54
|
|
|
55
|
+ // ---------------------------------- admin-client ------------------------------------
|
|
56
|
+ private static List<AdminBiz> adminBizList;
|
|
57
|
+ private static void initAdminBizList(String adminAddresses) throws Exception {
|
|
58
|
+ if (adminAddresses!=null && adminAddresses.trim().length()>0) {
|
|
59
|
+ for (String address: adminAddresses.trim().split(",")) {
|
|
60
|
+ if (address!=null && address.trim().length()>0) {
|
|
61
|
+ String addressUrl = address.concat("/api");
|
|
62
|
+ AdminBiz adminBiz = (AdminBiz) new NetComClientProxy(AdminBiz.class, addressUrl).getObject();
|
|
63
|
+ if (adminBizList == null) {
|
|
64
|
+ adminBizList = new ArrayList<AdminBiz>();
|
|
65
|
+ }
|
|
66
|
+ adminBizList.add(adminBiz);
|
|
67
|
+ }
|
|
68
|
+ }
|
|
69
|
+ }
|
|
70
|
+ }
|
|
71
|
+ public static List<AdminBiz> getAdminBizList(){
|
|
72
|
+ return adminBizList;
|
|
73
|
+ }
|
|
74
|
+
|
51
|
75
|
// ---------------------------------- job server ------------------------------------
|
52
|
76
|
private NetComServerFactory serverFactory = new NetComServerFactory();
|
53
|
77
|
public void start() throws Exception {
|
|
78
|
+ // init admin-client
|
|
79
|
+ initAdminBizList(adminAddresses);
|
|
80
|
+
|
54
|
81
|
// executor start
|
55
|
82
|
NetComServerFactory.putService(ExecutorBiz.class, new ExecutorBizImpl()); // rpc-service, base on jetty
|
56
|
83
|
serverFactory.start(port, ip, appName);
|