|
@@ -10,7 +10,7 @@ import com.xxl.job.core.thread.ExecutorRegistryThread;
|
|
|
import com.xxl.job.core.thread.JobLogFileCleanThread;
|
|
|
import com.xxl.job.core.thread.JobThread;
|
|
|
import com.xxl.job.core.thread.TriggerCallbackThread;
|
|
|
-import com.xxl.rpc.registry.impl.LocalServiceRegistry;
|
|
|
+import com.xxl.rpc.registry.ServiceRegistry;
|
|
|
import com.xxl.rpc.remoting.invoker.XxlRpcInvokerFactory;
|
|
|
import com.xxl.rpc.remoting.invoker.call.CallType;
|
|
|
import com.xxl.rpc.remoting.invoker.reference.XxlRpcReferenceBean;
|
|
@@ -25,9 +25,7 @@ import org.springframework.beans.BeansException;
|
|
|
import org.springframework.context.ApplicationContext;
|
|
|
import org.springframework.context.ApplicationContextAware;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
|
|
/**
|
|
@@ -38,7 +36,7 @@ public class XxlJobExecutor implements ApplicationContextAware {
|
|
|
|
|
|
// ---------------------- param ----------------------
|
|
|
private String adminAddresses;
|
|
|
- private static String appName;
|
|
|
+ private String appName;
|
|
|
private String ip;
|
|
|
private int port;
|
|
|
private String accessToken;
|
|
@@ -123,7 +121,7 @@ public class XxlJobExecutor implements ApplicationContextAware {
|
|
|
|
|
|
// ---------------------- admin-client (rpc invoker) ----------------------
|
|
|
private static List<AdminBiz> adminBizList;
|
|
|
- private static void initAdminBizList(String adminAddresses, String accessToken) throws Exception {
|
|
|
+ private void initAdminBizList(String adminAddresses, String accessToken) throws Exception {
|
|
|
if (adminAddresses!=null && adminAddresses.trim().length()>0) {
|
|
|
for (String address: adminAddresses.trim().split(",")) {
|
|
|
if (address!=null && address.trim().length()>0) {
|
|
@@ -155,13 +153,19 @@ public class XxlJobExecutor implements ApplicationContextAware {
|
|
|
// ---------------------- executor-server (rpc provider) ----------------------
|
|
|
private XxlRpcInvokerFactory xxlRpcInvokerFactory = null;
|
|
|
private XxlRpcProviderFactory xxlRpcProviderFactory = null;
|
|
|
+
|
|
|
private void initRpcProvider(String ip, int port, String appName, String accessToken) throws Exception {
|
|
|
// init invoker factory
|
|
|
xxlRpcInvokerFactory = new XxlRpcInvokerFactory();
|
|
|
|
|
|
// init, provider factory
|
|
|
+ String address = IpUtil.getIpPort(ip, port);
|
|
|
+ Map<String, String> serviceRegistryParam = new HashMap<String, String>();
|
|
|
+ serviceRegistryParam.put("appName", appName);
|
|
|
+ serviceRegistryParam.put("address", address);
|
|
|
+
|
|
|
xxlRpcProviderFactory = new XxlRpcProviderFactory();
|
|
|
- xxlRpcProviderFactory.initConfig(NetEnum.JETTY, Serializer.SerializeEnum.HESSIAN.getSerializer(), ip, port, accessToken, ExecutorServiceRegistry.class, null);
|
|
|
+ xxlRpcProviderFactory.initConfig(NetEnum.JETTY, Serializer.SerializeEnum.HESSIAN.getSerializer(), ip, port, accessToken, ExecutorServiceRegistry.class, serviceRegistryParam);
|
|
|
|
|
|
// add services
|
|
|
xxlRpcProviderFactory.addService(ExecutorBiz.class.getName(), null, new ExecutorBizImpl());
|
|
@@ -171,25 +175,32 @@ public class XxlJobExecutor implements ApplicationContextAware {
|
|
|
|
|
|
}
|
|
|
|
|
|
- public static class ExecutorServiceRegistry extends LocalServiceRegistry {
|
|
|
- @Override
|
|
|
- public boolean registry(String key, String value) {
|
|
|
+ public static class ExecutorServiceRegistry extends ServiceRegistry {
|
|
|
|
|
|
+ @Override
|
|
|
+ public void start(Map<String, String> param) {
|
|
|
// start registry
|
|
|
- if (ExecutorBiz.class.getName().equalsIgnoreCase(key)) {
|
|
|
- ExecutorRegistryThread.getInstance().start(appName, value);
|
|
|
- }
|
|
|
-
|
|
|
- return super.registry(key, value);
|
|
|
+ ExecutorRegistryThread.getInstance().start(param.get("appName"), param.get("address"));
|
|
|
}
|
|
|
-
|
|
|
@Override
|
|
|
public void stop() {
|
|
|
// stop registry
|
|
|
ExecutorRegistryThread.getInstance().toStop();
|
|
|
+ }
|
|
|
|
|
|
- super.stop();
|
|
|
+ @Override
|
|
|
+ public boolean registry(String key, String value) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ @Override
|
|
|
+ public boolean remove(String key, String value) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ @Override
|
|
|
+ public TreeSet<String> discovery(String key) {
|
|
|
+ return null;
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
private void stopRpcProvider() {
|
|
@@ -217,7 +228,7 @@ public class XxlJobExecutor implements ApplicationContextAware {
|
|
|
public static IJobHandler loadJobHandler(String name){
|
|
|
return jobHandlerRepository.get(name);
|
|
|
}
|
|
|
- private static void initJobHandlerRepository(ApplicationContext applicationContext){
|
|
|
+ private void initJobHandlerRepository(ApplicationContext applicationContext){
|
|
|
if (applicationContext == null) {
|
|
|
return;
|
|
|
}
|