diff --git a/xxl-job-admin/src/main/java/com/xxl/quartz/DynamicSchedulerUtil.java b/xxl-job-admin/src/main/java/com/xxl/quartz/DynamicSchedulerUtil.java new file mode 100644 index 00000000..a882d23b --- /dev/null +++ b/xxl-job-admin/src/main/java/com/xxl/quartz/DynamicSchedulerUtil.java @@ -0,0 +1,151 @@ +package com.xxl.quartz; + +import java.util.Date; +import java.util.Map; +import java.util.Set; + +import org.quartz.CronScheduleBuilder; +import org.quartz.CronTrigger; +import org.quartz.Job; +import org.quartz.JobBuilder; +import org.quartz.JobDataMap; +import org.quartz.JobDetail; +import org.quartz.JobKey; +import org.quartz.Scheduler; +import org.quartz.SchedulerException; +import org.quartz.Trigger; +import org.quartz.TriggerBuilder; +import org.quartz.TriggerKey; +import org.quartz.impl.matchers.GroupMatcher; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.InitializingBean; +import org.springframework.util.Assert; + +public final class DynamicSchedulerUtil implements InitializingBean { + private static final Logger logger = LoggerFactory.getLogger(DynamicSchedulerUtil.class); + + // Scheduler + private static Scheduler scheduler; + public static void setScheduler(Scheduler scheduler) { + DynamicSchedulerUtil.scheduler = scheduler; + } + + @Override + public void afterPropertiesSet() throws Exception { + Assert.notNull(scheduler, "quartz scheduler is null"); + logger.info(">>>>>>>>> init quartz scheduler success.[{}]", scheduler); + } + + // getJobKeys + public static Set getJobKeys(){ + try { + String groupName = scheduler.getJobGroupNames().get(0); + return scheduler.getJobKeys(GroupMatcher.jobGroupEquals(groupName)); + } catch (SchedulerException e) { + e.printStackTrace(); + return null; + } + } + + // addJob 新增 + public static boolean addJob(String triggerKeyName, String cronExpression, Class jobClass, Map jobData) throws SchedulerException { + // TriggerKey : name + group + String group = Scheduler.DEFAULT_GROUP; + TriggerKey triggerKey = TriggerKey.triggerKey(triggerKeyName, group); + + // TriggerKey valid if_exists + if (scheduler.checkExists(triggerKey)) { + Trigger trigger = scheduler.getTrigger(triggerKey); + logger.info(">>>>>>>>> Already exist trigger [" + trigger + "] by key [" + triggerKey + "] in Scheduler"); + return false; + } + + // CronTrigger : TriggerKey + cronExpression + CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule(cronExpression); + CronTrigger cronTrigger = TriggerBuilder.newTrigger().withIdentity(triggerKey).withSchedule(cronScheduleBuilder).build(); + + // JobDetail : jobClass + JobDetail jobDetail = JobBuilder.newJob(jobClass).withIdentity(triggerKeyName, group).build(); + if (jobData!=null && jobData.size() > 0) { + JobDataMap jobDataMap = jobDetail.getJobDataMap(); + jobDataMap.putAll(jobData); // JobExecutionContext context.getMergedJobDataMap().get("mailGuid"); + } + + // schedule : jobDetail + cronTrigger + Date date = scheduler.scheduleJob(jobDetail, cronTrigger); + + logger.info(">>>>>>>>>>> addJob success, jobDetail:{}, cronTrigger:{}, date:{}", jobDetail, cronTrigger, date); + return true; + } + + // unscheduleJob 删除 + public static boolean removeJob(String triggerKeyName) throws SchedulerException { + // TriggerKey : name + group + String group = Scheduler.DEFAULT_GROUP; + TriggerKey triggerKey = TriggerKey.triggerKey(triggerKeyName, group); + + boolean result = false; + if (scheduler.checkExists(triggerKey)) { + result = scheduler.unscheduleJob(triggerKey); + } + logger.info(">>>>>>>>>>> removeJob, triggerKey:{}, result [{}]", triggerKey, result); + return result; + } + + // reschedule 重置cron + public static boolean rescheduleJob(String triggerKeyName, String cronExpression) throws SchedulerException { + // TriggerKey : name + group + String group = Scheduler.DEFAULT_GROUP; + TriggerKey triggerKey = TriggerKey.triggerKey(triggerKeyName, group); + + boolean result = false; + if (scheduler.checkExists(triggerKey)) { + // CronTrigger : TriggerKey + cronExpression + CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule(cronExpression); + CronTrigger cronTrigger = TriggerBuilder.newTrigger().withIdentity(triggerKey).withSchedule(cronScheduleBuilder).build(); + + Date date = scheduler.rescheduleJob(triggerKey, cronTrigger); + result = true; + logger.info(">>>>>>>>>>> resumeJob success, triggerKey:{}, cronExpression:{}, date:{}", triggerKey, cronExpression, date); + } else { + logger.info(">>>>>>>>>>> resumeJob fail, triggerKey:{}, cronExpression:{}", triggerKey, cronExpression); + } + return result; + } + + // Pause 暂停 + public static boolean pauseJob(String triggerKeyName) throws SchedulerException { + // TriggerKey : name + group + String group = Scheduler.DEFAULT_GROUP; + TriggerKey triggerKey = TriggerKey.triggerKey(triggerKeyName, group); + + boolean result = false; + if (scheduler.checkExists(triggerKey)) { + scheduler.pauseTrigger(triggerKey); + result = true; + logger.info(">>>>>>>>>>> pauseJob success, triggerKey:{}", triggerKey); + } else { + logger.info(">>>>>>>>>>> pauseJob fail, triggerKey:{}", triggerKey); + } + return result; + } + + // resume 重启 + public static boolean resumeTrigger(String triggerKeyName) throws SchedulerException { + // TriggerKey : name + group + String group = Scheduler.DEFAULT_GROUP; + TriggerKey triggerKey = TriggerKey.triggerKey(triggerKeyName, group); + + boolean result = false; + if (scheduler.checkExists(triggerKey)) { + scheduler.resumeTrigger(triggerKey); + result = true; + logger.info(">>>>>>>>>>> resumeJob success, triggerKey:{}", triggerKey); + } else { + logger.info(">>>>>>>>>>> resumeJob fail, triggerKey:{}", triggerKey); + } + return result; + } + +} \ No newline at end of file diff --git a/xxl-job-admin/src/main/java/com/xxl/service/impl/TriggerServiceImpl.java b/xxl-job-admin/src/main/java/com/xxl/service/impl/TriggerServiceImpl.java index e8936414..ec0a2fd8 100644 --- a/xxl-job-admin/src/main/java/com/xxl/service/impl/TriggerServiceImpl.java +++ b/xxl-job-admin/src/main/java/com/xxl/service/impl/TriggerServiceImpl.java @@ -1,5 +1,8 @@ package com.xxl.service.impl; +import java.util.Date; + +import org.apache.commons.lang.time.FastDateFormat; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; @@ -19,12 +22,7 @@ public class TriggerServiceImpl implements ITriggerService { * 全站静态化 */ public void generateNetHtml() { - long start = System.currentTimeMillis(); - logger.info("全站静态化... start:{}", start); - - - long end = System.currentTimeMillis(); - logger.info("全站静态化... end:{}, cost:{}", end, end - start); + logger.info("全站静态化 run at :{}", FastDateFormat.getInstance("yyyy-MM-dd HH:mm:ss").format(new Date())); } } diff --git a/xxl-job-demo/src/main/java/com/xxl/service/job/JobDetailDemo.java b/xxl-job-admin/src/main/java/com/xxl/service/job/JobDetailDemo.java similarity index 100% rename from xxl-job-demo/src/main/java/com/xxl/service/job/JobDetailDemo.java rename to xxl-job-admin/src/main/java/com/xxl/service/job/JobDetailDemo.java diff --git a/xxl-job-demo/src/test/java/quartz/TestDynamicJob.java b/xxl-job-admin/src/main/java/com/xxl/service/job/TestDynamicJob.java similarity index 56% rename from xxl-job-demo/src/test/java/quartz/TestDynamicJob.java rename to xxl-job-admin/src/main/java/com/xxl/service/job/TestDynamicJob.java index 8e4f93de..bd2283e5 100644 --- a/xxl-job-demo/src/test/java/quartz/TestDynamicJob.java +++ b/xxl-job-admin/src/main/java/com/xxl/service/job/TestDynamicJob.java @@ -1,4 +1,4 @@ -package quartz; +package com.xxl.service.job; import org.quartz.Job; import org.quartz.JobExecutionContext; @@ -11,7 +11,7 @@ public class TestDynamicJob implements Job { @Override public void execute(JobExecutionContext context) throws JobExecutionException { - final Object mailGuid = context.getMergedJobDataMap().get("mailGuid"); - System.out.println("[Dynamic-Job] It is " + new Date() + " now, mailGuid=" + mailGuid); + Object mailGuid = context.getMergedJobDataMap().get("mailGuid"); + System.out.println("[demo-job] run at " + new Date() + " now, mailGuid=" + mailGuid); } } \ No newline at end of file diff --git a/xxl-job-demo/src/main/resources/applicationcontext-trigger-db.xml b/xxl-job-admin/src/main/resources/applicationcontext-trigger-db.xml similarity index 100% rename from xxl-job-demo/src/main/resources/applicationcontext-trigger-db.xml rename to xxl-job-admin/src/main/resources/applicationcontext-trigger-db.xml diff --git a/xxl-job-demo/src/main/resources/applicationcontext-trigger-local.xml b/xxl-job-admin/src/main/resources/applicationcontext-trigger-local.xml similarity index 94% rename from xxl-job-demo/src/main/resources/applicationcontext-trigger-local.xml rename to xxl-job-admin/src/main/resources/applicationcontext-trigger-local.xml index ffc06c6c..c494d6a5 100644 --- a/xxl-job-demo/src/main/resources/applicationcontext-trigger-local.xml +++ b/xxl-job-admin/src/main/resources/applicationcontext-trigger-local.xml @@ -19,7 +19,7 @@ - + diff --git a/xxl-job-admin/src/main/resources/applicationcontext-trigger.xml b/xxl-job-admin/src/main/resources/applicationcontext-trigger.xml deleted file mode 100644 index ebd95531..00000000 --- a/xxl-job-admin/src/main/resources/applicationcontext-trigger.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/xxl-job-admin/src/main/resources/log4j.properties b/xxl-job-admin/src/main/resources/log4j.properties index 77966c63..60ca14ad 100644 --- a/xxl-job-admin/src/main/resources/log4j.properties +++ b/xxl-job-admin/src/main/resources/log4j.properties @@ -2,9 +2,9 @@ log4j.rootLogger=info,console log4j.appender.console=org.apache.log4j.ConsoleAppender log4j.appender.console.layout=org.apache.log4j.PatternLayout -log4j.appender.console.layout.ConversionPattern=%d - xxl-job-admin - %p [%c] - <%m>%n +log4j.appender.console.layout.ConversionPattern=%d - xxl-job-demo - %p [%c] - <%m>%n log4j.appender.logFile=org.apache.log4j.DailyRollingFileAppender -log4j.appender.logFile.File=${catalina.base}/logs/xxl-job-admin.log +log4j.appender.logFile.File=${catalina.base}/logs/xxl-job-demo.log log4j.appender.logFile.layout=org.apache.log4j.PatternLayout -log4j.appender.logFile.layout.ConversionPattern=%d - xxl-job-admin - %p [%c] - <%m>%n +log4j.appender.logFile.layout.ConversionPattern=%d - xxl-job-demo - %p [%c] - <%m>%n diff --git a/xxl-job-demo/src/main/resources/quartz.properties b/xxl-job-admin/src/main/resources/quartz.properties similarity index 100% rename from xxl-job-demo/src/main/resources/quartz.properties rename to xxl-job-admin/src/main/resources/quartz.properties diff --git a/xxl-job-admin/src/test/java/Test.java b/xxl-job-admin/src/test/java/Test.java deleted file mode 100644 index 74d954e7..00000000 --- a/xxl-job-admin/src/test/java/Test.java +++ /dev/null @@ -1,65 +0,0 @@ -import java.util.Date; -import java.util.Timer; - -import org.apache.commons.lang.time.FastDateFormat; - - -public class Test { - - static class DemoTimeTask extends java.util.TimerTask { - public void run() { - System.out.println("run:" + FastDateFormat.getInstance("yyyy-MM-dd HH:mm:ss").format(new Date())); - } - } - - // ??? 某一个时间段内,重复执行 - - // runTime:第一次执行时间 - // delay: 延迟执行的毫秒数,即在delay毫秒之后第一次执行 - // period:重复执行的时间间隔 - public static Timer mainTimer; - public static void main(String[] args) { - // 调度器 - mainTimer = new Timer(); - // Demo任务 - DemoTimeTask timeTask = new DemoTimeTask(); - System.out.println("now:" + FastDateFormat.getInstance("yyyy-MM-dd HH:mm:ss").format(new Date())); - - // 1、在特定时间执行任务,只执行一次 - //Date runTime = DateUtils.addSeconds(new Date(), 1); - //mainTimer.schedule(timeTask, runTime); // runTime - - // 2、在特定时间之后执行任务,只执行一次 - //long delay = 1000; - //mainTimer.schedule(timeTask, delay); // delay/ms - - // 3、指定第一次执行的时间,然后按照间隔时间,重复执行 - //Date firstTime = DateUtils.addSeconds(new Date(), 1); - //long period = 1000; - //mainTimer.schedule(timeTask, firstTime, period); // "period/ms" after "firstTime" - - // 4、在特定延迟之后第一次执行,然后按照间隔时间,重复执行 - //long delay = 1000; - //long period = 1000; - //mainTimer.schedule(timeTask, delay, period); // "period/ms" after "delay/ms" - - // 5、第一次执行之后,特定频率执行,与3同 - //Date firstTime = DateUtils.addSeconds(new Date(), 1); - //long period = 1000; - //mainTimer.scheduleAtFixedRate(timeTask, firstTime, period); - - // 6、在delay毫秒之后第一次执行,后按照特定频率执行 - long delay = 1000; - long period = 1000; - mainTimer.scheduleAtFixedRate(timeTask, delay, period); - /** - * <1>schedule()方法更注重保持间隔时间的稳定:保障每隔period时间可调用一次 - * <2>scheduleAtFixedRate()方法更注重保持执行频率的稳定:保障多次调用的频率趋近于period时间,如果任务执行时间大于period,会在任务执行之后马上执行下一次任务 - */ - - // Timer注销 - mainTimer.cancel(); - - } - -} diff --git a/xxl-job-admin/src/test/java/quartz/JunitTest.java b/xxl-job-admin/src/test/java/quartz/JunitTest.java new file mode 100644 index 00000000..a066e734 --- /dev/null +++ b/xxl-job-admin/src/test/java/quartz/JunitTest.java @@ -0,0 +1,65 @@ +package quartz; + + +import java.lang.reflect.InvocationTargetException; +import java.util.Set; +import java.util.concurrent.TimeUnit; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.quartz.JobKey; +import org.quartz.SchedulerException; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import com.xxl.quartz.DynamicSchedulerUtil; +import com.xxl.service.job.TestDynamicJob; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(locations = "classpath*:applicationcontext-*.xml") +public class JunitTest { + + @Test + public void getJobKeys() throws SchedulerException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, InterruptedException { + Set list = DynamicSchedulerUtil.getJobKeys(); + System.out.println(list); + TimeUnit.SECONDS.sleep(30); + } + + @Test + public void addJob() throws SchedulerException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, InterruptedException { + boolean ret = DynamicSchedulerUtil.addJob("demo-job02", "0/2 * * * * ?", TestDynamicJob.class, null); + System.out.println(ret); + TimeUnit.SECONDS.sleep(30); + } + + @Test + public void removeJob() throws SchedulerException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, InterruptedException { + boolean ret = DynamicSchedulerUtil.removeJob("demo-job02"); + System.out.println(ret); + TimeUnit.SECONDS.sleep(30); + } + + @Test + public void rescheduleJob() throws SchedulerException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, InterruptedException { + boolean ret = DynamicSchedulerUtil.rescheduleJob("demo-job02", "0/3 * * * * ?"); + System.out.println(ret); + TimeUnit.SECONDS.sleep(30); + } + + @Test + public void pauseJob() throws SchedulerException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, InterruptedException { + boolean ret = DynamicSchedulerUtil.pauseJob("demo-job02"); + System.out.println(ret); + TimeUnit.SECONDS.sleep(30); + } + + @Test + public void resumeTrigger() throws SchedulerException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, InterruptedException { + boolean ret = DynamicSchedulerUtil.resumeTrigger("demo-job02"); + System.out.println(ret); + TimeUnit.SECONDS.sleep(30); + } + + +} diff --git a/xxl-job-demo/pom.xml b/xxl-job-demo/pom.xml deleted file mode 100644 index 118a158f..00000000 --- a/xxl-job-demo/pom.xml +++ /dev/null @@ -1,164 +0,0 @@ - - 4.0.0 - - com.xxl - xxl-job - 0.0.1-SNAPSHOT - - xxl-job-demo - war - - - 3.2.14.RELEASE - - - - - - org.springframework - spring-webmvc - ${spring.version} - - - org.springframework - spring-context-support - ${spring.version} - - - org.springframework - spring-orm - ${spring.version} - - - org.springframework - spring-test - ${spring.version} - - - - - org.aspectj - aspectjweaver - 1.8.7 - - - - org.codehaus.jackson - jackson-mapper-asl - 1.9.13 - - - - - org.slf4j - slf4j-log4j12 - 1.7.5 - - - - - org.freemarker - freemarker - 2.3.20 - - - - - commons-beanutils - commons-beanutils - 1.9.2 - - - - commons-lang - commons-lang - 2.6 - - - - - javax.servlet - servlet-api - 2.5 - provided - - - javax.servlet.jsp - jsp-api - 2.1 - provided - - - - - junit - junit - 4.11 - test - - - - - c3p0 - c3p0 - 0.9.1.2 - - - - org.mybatis - mybatis-spring - 1.2.2 - - - org.mybatis - mybatis - 3.2.8 - - - - mysql - mysql-connector-java - 5.1.29 - - - - - org.quartz-scheduler - quartz - 2.2.1 - - - - com.xxl - xxl-job-core - 0.0.1-SNAPSHOT - - - - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.1 - - 1.6 - 1.6 - UTF8 - - - - org.apache.maven.plugins - maven-war-plugin - 2.2 - - true - - - - - diff --git a/xxl-job-demo/src/main/java/com/xxl/controller/IndexController.java b/xxl-job-demo/src/main/java/com/xxl/controller/IndexController.java deleted file mode 100644 index 746210e5..00000000 --- a/xxl-job-demo/src/main/java/com/xxl/controller/IndexController.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.xxl.controller; - -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.ResponseBody; - -@Controller -@RequestMapping("/") -public class IndexController { - - @RequestMapping("") - @ResponseBody - private String index() { - return "hehe"; - } -} diff --git a/xxl-job-demo/src/main/java/com/xxl/quartz/DynamicSchedulerUtil.java b/xxl-job-demo/src/main/java/com/xxl/quartz/DynamicSchedulerUtil.java deleted file mode 100644 index 9d086528..00000000 --- a/xxl-job-demo/src/main/java/com/xxl/quartz/DynamicSchedulerUtil.java +++ /dev/null @@ -1,90 +0,0 @@ -package com.xxl.quartz; - -import org.quartz.*; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.InitializingBean; -import org.springframework.util.Assert; - -import java.util.Date; - -public final class DynamicSchedulerUtil implements InitializingBean { - private static final Logger logger = LoggerFactory.getLogger(DynamicSchedulerUtil.class); - - // Scheduler - private static Scheduler scheduler; - public static void setScheduler(Scheduler scheduler) { - DynamicSchedulerUtil.scheduler = scheduler; - } - - @Override - public void afterPropertiesSet() throws Exception { - Assert.notNull(scheduler, "quartz scheduler is null"); - logger.info(">>>>>>>>> init quartz scheduler success.[{}]", scheduler); - } - - // Add 新增 - public static boolean addJob(JobModel job) throws SchedulerException { - final TriggerKey triggerKey = job.getTriggerKey(); - if (scheduler.checkExists(triggerKey)) { - final Trigger trigger = scheduler.getTrigger(triggerKey); - logger.info(">>>>>>>>> Already exist trigger [" + trigger + "] by key [" + triggerKey + "] in Scheduler"); - return false; - } - - final CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule(job.getCronExpression()); - final CronTrigger cronTrigger = TriggerBuilder.newTrigger().withIdentity(triggerKey) - .withSchedule(cronScheduleBuilder) - .build(); - - final JobDetail jobDetail = job.getJobDetail(); - final Date date = scheduler.scheduleJob(jobDetail, cronTrigger); - - logger.debug("Register DynamicJob {} on [{}]", job, date); - return true; - } - - // Pause 暂停-指定Job - public static boolean pauseJob(JobModel existJob) throws SchedulerException { - final TriggerKey triggerKey = existJob.getTriggerKey(); - boolean result = false; - if (scheduler.checkExists(triggerKey)) { - scheduler.pauseTrigger(triggerKey); - result = true; - logger.debug("Pause exist DynamicJob {}, triggerKey [{}] successful", existJob, triggerKey); - } else { - logger.debug("Failed pause exist DynamicJob {}, because not fount triggerKey [{}]", existJob, triggerKey); - } - return result; - } - - // Resume 重启-指定Job - public static boolean resumeJob(JobModel existJob) throws SchedulerException { - final TriggerKey triggerKey = existJob.getTriggerKey(); - boolean result = false; - if (scheduler.checkExists(triggerKey)) { - final CronTrigger newTrigger = existJob.cronTrigger(); - final Date date = scheduler.rescheduleJob(triggerKey, newTrigger); - - result = true; - logger.debug("Resume exist DynamicJob {}, triggerKey [{}] on [{}] successful", existJob, triggerKey, date); - } else { - logger.debug("Failed resume exist DynamicJob {}, because not fount triggerKey [{}]", existJob, triggerKey); - } - return result; - } - - // Remove exists job 移除-指定Job - public static boolean removeJob(JobModel existJob) throws SchedulerException { - final TriggerKey triggerKey = existJob.getTriggerKey(); - boolean result = false; - if (scheduler.checkExists(triggerKey)) { - result = scheduler.unscheduleJob(triggerKey); - } - - logger.debug("Remove DynamicJob {} result [{}]", existJob, result); - return result; - } - - -} \ No newline at end of file diff --git a/xxl-job-demo/src/main/java/com/xxl/quartz/JobModel.java b/xxl-job-demo/src/main/java/com/xxl/quartz/JobModel.java deleted file mode 100644 index d809e9d5..00000000 --- a/xxl-job-demo/src/main/java/com/xxl/quartz/JobModel.java +++ /dev/null @@ -1,77 +0,0 @@ -package com.xxl.quartz; - -import org.quartz.CronScheduleBuilder; -import org.quartz.CronTrigger; -import org.quartz.Job; -import org.quartz.JobBuilder; -import org.quartz.JobDataMap; -import org.quartz.JobDetail; -import org.quartz.Scheduler; -import org.quartz.TriggerBuilder; -import org.quartz.TriggerKey; - -/** - * 任务model - * @author xuxueli 2015-12-1 16:01:19 - */ -public class JobModel { - - // param - private String group; - private String name; - private String cronExpression; - private Class jobClass; - - public JobModel(String name, String cronExpression, Class jobClass) { - this.group = Scheduler.DEFAULT_GROUP; - this.name = name; - this.cronExpression = cronExpression; - this.jobClass = jobClass; - } - - public String getGroup() { - return group; - } - public void setGroup(String group) { - this.group = group; - } - public String getName() { - return name; - } - public void setName(String name) { - this.name = name; - } - public String getCronExpression() { - return cronExpression; - } - public void setCronExpression(String cronExpression) { - this.cronExpression = cronExpression; - } - public Class getJobClass() { - return jobClass; - } - public void setJobClass(Class jobClass) { - this.jobClass = jobClass; - } - - // TriggerKey - public TriggerKey getTriggerKey() { - return TriggerKey.triggerKey(this.name, this.group); - } - // JobDetail - public JobDetail getJobDetail() { - return JobBuilder.newJob(jobClass).withIdentity(this.name, this.group).build(); - } - // JobDataMap.add - public JobModel addJobData(String key, Object value) { - JobDataMap jobDataMap = this.getJobDetail().getJobDataMap(); - jobDataMap.put(key, value); - return this; - } - // CronTrigger - public CronTrigger cronTrigger() { - CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule(this.cronExpression); - return TriggerBuilder.newTrigger().withIdentity(this.getTriggerKey()).withSchedule(cronScheduleBuilder).build(); - } - -} \ No newline at end of file diff --git a/xxl-job-demo/src/main/java/com/xxl/service/ITriggerService.java b/xxl-job-demo/src/main/java/com/xxl/service/ITriggerService.java deleted file mode 100644 index 745c89fc..00000000 --- a/xxl-job-demo/src/main/java/com/xxl/service/ITriggerService.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.xxl.service; - -/** - * Trigger Service - * @author xuxueli - */ -public interface ITriggerService { - - /** - * 全站静态化 - */ - public void generateNetHtml(); -} diff --git a/xxl-job-demo/src/main/java/com/xxl/service/impl/TriggerServiceImpl.java b/xxl-job-demo/src/main/java/com/xxl/service/impl/TriggerServiceImpl.java deleted file mode 100644 index ec0a2fd8..00000000 --- a/xxl-job-demo/src/main/java/com/xxl/service/impl/TriggerServiceImpl.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.xxl.service.impl; - -import java.util.Date; - -import org.apache.commons.lang.time.FastDateFormat; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Service; - -import com.xxl.service.ITriggerService; - -/** - * Trigger Service - * @author xuxueli - */ -@Service("triggerService") -public class TriggerServiceImpl implements ITriggerService { - private static transient Logger logger = LoggerFactory.getLogger(TriggerServiceImpl.class); - - - /** - * 全站静态化 - */ - public void generateNetHtml() { - logger.info("全站静态化 run at :{}", FastDateFormat.getInstance("yyyy-MM-dd HH:mm:ss").format(new Date())); - } - -} diff --git a/xxl-job-demo/src/main/resources/applicationcontext-base.xml b/xxl-job-demo/src/main/resources/applicationcontext-base.xml deleted file mode 100644 index e63b7982..00000000 --- a/xxl-job-demo/src/main/resources/applicationcontext-base.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - classpath*:jdbc.properties - - - - - \ No newline at end of file diff --git a/xxl-job-demo/src/main/resources/applicationcontext-database.xml b/xxl-job-demo/src/main/resources/applicationcontext-database.xml deleted file mode 100644 index cdb291a1..00000000 --- a/xxl-job-demo/src/main/resources/applicationcontext-database.xml +++ /dev/null @@ -1,43 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/xxl-job-demo/src/main/resources/applicationcontext-tx.xml b/xxl-job-demo/src/main/resources/applicationcontext-tx.xml deleted file mode 100644 index 2511344b..00000000 --- a/xxl-job-demo/src/main/resources/applicationcontext-tx.xml +++ /dev/null @@ -1,44 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/xxl-job-demo/src/main/resources/freemarker.properties b/xxl-job-demo/src/main/resources/freemarker.properties deleted file mode 100644 index fbc42ea5..00000000 --- a/xxl-job-demo/src/main/resources/freemarker.properties +++ /dev/null @@ -1,10 +0,0 @@ -template_update_delay=0 -default_encoding=UTF-8 -output_encoding=UTF-8 -locale=zh_CN -number_format=0.########## -date_format=yyyy-MM-dd -time_format=HH:mm:ss -datetime_format=yyyy-MM-dd HH:mm:s -classic_compatible=true -template_exception_handler=ignore \ No newline at end of file diff --git a/xxl-job-demo/src/main/resources/freemarker.variables.properties b/xxl-job-demo/src/main/resources/freemarker.variables.properties deleted file mode 100644 index bbbd6077..00000000 --- a/xxl-job-demo/src/main/resources/freemarker.variables.properties +++ /dev/null @@ -1,2 +0,0 @@ -# 静态文件地址 -static_url=https://www.baidu.com/ \ No newline at end of file diff --git a/xxl-job-demo/src/main/resources/jdbc.properties b/xxl-job-demo/src/main/resources/jdbc.properties deleted file mode 100644 index ff308dab..00000000 --- a/xxl-job-demo/src/main/resources/jdbc.properties +++ /dev/null @@ -1,4 +0,0 @@ -c3p0.driverClass=com.mysql.jdbc.Driver -c3p0.url=jdbc:mysql://localhost:3306/test?Unicode=true&characterEncoding=UTF-8 -c3p0.user=root -c3p0.password=root_pwd \ No newline at end of file diff --git a/xxl-job-demo/src/main/resources/log4j.properties b/xxl-job-demo/src/main/resources/log4j.properties deleted file mode 100644 index 60ca14ad..00000000 --- a/xxl-job-demo/src/main/resources/log4j.properties +++ /dev/null @@ -1,10 +0,0 @@ -log4j.rootLogger=info,console - -log4j.appender.console=org.apache.log4j.ConsoleAppender -log4j.appender.console.layout=org.apache.log4j.PatternLayout -log4j.appender.console.layout.ConversionPattern=%d - xxl-job-demo - %p [%c] - <%m>%n - -log4j.appender.logFile=org.apache.log4j.DailyRollingFileAppender -log4j.appender.logFile.File=${catalina.base}/logs/xxl-job-demo.log -log4j.appender.logFile.layout=org.apache.log4j.PatternLayout -log4j.appender.logFile.layout.ConversionPattern=%d - xxl-job-demo - %p [%c] - <%m>%n diff --git a/xxl-job-demo/src/main/resources/springmvc-context.xml b/xxl-job-demo/src/main/resources/springmvc-context.xml deleted file mode 100644 index 86ea71c2..00000000 --- a/xxl-job-demo/src/main/resources/springmvc-context.xml +++ /dev/null @@ -1,50 +0,0 @@ - - - - Spring-web MVC配置 - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/xxl-job-demo/src/main/webapp/WEB-INF/web.xml b/xxl-job-demo/src/main/webapp/WEB-INF/web.xml deleted file mode 100644 index 45d238af..00000000 --- a/xxl-job-demo/src/main/webapp/WEB-INF/web.xml +++ /dev/null @@ -1,55 +0,0 @@ - - - xxl-job-demo - - - contextConfigLocation - classpath*:applicationcontext-*.xml - - - - org.springframework.web.util.Log4jConfigListener - - - org.springframework.web.context.ContextLoaderListener - - - - encodingFilter - org.springframework.web.filter.CharacterEncodingFilter - - encoding - UTF-8 - - - forceEncoding - true - - - - encodingFilter - /* - - - - springmvc - org.springframework.web.servlet.DispatcherServlet - - contextConfigLocation - classpath*:springmvc-context.xml - - 1 - - - springmvc - / - - - - index.html - - - \ No newline at end of file diff --git a/xxl-job-demo/src/test/java/quartz/JunitTest.java b/xxl-job-demo/src/test/java/quartz/JunitTest.java deleted file mode 100644 index 4415a63f..00000000 --- a/xxl-job-demo/src/test/java/quartz/JunitTest.java +++ /dev/null @@ -1,30 +0,0 @@ -package quartz; - - -import java.lang.reflect.InvocationTargetException; -import java.util.concurrent.TimeUnit; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.quartz.SchedulerException; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -import com.xxl.quartz.DynamicSchedulerUtil; -import com.xxl.quartz.JobModel; - -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations = "classpath*:applicationcontext-*.xml") -public class JunitTest { - - @Test - public void addJob() throws SchedulerException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, InterruptedException { - boolean ret = DynamicSchedulerUtil.addJob(new JobModel("Jost-job", "0/1 * * * * ?", TestDynamicJob.class)); - System.out.println(ret); - TimeUnit.SECONDS.sleep(30); - } - - - - -}