|
|
@@ -10,7 +10,7 @@ import com.xxl.job.core.thread.ExecutorRegistryThread;
|
|
10
|
10
|
import com.xxl.job.core.thread.JobLogFileCleanThread;
|
|
11
|
11
|
import com.xxl.job.core.thread.JobThread;
|
|
12
|
12
|
import com.xxl.job.core.thread.TriggerCallbackThread;
|
|
13
|
|
-import com.xxl.rpc.registry.impl.LocalServiceRegistry;
|
|
|
13
|
+import com.xxl.rpc.registry.ServiceRegistry;
|
|
14
|
14
|
import com.xxl.rpc.remoting.invoker.XxlRpcInvokerFactory;
|
|
15
|
15
|
import com.xxl.rpc.remoting.invoker.call.CallType;
|
|
16
|
16
|
import com.xxl.rpc.remoting.invoker.reference.XxlRpcReferenceBean;
|
|
|
@@ -25,9 +25,7 @@ import org.springframework.beans.BeansException;
|
|
25
|
25
|
import org.springframework.context.ApplicationContext;
|
|
26
|
26
|
import org.springframework.context.ApplicationContextAware;
|
|
27
|
27
|
|
|
28
|
|
-import java.util.ArrayList;
|
|
29
|
|
-import java.util.List;
|
|
30
|
|
-import java.util.Map;
|
|
|
28
|
+import java.util.*;
|
|
31
|
29
|
import java.util.concurrent.ConcurrentHashMap;
|
|
32
|
30
|
|
|
33
|
31
|
/**
|
|
|
@@ -38,7 +36,7 @@ public class XxlJobExecutor implements ApplicationContextAware {
|
|
38
|
36
|
|
|
39
|
37
|
// ---------------------- param ----------------------
|
|
40
|
38
|
private String adminAddresses;
|
|
41
|
|
- private static String appName;
|
|
|
39
|
+ private String appName;
|
|
42
|
40
|
private String ip;
|
|
43
|
41
|
private int port;
|
|
44
|
42
|
private String accessToken;
|
|
|
@@ -123,7 +121,7 @@ public class XxlJobExecutor implements ApplicationContextAware {
|
|
123
|
121
|
|
|
124
|
122
|
// ---------------------- admin-client (rpc invoker) ----------------------
|
|
125
|
123
|
private static List<AdminBiz> adminBizList;
|
|
126
|
|
- private static void initAdminBizList(String adminAddresses, String accessToken) throws Exception {
|
|
|
124
|
+ private void initAdminBizList(String adminAddresses, String accessToken) throws Exception {
|
|
127
|
125
|
if (adminAddresses!=null && adminAddresses.trim().length()>0) {
|
|
128
|
126
|
for (String address: adminAddresses.trim().split(",")) {
|
|
129
|
127
|
if (address!=null && address.trim().length()>0) {
|
|
|
@@ -155,13 +153,19 @@ public class XxlJobExecutor implements ApplicationContextAware {
|
|
155
|
153
|
// ---------------------- executor-server (rpc provider) ----------------------
|
|
156
|
154
|
private XxlRpcInvokerFactory xxlRpcInvokerFactory = null;
|
|
157
|
155
|
private XxlRpcProviderFactory xxlRpcProviderFactory = null;
|
|
|
156
|
+
|
|
158
|
157
|
private void initRpcProvider(String ip, int port, String appName, String accessToken) throws Exception {
|
|
159
|
158
|
// init invoker factory
|
|
160
|
159
|
xxlRpcInvokerFactory = new XxlRpcInvokerFactory();
|
|
161
|
160
|
|
|
162
|
161
|
// init, provider factory
|
|
|
162
|
+ String address = IpUtil.getIpPort(ip, port);
|
|
|
163
|
+ Map<String, String> serviceRegistryParam = new HashMap<String, String>();
|
|
|
164
|
+ serviceRegistryParam.put("appName", appName);
|
|
|
165
|
+ serviceRegistryParam.put("address", address);
|
|
|
166
|
+
|
|
163
|
167
|
xxlRpcProviderFactory = new XxlRpcProviderFactory();
|
|
164
|
|
- xxlRpcProviderFactory.initConfig(NetEnum.JETTY, Serializer.SerializeEnum.HESSIAN.getSerializer(), ip, port, accessToken, ExecutorServiceRegistry.class, null);
|
|
|
168
|
+ xxlRpcProviderFactory.initConfig(NetEnum.JETTY, Serializer.SerializeEnum.HESSIAN.getSerializer(), ip, port, accessToken, ExecutorServiceRegistry.class, serviceRegistryParam);
|
|
165
|
169
|
|
|
166
|
170
|
// add services
|
|
167
|
171
|
xxlRpcProviderFactory.addService(ExecutorBiz.class.getName(), null, new ExecutorBizImpl());
|
|
|
@@ -171,25 +175,32 @@ public class XxlJobExecutor implements ApplicationContextAware {
|
|
171
|
175
|
|
|
172
|
176
|
}
|
|
173
|
177
|
|
|
174
|
|
- public static class ExecutorServiceRegistry extends LocalServiceRegistry {
|
|
175
|
|
- @Override
|
|
176
|
|
- public boolean registry(String key, String value) {
|
|
|
178
|
+ public static class ExecutorServiceRegistry extends ServiceRegistry {
|
|
177
|
179
|
|
|
|
180
|
+ @Override
|
|
|
181
|
+ public void start(Map<String, String> param) {
|
|
178
|
182
|
// start registry
|
|
179
|
|
- if (ExecutorBiz.class.getName().equalsIgnoreCase(key)) {
|
|
180
|
|
- ExecutorRegistryThread.getInstance().start(appName, value);
|
|
181
|
|
- }
|
|
182
|
|
-
|
|
183
|
|
- return super.registry(key, value);
|
|
|
183
|
+ ExecutorRegistryThread.getInstance().start(param.get("appName"), param.get("address"));
|
|
184
|
184
|
}
|
|
185
|
|
-
|
|
186
|
185
|
@Override
|
|
187
|
186
|
public void stop() {
|
|
188
|
187
|
// stop registry
|
|
189
|
188
|
ExecutorRegistryThread.getInstance().toStop();
|
|
|
189
|
+ }
|
|
190
|
190
|
|
|
191
|
|
- super.stop();
|
|
|
191
|
+ @Override
|
|
|
192
|
+ public boolean registry(String key, String value) {
|
|
|
193
|
+ return false;
|
|
|
194
|
+ }
|
|
|
195
|
+ @Override
|
|
|
196
|
+ public boolean remove(String key, String value) {
|
|
|
197
|
+ return false;
|
|
|
198
|
+ }
|
|
|
199
|
+ @Override
|
|
|
200
|
+ public TreeSet<String> discovery(String key) {
|
|
|
201
|
+ return null;
|
|
192
|
202
|
}
|
|
|
203
|
+
|
|
193
|
204
|
}
|
|
194
|
205
|
|
|
195
|
206
|
private void stopRpcProvider() {
|
|
|
@@ -217,7 +228,7 @@ public class XxlJobExecutor implements ApplicationContextAware {
|
|
217
|
228
|
public static IJobHandler loadJobHandler(String name){
|
|
218
|
229
|
return jobHandlerRepository.get(name);
|
|
219
|
230
|
}
|
|
220
|
|
- private static void initJobHandlerRepository(ApplicationContext applicationContext){
|
|
|
231
|
+ private void initJobHandlerRepository(ApplicationContext applicationContext){
|
|
221
|
232
|
if (applicationContext == null) {
|
|
222
|
233
|
return;
|
|
223
|
234
|
}
|