From 725d1f4fe58b10500677084389aca55b4488944e Mon Sep 17 00:00:00 2001 From: "xueli.xue" Date: Thu, 2 Mar 2017 15:46:14 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E4=BB=BB=E5=8A=A1=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E8=A1=A8"=E8=B0=83=E5=BA=A6=E7=8A=B6=E6=80=81"=E5=92=8C"?= =?UTF-8?q?=E6=89=A7=E8=A1=8C=E7=8A=B6=E6=80=81"=E7=BB=9F=E4=B8=80?= =?UTF-8?q?=E4=B8=BAint=E5=80=BC=EF=BC=8C=E4=BF=AE=E6=94=B9=E5=AF=B9?= =?UTF-8?q?=E5=BA=94=E8=A1=A8=E7=BB=93=E6=9E=84=EF=BC=9B=202=E3=80=81?= =?UTF-8?q?=E5=88=86=E5=B8=83=E5=BC=8F=E8=B0=83=E5=BA=A6=E5=99=A8=E6=9B=B4?= =?UTF-8?q?=E5=90=8D=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xxl/job/admin/core/biz/AdminBizImpl.java | 12 ++++++------ .../admin/core/jobbean/RemoteHttpJobBean.java | 12 ++++++------ ...erUtil.java => XxlJobDynamicScheduler.java} | 14 +++++++------- .../admin/core/thread/JobMonitorHelper.java | 8 ++++---- .../admin/core/thread/JobRegistryHelper.java | 10 +++++----- .../admin/service/impl/XxlJobServiceImpl.java | 18 +++++++++--------- .../resources/applicationcontext-xxl-job.xml | 2 +- 7 files changed, 38 insertions(+), 38 deletions(-) rename xxl-job-admin/src/main/java/com/xxl/job/admin/core/schedule/{DynamicSchedulerUtil.java => XxlJobDynamicScheduler.java} (95%) diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/biz/AdminBizImpl.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/biz/AdminBizImpl.java index 03b9a183..7f5454a9 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/biz/AdminBizImpl.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/biz/AdminBizImpl.java @@ -2,7 +2,7 @@ package com.xxl.job.admin.core.biz; import com.xxl.job.admin.core.model.XxlJobInfo; import com.xxl.job.admin.core.model.XxlJobLog; -import com.xxl.job.admin.core.schedule.DynamicSchedulerUtil; +import com.xxl.job.admin.core.schedule.XxlJobDynamicScheduler; import com.xxl.job.core.biz.AdminBiz; import com.xxl.job.core.biz.model.HandleCallbackParam; import com.xxl.job.core.biz.model.ReturnT; @@ -24,7 +24,7 @@ public class AdminBizImpl implements AdminBiz { public ReturnT callback(HandleCallbackParam handleCallbackParam) { // valid log item - XxlJobLog log = DynamicSchedulerUtil.xxlJobLogDao.load(handleCallbackParam.getLogId()); + XxlJobLog log = XxlJobDynamicScheduler.xxlJobLogDao.load(handleCallbackParam.getLogId()); if (log == null) { return new ReturnT(ReturnT.FAIL_CODE, "log item not found."); } @@ -32,17 +32,17 @@ public class AdminBizImpl implements AdminBiz { // trigger success, to trigger child job, and avoid repeat trigger child job String childTriggerMsg = null; if (ReturnT.SUCCESS_CODE==handleCallbackParam.getCode() && ReturnT.SUCCESS_CODE!=log.getHandleCode()) { - XxlJobInfo xxlJobInfo = DynamicSchedulerUtil.xxlJobInfoDao.load(log.getJobGroup(), log.getJobName()); + XxlJobInfo xxlJobInfo = XxlJobDynamicScheduler.xxlJobInfoDao.load(log.getJobGroup(), log.getJobName()); if (xxlJobInfo!=null && StringUtils.isNotBlank(xxlJobInfo.getChildJobKey())) { childTriggerMsg = "
"; String[] childJobKeys = xxlJobInfo.getChildJobKey().split(","); for (int i = 0; i < childJobKeys.length; i++) { String[] jobKeyArr = childJobKeys[i].split("_"); if (jobKeyArr!=null && jobKeyArr.length==2) { - XxlJobInfo childJobInfo = DynamicSchedulerUtil.xxlJobInfoDao.load(Integer.valueOf(jobKeyArr[0]), jobKeyArr[1]); + XxlJobInfo childJobInfo = XxlJobDynamicScheduler.xxlJobInfoDao.load(Integer.valueOf(jobKeyArr[0]), jobKeyArr[1]); if (childJobInfo!=null) { try { - boolean ret = DynamicSchedulerUtil.triggerJob(childJobInfo.getJobName(), String.valueOf(childJobInfo.getJobGroup())); + boolean ret = XxlJobDynamicScheduler.triggerJob(childJobInfo.getJobName(), String.valueOf(childJobInfo.getJobGroup())); // add msg childTriggerMsg += MessageFormat.format("
{0}/{1} 触发子任务成功, 子任务Key: {2}, status: {3}, 子任务描述: {4}", @@ -79,7 +79,7 @@ public class AdminBizImpl implements AdminBiz { log.setHandleTime(new Date()); log.setHandleCode(handleCallbackParam.getCode()); log.setHandleMsg(handleMsg.toString()); - DynamicSchedulerUtil.xxlJobLogDao.updateHandleInfo(log); + XxlJobDynamicScheduler.xxlJobLogDao.updateHandleInfo(log); return new ReturnT(ReturnT.SUCCESS_CODE, null); } 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 e0119efc..e0dce473 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 @@ -3,9 +3,9 @@ package com.xxl.job.admin.core.jobbean; import com.xxl.job.admin.core.model.XxlJobGroup; import com.xxl.job.admin.core.model.XxlJobInfo; import com.xxl.job.admin.core.model.XxlJobLog; +import com.xxl.job.admin.core.schedule.XxlJobDynamicScheduler; import com.xxl.job.admin.core.thread.JobMonitorHelper; import com.xxl.job.admin.core.thread.JobRegistryHelper; -import com.xxl.job.admin.core.schedule.DynamicSchedulerUtil; import com.xxl.job.core.biz.ExecutorBiz; import com.xxl.job.core.biz.model.ReturnT; import com.xxl.job.core.biz.model.TriggerParam; @@ -36,12 +36,12 @@ public class RemoteHttpJobBean extends QuartzJobBean { throws JobExecutionException { JobKey jobKey = context.getTrigger().getJobKey(); - XxlJobInfo jobInfo = DynamicSchedulerUtil.xxlJobInfoDao.load(Integer.valueOf(jobKey.getGroup()), jobKey.getName()); + XxlJobInfo jobInfo = XxlJobDynamicScheduler.xxlJobInfoDao.load(Integer.valueOf(jobKey.getGroup()), jobKey.getName()); // save log XxlJobLog jobLog = new XxlJobLog(); jobLog.setJobGroup(jobInfo.getJobGroup()); jobLog.setJobName(jobInfo.getJobName()); - DynamicSchedulerUtil.xxlJobLogDao.save(jobLog); + XxlJobDynamicScheduler.xxlJobLogDao.save(jobLog); logger.debug(">>>>>>>>>>> xxl-job trigger start, jobId:{}", jobLog.getId()); // admin address @@ -50,7 +50,7 @@ public class RemoteHttpJobBean extends QuartzJobBean { if (adminAddressList!=null) { adminAddressSet.addAll(adminAddressList); } - adminAddressSet.add(DynamicSchedulerUtil.getCallbackAddress()); + adminAddressSet.add(XxlJobDynamicScheduler.getCallbackAddress()); // update trigger info 1/2 jobLog.setTriggerTime(new Date()); @@ -68,7 +68,7 @@ public class RemoteHttpJobBean extends QuartzJobBean { // parse address List addressList = new ArrayList(); - XxlJobGroup group = DynamicSchedulerUtil.xxlJobGroupDao.load(Integer.valueOf(jobInfo.getJobGroup())); + XxlJobGroup group = XxlJobDynamicScheduler.xxlJobGroupDao.load(Integer.valueOf(jobInfo.getJobGroup())); if (group!=null) { addressList = JobRegistryHelper.discover(RegistHelper.RegistType.EXECUTOR.name(), group.getAppName()); } @@ -82,7 +82,7 @@ public class RemoteHttpJobBean extends QuartzJobBean { // update trigger info 2/2 jobLog.setTriggerCode(responseModel.getCode()); jobLog.setTriggerMsg(responseModel.getMsg()); - DynamicSchedulerUtil.xxlJobLogDao.updateTriggerInfo(jobLog); + XxlJobDynamicScheduler.xxlJobLogDao.updateTriggerInfo(jobLog); // monitor triger JobMonitorHelper.monitor(jobLog.getId()); diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/schedule/DynamicSchedulerUtil.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/schedule/XxlJobDynamicScheduler.java similarity index 95% rename from xxl-job-admin/src/main/java/com/xxl/job/admin/core/schedule/DynamicSchedulerUtil.java rename to xxl-job-admin/src/main/java/com/xxl/job/admin/core/schedule/XxlJobDynamicScheduler.java index f1a3a1d4..d0437f7a 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/schedule/DynamicSchedulerUtil.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/schedule/XxlJobDynamicScheduler.java @@ -29,13 +29,13 @@ import java.util.*; * base quartz scheduler util * @author xuxueli 2015-12-19 16:13:53 */ -public final class DynamicSchedulerUtil implements ApplicationContextAware, InitializingBean { - private static final Logger logger = LoggerFactory.getLogger(DynamicSchedulerUtil.class); +public final class XxlJobDynamicScheduler implements ApplicationContextAware, InitializingBean { + private static final Logger logger = LoggerFactory.getLogger(XxlJobDynamicScheduler.class); // Scheduler private static Scheduler scheduler; public static void setScheduler(Scheduler scheduler) { - DynamicSchedulerUtil.scheduler = scheduler; + XxlJobDynamicScheduler.scheduler = scheduler; } // trigger callback address @@ -84,10 +84,10 @@ public final class DynamicSchedulerUtil implements ApplicationContextAware, Init @Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { - DynamicSchedulerUtil.xxlJobLogDao = applicationContext.getBean(IXxlJobLogDao.class); - DynamicSchedulerUtil.xxlJobInfoDao = applicationContext.getBean(IXxlJobInfoDao.class); - DynamicSchedulerUtil.xxlJobRegistryDao = applicationContext.getBean(IXxlJobRegistryDao.class); - DynamicSchedulerUtil.xxlJobGroupDao = applicationContext.getBean(IXxlJobGroupDao.class); + XxlJobDynamicScheduler.xxlJobLogDao = applicationContext.getBean(IXxlJobLogDao.class); + XxlJobDynamicScheduler.xxlJobInfoDao = applicationContext.getBean(IXxlJobInfoDao.class); + XxlJobDynamicScheduler.xxlJobRegistryDao = applicationContext.getBean(IXxlJobRegistryDao.class); + XxlJobDynamicScheduler.xxlJobGroupDao = applicationContext.getBean(IXxlJobGroupDao.class); } @Override diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/thread/JobMonitorHelper.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/thread/JobMonitorHelper.java index 17b86ad2..e695bdc4 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/thread/JobMonitorHelper.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/thread/JobMonitorHelper.java @@ -3,7 +3,7 @@ package com.xxl.job.admin.core.thread; import com.xxl.job.admin.core.model.XxlJobGroup; import com.xxl.job.admin.core.model.XxlJobInfo; import com.xxl.job.admin.core.model.XxlJobLog; -import com.xxl.job.admin.core.schedule.DynamicSchedulerUtil; +import com.xxl.job.admin.core.schedule.XxlJobDynamicScheduler; import com.xxl.job.admin.core.util.MailUtil; import com.xxl.job.core.biz.model.ReturnT; import org.slf4j.Logger; @@ -38,7 +38,7 @@ public class JobMonitorHelper { Integer jobLogId = JobMonitorHelper.helper.queue.take(); if (jobLogId != null && jobLogId > 0) { logger.info(">>>>>>>>>>> job monitor heat success, JobLogId:{}", jobLogId); - XxlJobLog log = DynamicSchedulerUtil.xxlJobLogDao.load(jobLogId); + XxlJobLog log = XxlJobDynamicScheduler.xxlJobLogDao.load(jobLogId); if (log!=null) { if (ReturnT.SUCCESS_CODE==log.getTriggerCode() && log.getHandleCode()==0) { // running @@ -53,13 +53,13 @@ public class JobMonitorHelper { // pass } if (ReturnT.FAIL_CODE == log.getTriggerCode()|| ReturnT.FAIL_CODE==log.getHandleCode()) { - XxlJobInfo info = DynamicSchedulerUtil.xxlJobInfoDao.load(log.getJobGroup(), log.getJobName()); + XxlJobInfo info = XxlJobDynamicScheduler.xxlJobInfoDao.load(log.getJobGroup(), log.getJobName()); if (info!=null && info.getAlarmEmail()!=null && info.getAlarmEmail().trim().length()>0) { Set emailSet = new HashSet(Arrays.asList(info.getAlarmEmail().split(","))); for (String email: emailSet) { String title = "《调度监控报警》(任务调度中心XXL-JOB)"; - XxlJobGroup group = DynamicSchedulerUtil.xxlJobGroupDao.load(Integer.valueOf(info.getJobGroup())); + XxlJobGroup group = XxlJobDynamicScheduler.xxlJobGroupDao.load(Integer.valueOf(info.getJobGroup())); String content = MessageFormat.format("任务调度失败, 执行器名称:{0}, 任务描述:{1}.", group!=null?group.getTitle():"null", info.getJobDesc()); MailUtil.sendMail(email, title, content, false, null); } 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 e641769b..5b8d06a4 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,7 +1,7 @@ package com.xxl.job.admin.core.thread; import com.xxl.job.admin.core.model.XxlJobRegistry; -import com.xxl.job.admin.core.schedule.DynamicSchedulerUtil; +import com.xxl.job.admin.core.schedule.XxlJobDynamicScheduler; import com.xxl.job.core.registry.RegistHelper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -28,15 +28,15 @@ public class JobRegistryHelper { while (true) { try { // registry admin - int ret = DynamicSchedulerUtil.xxlJobRegistryDao.registryUpdate(RegistHelper.RegistType.ADMIN.name(), RegistHelper.RegistType.ADMIN.name(), DynamicSchedulerUtil.getCallbackAddress()); + int ret = XxlJobDynamicScheduler.xxlJobRegistryDao.registryUpdate(RegistHelper.RegistType.ADMIN.name(), RegistHelper.RegistType.ADMIN.name(), XxlJobDynamicScheduler.getCallbackAddress()); if (ret < 1) { - DynamicSchedulerUtil.xxlJobRegistryDao.registrySave(RegistHelper.RegistType.ADMIN.name(), RegistHelper.RegistType.ADMIN.name(), DynamicSchedulerUtil.getCallbackAddress()); + XxlJobDynamicScheduler.xxlJobRegistryDao.registrySave(RegistHelper.RegistType.ADMIN.name(), RegistHelper.RegistType.ADMIN.name(), XxlJobDynamicScheduler.getCallbackAddress()); } // fresh registry map ConcurrentHashMap> temp = new ConcurrentHashMap>(); - DynamicSchedulerUtil.xxlJobRegistryDao.removeDead(RegistHelper.TIMEOUT*2); - List list = DynamicSchedulerUtil.xxlJobRegistryDao.findAll(RegistHelper.TIMEOUT*2); + XxlJobDynamicScheduler.xxlJobRegistryDao.removeDead(RegistHelper.TIMEOUT*2); + List list = XxlJobDynamicScheduler.xxlJobRegistryDao.findAll(RegistHelper.TIMEOUT*2); if (list != null) { for (XxlJobRegistry item: list) { String groupKey = makeGroupKey(item.getRegistryGroup(), item.getRegistryKey()); diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/service/impl/XxlJobServiceImpl.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/service/impl/XxlJobServiceImpl.java index 82f882de..77b63609 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/admin/service/impl/XxlJobServiceImpl.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/service/impl/XxlJobServiceImpl.java @@ -2,7 +2,7 @@ package com.xxl.job.admin.service.impl; import com.xxl.job.admin.core.model.XxlJobGroup; import com.xxl.job.admin.core.model.XxlJobInfo; -import com.xxl.job.admin.core.schedule.DynamicSchedulerUtil; +import com.xxl.job.admin.core.schedule.XxlJobDynamicScheduler; import com.xxl.job.admin.dao.IXxlJobGroupDao; import com.xxl.job.admin.dao.IXxlJobInfoDao; import com.xxl.job.admin.dao.IXxlJobLogDao; @@ -51,7 +51,7 @@ public class XxlJobServiceImpl implements IXxlJobService { // fill job info if (list!=null && list.size()>0) { for (XxlJobInfo jobInfo : list) { - DynamicSchedulerUtil.fillJobInfo(jobInfo); + XxlJobDynamicScheduler.fillJobInfo(jobInfo); } } @@ -106,7 +106,7 @@ public class XxlJobServiceImpl implements IXxlJobService { // generate jobName String jobName = FastDateFormat.getInstance("yyyyMMddHHmmssSSSS").format(new Date()); try { - if (DynamicSchedulerUtil.checkExists(jobName, String.valueOf(jobGroup))) { + if (XxlJobDynamicScheduler.checkExists(jobName, String.valueOf(jobGroup))) { return new ReturnT(500, "系统繁忙,请稍后重试"); } } catch (SchedulerException e1) { @@ -131,7 +131,7 @@ public class XxlJobServiceImpl implements IXxlJobService { try { // add job 2 quartz - boolean result = DynamicSchedulerUtil.addJob(String.valueOf(jobGroup), jobName, jobCron); + boolean result = XxlJobDynamicScheduler.addJob(String.valueOf(jobGroup), jobName, jobCron); if (result) { xxlJobInfoDao.save(jobInfo); return ReturnT.SUCCESS; @@ -200,7 +200,7 @@ public class XxlJobServiceImpl implements IXxlJobService { try { // fresh quartz - boolean ret = DynamicSchedulerUtil.rescheduleJob(String.valueOf(jobGroup), jobName, jobCron); + boolean ret = XxlJobDynamicScheduler.rescheduleJob(String.valueOf(jobGroup), jobName, jobCron); if (ret) { xxlJobInfoDao.update(jobInfo); return ReturnT.SUCCESS; @@ -216,7 +216,7 @@ public class XxlJobServiceImpl implements IXxlJobService { @Override public ReturnT remove(int jobGroup, String jobName) { try { - DynamicSchedulerUtil.removeJob(jobName, String.valueOf(jobGroup)); + XxlJobDynamicScheduler.removeJob(jobName, String.valueOf(jobGroup)); xxlJobInfoDao.delete(jobGroup, jobName); xxlJobLogDao.delete(jobGroup, jobName); xxlJobLogGlueDao.delete(jobGroup, jobName); @@ -230,7 +230,7 @@ public class XxlJobServiceImpl implements IXxlJobService { @Override public ReturnT pause(int jobGroup, String jobName) { try { - DynamicSchedulerUtil.pauseJob(jobName, String.valueOf(jobGroup)); // jobStatus do not store + XxlJobDynamicScheduler.pauseJob(jobName, String.valueOf(jobGroup)); // jobStatus do not store return ReturnT.SUCCESS; } catch (SchedulerException e) { e.printStackTrace(); @@ -241,7 +241,7 @@ public class XxlJobServiceImpl implements IXxlJobService { @Override public ReturnT resume(int jobGroup, String jobName) { try { - DynamicSchedulerUtil.resumeJob(jobName, String.valueOf(jobGroup)); + XxlJobDynamicScheduler.resumeJob(jobName, String.valueOf(jobGroup)); return ReturnT.SUCCESS; } catch (SchedulerException e) { e.printStackTrace(); @@ -252,7 +252,7 @@ public class XxlJobServiceImpl implements IXxlJobService { @Override public ReturnT triggerJob(int jobGroup, String jobName) { try { - DynamicSchedulerUtil.triggerJob(jobName, String.valueOf(jobGroup)); + XxlJobDynamicScheduler.triggerJob(jobName, String.valueOf(jobGroup)); return ReturnT.SUCCESS; } catch (SchedulerException e) { e.printStackTrace(); 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 28b4d7de..f1a96ec2 100644 --- a/xxl-job-admin/src/main/resources/applicationcontext-xxl-job.xml +++ b/xxl-job-admin/src/main/resources/applicationcontext-xxl-job.xml @@ -14,7 +14,7 @@ - +