From 65cfe57b6b5616032136e809b872d2589e5daaff Mon Sep 17 00:00:00 2001 From: "xueli.xue" Date: Sat, 21 Jan 2017 23:05:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=A7=E8=A1=8C=E5=99=A8=E3=80=81=E8=B0=83?= =?UTF-8?q?=E5=BA=A6=E4=B8=AD=E5=BF=83=EF=BC=8C=E6=94=AF=E6=8C=81=E8=87=AA?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E6=B3=A8=E5=86=8CIP=E5=9C=B0=E5=9D=80?= =?UTF-8?q?=EF=BC=9B=E8=A7=A3=E5=86=B3=E6=9C=BA=E5=99=A8=E5=A4=9A=E7=BD=91?= =?UTF-8?q?=E5=8D=A1=E6=97=B6=E9=94=99=E8=AF=AF=E7=BD=91=E5=8D=A1=E6=B3=A8?= =?UTF-8?q?=E5=86=8C=E7=9A=84=E6=83=85=E5=86=B5=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + .../callback/XxlJobLogCallbackServer.java | 10 --------- .../admin/core/jobbean/RemoteHttpJobBean.java | 3 +-- .../admin/core/thread/JobRegistryHelper.java | 5 ++--- .../admin/core/util/DynamicSchedulerUtil.java | 21 +++++++++++++++++-- .../resources/applicationcontext-xxl-job.xml | 4 ++++ .../core/executor/jetty/XxlJobExecutor.java | 15 ++++++++++++- .../resources/applicationcontext-xxl-job.xml | 2 ++ 8 files changed, 43 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index d566ca05..cbb24503 100644 --- a/README.md +++ b/README.md @@ -702,6 +702,7 @@ Tips: 历史版本(V1.3.x)目前已经Release至稳定版本, 进入维护阶段 #### 6.10 版本 V1.5.2 特性 - 1、IP工具类优化,IP静态缓存; +- 2、执行器、调度中心,支持自定义注册IP地址;解决机器多网卡时错误网卡注册的情况; #### 规划中 - 1、集群执行器选择规则自定义:单点=选择第一个,随机=随机选择一个; diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/callback/XxlJobLogCallbackServer.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/callback/XxlJobLogCallbackServer.java index 6d6452ba..1f063ac5 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/callback/XxlJobLogCallbackServer.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/callback/XxlJobLogCallbackServer.java @@ -9,25 +9,15 @@ import org.eclipse.jetty.util.thread.ExecutorThreadPool; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.xxl.job.core.util.IpUtil; - /** * Created by xuxueli on 2016-5-22 11:15:42 */ public class XxlJobLogCallbackServer { private static final Logger logger = LoggerFactory.getLogger(XxlJobLogCallbackServer.class); - private static String trigger_log_address; - public static String getTrigger_log_address() { - return trigger_log_address; - } - Server server = null; public void start(int callBackPort) throws Exception { - // init address - trigger_log_address = IpUtil.getIpPort(callBackPort); - final int port = Integer.valueOf(callBackPort); new Thread(new Runnable() { @Override diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/jobbean/RemoteHttpJobBean.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/jobbean/RemoteHttpJobBean.java index a632de90..18e74372 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/jobbean/RemoteHttpJobBean.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/jobbean/RemoteHttpJobBean.java @@ -1,6 +1,5 @@ package com.xxl.job.admin.core.jobbean; -import com.xxl.job.admin.core.callback.XxlJobLogCallbackServer; import com.xxl.job.admin.core.model.XxlJobGroup; import com.xxl.job.admin.core.model.XxlJobInfo; import com.xxl.job.admin.core.model.XxlJobLog; @@ -51,7 +50,7 @@ public class RemoteHttpJobBean extends QuartzJobBean { if (adminAddressList!=null) { adminAddressSet.addAll(adminAddressList); } - adminAddressSet.add(XxlJobLogCallbackServer.getTrigger_log_address()); + adminAddressSet.add(DynamicSchedulerUtil.getCallbackAddress()); // trigger request RequestModel requestModel = new RequestModel(); diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/thread/JobRegistryHelper.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/thread/JobRegistryHelper.java index 20f694fb..61a84d75 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/thread/JobRegistryHelper.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/thread/JobRegistryHelper.java @@ -1,6 +1,5 @@ package com.xxl.job.admin.core.thread; -import com.xxl.job.admin.core.callback.XxlJobLogCallbackServer; import com.xxl.job.admin.core.model.XxlJobRegistry; import com.xxl.job.admin.core.util.DynamicSchedulerUtil; import com.xxl.job.core.registry.RegistHelper; @@ -29,9 +28,9 @@ public class JobRegistryHelper { while (true) { try { // registry admin - int ret = DynamicSchedulerUtil.xxlJobRegistryDao.registryUpdate(RegistHelper.RegistType.ADMIN.name(), RegistHelper.RegistType.ADMIN.name(), XxlJobLogCallbackServer.getTrigger_log_address()); + int ret = DynamicSchedulerUtil.xxlJobRegistryDao.registryUpdate(RegistHelper.RegistType.ADMIN.name(), RegistHelper.RegistType.ADMIN.name(), DynamicSchedulerUtil.getCallbackAddress()); if (ret < 1) { - DynamicSchedulerUtil.xxlJobRegistryDao.registrySave(RegistHelper.RegistType.ADMIN.name(), RegistHelper.RegistType.ADMIN.name(), XxlJobLogCallbackServer.getTrigger_log_address()); + DynamicSchedulerUtil.xxlJobRegistryDao.registrySave(RegistHelper.RegistType.ADMIN.name(), RegistHelper.RegistType.ADMIN.name(), DynamicSchedulerUtil.getCallbackAddress()); } // fresh registry map diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/util/DynamicSchedulerUtil.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/util/DynamicSchedulerUtil.java index 1c3c5bb4..3e865b8c 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/util/DynamicSchedulerUtil.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/util/DynamicSchedulerUtil.java @@ -8,6 +8,7 @@ import com.xxl.job.admin.dao.IXxlJobGroupDao; import com.xxl.job.admin.dao.IXxlJobInfoDao; import com.xxl.job.admin.dao.IXxlJobLogDao; import com.xxl.job.admin.dao.IXxlJobRegistryDao; +import com.xxl.job.core.util.IpUtil; import org.quartz.*; import org.quartz.Trigger.TriggerState; import org.quartz.impl.matchers.GroupMatcher; @@ -35,12 +36,21 @@ public final class DynamicSchedulerUtil implements ApplicationContextAware, Init DynamicSchedulerUtil.scheduler = scheduler; } - // trigger callback port + // trigger callback address + private String callBackIp; private int callBackPort = 8888; + private static String callbackAddress; + + public void setCallBackIp(String callBackIp) { + this.callBackIp = callBackIp; + } public void setCallBackPort(int callBackPort) { this.callBackPort = callBackPort; } - + public static String getCallbackAddress(){ + return callbackAddress; + } + // init XxlJobLogCallbackServer xxlJobLogCallbackServer = null; public void init(){ @@ -52,6 +62,13 @@ public final class DynamicSchedulerUtil implements ApplicationContextAware, Init e.printStackTrace(); } + // init callbackAddress + if (callBackIp!=null && callBackIp.trim().length()>0) { + callbackAddress = callBackIp.trim().concat(":").concat(String.valueOf(callBackPort)); + } else { + callbackAddress = IpUtil.getIpPort(callBackPort);; + } + // init JobRegistryHelper JobRegistryHelper.discover("g", "k"); } diff --git a/xxl-job-admin/src/main/resources/applicationcontext-xxl-job.xml b/xxl-job-admin/src/main/resources/applicationcontext-xxl-job.xml index 7fcf3b1d..d38abe90 100644 --- a/xxl-job-admin/src/main/resources/applicationcontext-xxl-job.xml +++ b/xxl-job-admin/src/main/resources/applicationcontext-xxl-job.xml @@ -4,6 +4,7 @@ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> + @@ -16,6 +17,9 @@ + + + diff --git a/xxl-job-core/src/main/java/com/xxl/job/core/executor/jetty/XxlJobExecutor.java b/xxl-job-core/src/main/java/com/xxl/job/core/executor/jetty/XxlJobExecutor.java index e27120f9..5ba73870 100644 --- a/xxl-job-core/src/main/java/com/xxl/job/core/executor/jetty/XxlJobExecutor.java +++ b/xxl-job-core/src/main/java/com/xxl/job/core/executor/jetty/XxlJobExecutor.java @@ -26,9 +26,14 @@ import java.util.concurrent.TimeUnit; public class XxlJobExecutor implements ApplicationContextAware { private static final Logger logger = LoggerFactory.getLogger(XxlJobExecutor.class); + private String ip; private int port = 9999; private String appName; private RegistHelper registHelper; + + public void setIp(String ip) { + this.ip = ip; + } public void setPort(int port) { this.port = port; } @@ -94,7 +99,15 @@ public class XxlJobExecutor implements ApplicationContextAware { public void run() { while (true) { try { - String address = IpUtil.getIpPort(port); + + // generate addredd = ip:port + String address = null; + if (ip != null && ip.trim().length()>0) { + address = ip.trim().concat(":").concat(String.valueOf(port)); + } else { + address = IpUtil.getIpPort(port); + } + registHelper.registry(RegistHelper.RegistType.EXECUTOR.name(), appName, address); TimeUnit.SECONDS.sleep(RegistHelper.TIMEOUT); } catch (Exception e) { diff --git a/xxl-job-executor-example/src/main/resources/applicationcontext-xxl-job.xml b/xxl-job-executor-example/src/main/resources/applicationcontext-xxl-job.xml index c297885f..4c37cd50 100644 --- a/xxl-job-executor-example/src/main/resources/applicationcontext-xxl-job.xml +++ b/xxl-job-executor-example/src/main/resources/applicationcontext-xxl-job.xml @@ -14,6 +14,8 @@ + +