类org.quartz.impl.triggers.CronTriggerImpl源码实例Demo

下面列出了怎么用org.quartz.impl.triggers.CronTriggerImpl的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: GOAi   文件: ScheduledInfo.java
/**
 * 设置触发器
 */
private void initCronTrigger() {
    if (!useful(this.cron)) {
        return;
    }
    try {
        CronTriggerImpl cronTrigger = new CronTriggerImpl();
        cronTrigger.setCronExpression(this.cron);
        this.tip = "cron: " + this.cron;
        this.trigger = cronTrigger;
        this.fixedRate = -1;
        this.delay = -1;
    } catch (ParseException e) {
        log.error("can not format {} to cron", this.cron);
    }
}
 
源代码2 项目: GOAi   文件: TaskManager.java
/**
 * 添加任务
 */
private ScheduleJob checkJob(ScheduledMethod mt, int number) {
    Method method = mt.getMethod();
    Trigger trigger = mt.getScheduledInfo().getTrigger();
    String description = this.id + "-" + method.getName() + "-" + number;
    this.log.info("{} {}", description, mt.getScheduledInfo().getTip());
    JobDetail jobDetail = JobBuilder.newJob(ScheduledJob.class)
            .withDescription(description)
            .withIdentity(this.taskClass.getSimpleName(), description)
            .build();
    if (trigger instanceof CronTriggerImpl) {
        ((CronTriggerImpl) trigger).setName(description);
    }
    if (trigger instanceof SimpleTriggerImpl) {
        ((SimpleTriggerImpl) trigger).setName(description);
    }
    return new ScheduleJob(jobDetail, trigger);
}
 
源代码3 项目: TAC   文件: JobController.java
public void jobReschedule(String jobName, String jobGroupName, String cronExpression) throws Exception
{				
	try {
		TriggerKey triggerKey = TriggerKey.triggerKey(jobName, jobGroupName);
		// 表达式调度构建器
		CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(cronExpression);

		CronTrigger trigger = (CronTrigger) scheduler.getTrigger(triggerKey);

		// 按新的cronExpression表达式重新构建trigger
		trigger = trigger.getTriggerBuilder().withIdentity(triggerKey).withSchedule(scheduleBuilder).build();
           ((CronTriggerImpl)trigger).setStartTime(new Date());
		// 按新的trigger重新设置job执行
		scheduler.rescheduleJob(triggerKey, trigger);
	} catch (SchedulerException e) {
		System.out.println("更新定时任务失败"+e);
		throw new Exception("更新定时任务失败");
	}
}
 
源代码4 项目: uflo   文件: SchedulerServiceImpl.java
private void initScanReminderJob(){
	CronTriggerImpl trigger=new CronTriggerImpl();
	trigger.setName("UfloScanReminderTrigger");
	trigger.setKey(new TriggerKey("UfloScanReminderTrigger"));
	try {
		trigger.setCronExpression(SCAN_REMINDER_CRON);
		ScanReminderJob job=new ScanReminderJob();
		ScanReminderJobDetail detail=new ScanReminderJobDetail();
		detail.setSchedulerService(this);
		detail.setTaskService(taskService);
		detail.setReminderTaskList(reminderTaskList);
		detail.setJobClass(job.getClass());
		detail.setKey(new JobKey("UfloScanReminderJob"));
		scheduler.scheduleJob(detail, trigger);
	} catch (Exception e1) {
		throw new RuntimeException(e1);
	}
}
 
源代码5 项目: quartz-redis-jobstore   文件: StoreTriggerTest.java
@Test
public void storeTrigger() throws Exception {
    CronTriggerImpl trigger = getCronTrigger();
    trigger.getJobDataMap().put("foo", "bar");

    jobStore.storeTrigger(trigger, false);

    final String triggerHashKey = schema.triggerHashKey(trigger.getKey());
    Map<String, String> triggerMap = jedis.hgetAll(triggerHashKey);
    assertThat(triggerMap, hasKey("description"));
    assertEquals(trigger.getDescription(), triggerMap.get("description"));
    assertThat(triggerMap, hasKey("trigger_class"));
    assertEquals(trigger.getClass().getName(), triggerMap.get("trigger_class"));

    assertTrue("The trigger hash key is not a member of the triggers set.", jedis.sismember(schema.triggersSet(), triggerHashKey));
    assertTrue("The trigger group set key is not a member of the trigger group set.", jedis.sismember(schema.triggerGroupsSet(), schema.triggerGroupSetKey(trigger.getKey())));
    assertTrue(jedis.sismember(schema.triggerGroupSetKey(trigger.getKey()), triggerHashKey));
    assertTrue(jedis.sismember(schema.jobTriggersSetKey(trigger.getJobKey()), triggerHashKey));
    String triggerDataMapHashKey = schema.triggerDataMapHashKey(trigger.getKey());
    MatcherAssert.assertThat(jedis.exists(triggerDataMapHashKey), equalTo(true));
    MatcherAssert.assertThat(jedis.hget(triggerDataMapHashKey, "foo"), equalTo("bar"));
}
 
源代码6 项目: quartz-redis-jobstore   文件: StoreTriggerTest.java
@Test
public void retrieveTrigger() throws Exception {
    CronTriggerImpl cronTrigger = getCronTrigger();
    jobStore.storeJob(getJobDetail(), false);
    jobStore.storeTrigger(cronTrigger, false);

    OperableTrigger operableTrigger = jobStore.retrieveTrigger(cronTrigger.getKey());

    assertThat(operableTrigger, instanceOf(CronTriggerImpl.class));
    assertThat(operableTrigger.getFireInstanceId(), notNullValue());
    CronTriggerImpl retrievedTrigger = (CronTriggerImpl) operableTrigger;

    assertEquals(cronTrigger.getCronExpression(), retrievedTrigger.getCronExpression());
    assertEquals(cronTrigger.getTimeZone(), retrievedTrigger.getTimeZone());
    assertEquals(cronTrigger.getStartTime(), retrievedTrigger.getStartTime());
}
 
源代码7 项目: quartz-redis-jobstore   文件: StoreTriggerTest.java
@Test
public void removeTrigger() throws Exception {
    JobDetail job = getJobDetail();
    CronTriggerImpl trigger1 = getCronTrigger("trigger1", "triggerGroup", job.getKey());
    trigger1.getJobDataMap().put("foo", "bar");
    CronTriggerImpl trigger2 = getCronTrigger("trigger2", "triggerGroup", job.getKey());

    jobStore.storeJob(job, false);
    jobStore.storeTrigger(trigger1, false);
    jobStore.storeTrigger(trigger2, false);

    jobStore.removeTrigger(trigger1.getKey());

    // ensure that the trigger was removed, but the job was not
    assertThat(jobStore.retrieveTrigger(trigger1.getKey()), nullValue());
    assertThat(jobStore.retrieveJob(job.getKey()), not(nullValue()));

    // remove the second trigger
    jobStore.removeTrigger(trigger2.getKey());

    //  ensure that both the trigger and job were removed
    assertThat(jobStore.retrieveTrigger(trigger2.getKey()), nullValue());
    assertThat(jobStore.retrieveJob(job.getKey()), nullValue());
    MatcherAssert.assertThat(jedis.exists(schema.triggerDataMapHashKey(trigger1.getKey())), equalTo(false));
}
 
源代码8 项目: quartz-redis-jobstore   文件: StoreTriggerTest.java
@Test
public void getTriggerState() throws Exception {
    SchedulerSignaler signaler = mock(SchedulerSignaler.class);
    AbstractRedisStorage storageDriver = new RedisStorage(new RedisJobStoreSchema(), new ObjectMapper(), signaler, "scheduler1", 2000);

    // attempt to retrieve the state of a non-existent trigger
    Trigger.TriggerState state = jobStore.getTriggerState(new TriggerKey("foobar"));
    assertEquals(Trigger.TriggerState.NONE, state);

    // store a trigger
    JobDetail job = getJobDetail();
    CronTriggerImpl cronTrigger = getCronTrigger("trigger1", "group1", job.getKey());
    jobStore.storeTrigger(cronTrigger, false);

    // the newly-stored trigger's state should be NONE
    state = jobStore.getTriggerState(cronTrigger.getKey());
    assertEquals(Trigger.TriggerState.NORMAL, state);

    // set the trigger's state
    storageDriver.setTriggerState(RedisTriggerState.WAITING, 500, schema.triggerHashKey(cronTrigger.getKey()), jedis);

    // the trigger's state should now be NORMAL
    state = jobStore.getTriggerState(cronTrigger.getKey());
    assertEquals(Trigger.TriggerState.NORMAL, state);
}
 
源代码9 项目: quartz-redis-jobstore   文件: StoreTriggerTest.java
@Test
public void pauseTriggersStartsWith() throws Exception {
    JobDetail job = getJobDetail();
    CronTriggerImpl trigger1 = getCronTrigger("trigger1", "group1", job.getKey());
    CronTriggerImpl trigger2 = getCronTrigger("trigger1", "group2", job.getKey());
    CronTriggerImpl trigger3 = getCronTrigger("trigger1", "foogroup1", job.getKey());
    storeJobAndTriggers(job, trigger1, trigger2, trigger3);

    Collection<String> pausedTriggerGroups = jobStore.pauseTriggers(GroupMatcher.triggerGroupStartsWith("group"));

    assertThat(pausedTriggerGroups, hasSize(2));
    assertThat(pausedTriggerGroups, containsInAnyOrder("group1", "group2"));

    assertEquals(Trigger.TriggerState.PAUSED, jobStore.getTriggerState(trigger1.getKey()));
    assertEquals(Trigger.TriggerState.PAUSED, jobStore.getTriggerState(trigger2.getKey()));
    assertEquals(Trigger.TriggerState.NORMAL, jobStore.getTriggerState(trigger3.getKey()));
}
 
源代码10 项目: quartz-redis-jobstore   文件: StoreTriggerTest.java
@Test
public void pauseTriggersEndsWith() throws Exception {
    JobDetail job = getJobDetail();
    CronTriggerImpl trigger1 = getCronTrigger("trigger1", "group1", job.getKey());
    CronTriggerImpl trigger2 = getCronTrigger("trigger1", "group2", job.getKey());
    CronTriggerImpl trigger3 = getCronTrigger("trigger1", "foogroup1", job.getKey());
    storeJobAndTriggers(job, trigger1, trigger2, trigger3);

    Collection<String> pausedGroups = jobStore.pauseTriggers(GroupMatcher.triggerGroupEndsWith("oup1"));

    assertThat(pausedGroups, hasSize(2));
    assertThat(pausedGroups, containsInAnyOrder("group1", "foogroup1"));

    assertEquals(Trigger.TriggerState.PAUSED, jobStore.getTriggerState(trigger1.getKey()));
    assertEquals(Trigger.TriggerState.NORMAL, jobStore.getTriggerState(trigger2.getKey()));
    assertEquals(Trigger.TriggerState.PAUSED, jobStore.getTriggerState(trigger3.getKey()));
}
 
源代码11 项目: quartz-redis-jobstore   文件: StoreTriggerTest.java
@Test
public void resumeTrigger() throws Exception {
    // create and store a job and trigger
    JobDetail job = getJobDetail();
    jobStore.storeJob(job, false);
    CronTriggerImpl trigger = getCronTrigger("trigger1", "group1", job.getKey());
    trigger.computeFirstFireTime(new WeeklyCalendar());
    jobStore.storeTrigger(trigger, false);

    // pause the trigger
    jobStore.pauseTrigger(trigger.getKey());
    assertEquals(Trigger.TriggerState.PAUSED, jobStore.getTriggerState(trigger.getKey()));

    // resume the trigger
    jobStore.resumeTrigger(trigger.getKey());
    // the trigger state should now be NORMAL
    assertEquals(Trigger.TriggerState.NORMAL, jobStore.getTriggerState(trigger.getKey()));

    // attempt to resume the trigger, again
    jobStore.resumeTrigger(trigger.getKey());
    // the trigger state should not have changed
    assertEquals(Trigger.TriggerState.NORMAL, jobStore.getTriggerState(trigger.getKey()));
}
 
源代码12 项目: quartz-redis-jobstore   文件: StoreTriggerTest.java
@Test
public void resumeTriggersStartsWith() throws Exception {
    JobDetail job = getJobDetail();
    CronTriggerImpl trigger1 = getCronTrigger("trigger1", "mygroup1", job.getKey());
    CronTriggerImpl trigger2 = getCronTrigger("trigger2", "group1", job.getKey());
    CronTriggerImpl trigger3 = getCronTrigger("trigger3", "group2", job.getKey());
    CronTriggerImpl trigger4 = getCronTrigger("trigger4", "group3", job.getKey());
    storeJobAndTriggers(job, trigger1, trigger2, trigger3, trigger4);

    Collection<String> pausedGroups = jobStore.pauseTriggers(GroupMatcher.triggerGroupStartsWith("my"));

    assertThat(pausedGroups, hasSize(1));
    assertThat(pausedGroups, containsInAnyOrder("mygroup1"));

    // ensure that the triggers were actually paused
    assertEquals(Trigger.TriggerState.PAUSED, jobStore.getTriggerState(trigger1.getKey()));

    // resume triggers
    Collection<String> resumedGroups = jobStore.resumeTriggers(GroupMatcher.triggerGroupStartsWith("my"));

    assertThat(resumedGroups, hasSize(1));
    assertThat(resumedGroups, containsInAnyOrder("mygroup1"));

    // ensure that the triggers were actually resumed
    assertEquals(Trigger.TriggerState.NORMAL, jobStore.getTriggerState(trigger1.getKey()));
}
 
源代码13 项目: quartz-redis-jobstore   文件: StoreTriggerTest.java
@Test
public void replaceTriggerSingleTriggerNonDurableJob() throws Exception {
    // store trigger and job
    JobDetail job = getJobDetail();
    CronTriggerImpl trigger1 = getCronTrigger("trigger1", "group1", job.getKey());
    storeJobAndTriggers(job, trigger1);

    CronTriggerImpl newTrigger = getCronTrigger("newTrigger", "group1", job.getKey());

    assertTrue(jobStore.replaceTrigger(trigger1.getKey(), newTrigger));

    // ensure that the proper trigger was replaced
    assertThat(jobStore.retrieveTrigger(trigger1.getKey()), nullValue());

    List<OperableTrigger> jobTriggers = jobStore.getTriggersForJob(job.getKey());

    assertThat(jobTriggers, hasSize(1));

    // ensure that the job still exists
    assertThat(jobStore.retrieveJob(job.getKey()), not(nullValue()));
}
 
源代码14 项目: quartz-redis-jobstore   文件: StoreJobTest.java
@Test
public void removeJob() throws Exception {
    // attempt to remove a non-existent job
    assertFalse(jobStore.removeJob(JobKey.jobKey("foo", "bar")));

    // create and store a job with multiple triggers
    JobDetail job = getJobDetail("job1", "jobGroup1");
    CronTriggerImpl trigger1 = getCronTrigger("trigger1", "triggerGroup1", job.getKey());
    CronTriggerImpl trigger2 = getCronTrigger("trigger2", "triggerGroup1", job.getKey());
    Set<Trigger> triggersSet = new HashSet<>();
    triggersSet.add(trigger1);
    triggersSet.add(trigger2);
    Map<JobDetail, Set<? extends Trigger>> jobsAndTriggers = new HashMap<>();
    jobsAndTriggers.put(job, triggersSet);
    jobStore.storeJobsAndTriggers(jobsAndTriggers, false);

    assertTrue(jobStore.removeJob(job.getKey()));

    // ensure that the job and all of its triggers were removed
    assertThat(jobStore.retrieveJob(job.getKey()), nullValue());
    assertThat(jobStore.retrieveTrigger(trigger1.getKey()), nullValue());
    assertThat(jobStore.retrieveTrigger(trigger2.getKey()), nullValue());
    assertThat(jedis.get(schema.triggerHashKey(trigger1.getKey())), nullValue());
}
 
源代码15 项目: quartz-redis-jobstore   文件: StoreJobTest.java
@Test
public void pauseJob() throws Exception {
    // create and store a job with multiple triggers
    JobDetail job = getJobDetail("job1", "jobGroup1");
    CronTriggerImpl trigger1 = getCronTrigger("trigger1", "triggerGroup1", job.getKey());
    CronTriggerImpl trigger2 = getCronTrigger("trigger2", "triggerGroup1", job.getKey());
    Set<Trigger> triggersSet = new HashSet<>();
    triggersSet.add(trigger1);
    triggersSet.add(trigger2);
    Map<JobDetail, Set<? extends Trigger>> jobsAndTriggers = new HashMap<>();
    jobsAndTriggers.put(job, triggersSet);
    jobStore.storeJobsAndTriggers(jobsAndTriggers, false);

    // pause the job
    jobStore.pauseJob(job.getKey());

    // ensure that the job's triggers were paused
    assertEquals(Trigger.TriggerState.PAUSED, jobStore.getTriggerState(trigger1.getKey()));
    assertEquals(Trigger.TriggerState.PAUSED, jobStore.getTriggerState(trigger2.getKey()));
}
 
源代码16 项目: quartz-redis-jobstore   文件: StoreJobTest.java
@Test
public void pauseJobsStartsWith() throws Exception {
    JobDetail job1 = getJobDetail("job1", "jobGroup1");
    storeJobAndTriggers(job1, getCronTrigger("trigger1", "triggerGroup1", job1.getKey()), getCronTrigger("trigger2", "triggerGroup1", job1.getKey()));
    JobDetail job2 = getJobDetail("job2", "yobGroup1");
    CronTriggerImpl trigger3 = getCronTrigger("trigger3", "triggerGroup3", job2.getKey());
    CronTriggerImpl trigger4 = getCronTrigger("trigger4", "triggerGroup4", job2.getKey());
    storeJobAndTriggers(job2, trigger3, trigger4);

    // pause jobs with groups beginning with "yob"
    Collection<String> pausedJobs = jobStore.pauseJobs(GroupMatcher.jobGroupStartsWith("yob"));
    assertThat(pausedJobs, hasSize(1));
    assertThat(pausedJobs, containsInAnyOrder("yobGroup1"));

    // ensure that the job was added to the paused jobs set
    assertTrue(jedis.sismember(schema.pausedJobGroupsSet(), schema.jobGroupSetKey(job2.getKey())));

    // ensure that the job's triggers have been paused
    assertEquals(Trigger.TriggerState.PAUSED, jobStore.getTriggerState(trigger3.getKey()));
    assertEquals(Trigger.TriggerState.PAUSED, jobStore.getTriggerState(trigger4.getKey()));
}
 
源代码17 项目: quartz-redis-jobstore   文件: StoreJobTest.java
@Test
public void pauseJobsEndsWith() throws Exception {
    JobDetail job1 = getJobDetail("job1", "jobGroup1");
    CronTriggerImpl trigger1 = getCronTrigger("trigger1", "triggerGroup1", job1.getKey());
    CronTriggerImpl trigger2 = getCronTrigger("trigger2", "triggerGroup1", job1.getKey());
    storeJobAndTriggers(job1, trigger1, trigger2);
    JobDetail job2 = getJobDetail("job2", "yobGroup2");
    CronTriggerImpl trigger3 = getCronTrigger("trigger3", "triggerGroup3", job2.getKey());
    CronTriggerImpl trigger4 = getCronTrigger("trigger4", "triggerGroup4", job2.getKey());
    storeJobAndTriggers(job2, trigger3, trigger4);

    // pause job groups ending with "1"
    Collection<String> pausedJobs = jobStore.pauseJobs(GroupMatcher.jobGroupEndsWith("1"));
    assertThat(pausedJobs, hasSize(1));
    assertThat(pausedJobs, containsInAnyOrder("jobGroup1"));

    // ensure that the job was added to the paused jobs set
    assertTrue(jedis.sismember(schema.pausedJobGroupsSet(), schema.jobGroupSetKey(job1.getKey())));

    // ensure that the job's triggers have been paused
    assertEquals(Trigger.TriggerState.PAUSED, jobStore.getTriggerState(trigger1.getKey()));
    assertEquals(Trigger.TriggerState.PAUSED, jobStore.getTriggerState(trigger2.getKey()));
}
 
源代码18 项目: quartz-redis-jobstore   文件: StoreJobTest.java
@Test
public void resumeJob() throws Exception {
    // create and store a job with multiple triggers
    JobDetail job = getJobDetail("job1", "jobGroup1");
    CronTriggerImpl trigger1 = getCronTrigger("trigger1", "triggerGroup1", job.getKey());
    CronTriggerImpl trigger2 = getCronTrigger("trigger2", "triggerGroup1", job.getKey());
    storeJobAndTriggers(job, trigger1, trigger2);

    // pause the job
    jobStore.pauseJob(job.getKey());

    // ensure that the job's triggers have been paused
    assertEquals(Trigger.TriggerState.PAUSED, jobStore.getTriggerState(trigger1.getKey()));
    assertEquals(Trigger.TriggerState.PAUSED, jobStore.getTriggerState(trigger2.getKey()));

    // resume the job
    jobStore.resumeJob(job.getKey());

    // ensure that the triggers have been resumed
    assertEquals(Trigger.TriggerState.NORMAL, jobStore.getTriggerState(trigger1.getKey()));
    assertEquals(Trigger.TriggerState.NORMAL, jobStore.getTriggerState(trigger2.getKey()));
}
 
@Test
public void triggeredJobCompleteNonConcurrent() throws JobPersistenceException {
    JobDetail job = JobBuilder.newJob(TestJobNonConcurrent.class)
            .withIdentity("testJobNonConcurrent1", "jobGroupNonConcurrent1")
            .usingJobData("timeout", 42)
            .withDescription("I am describing a job!")
            .build();
    CronTriggerImpl trigger1 = getCronTrigger("triggerNonConcurrent1", "triggerNonConcurrentGroup1", job.getKey());
    CronTriggerImpl trigger2 = getCronTrigger("triggerNonConcurrent2", "triggerNonConcurrentGroup1", job.getKey());
    storeJobAndTriggers(job, trigger1, trigger2);

    jobStore.triggeredJobComplete(trigger1, job, Trigger.CompletedExecutionInstruction.SET_TRIGGER_COMPLETE);

    assertEquals(Trigger.TriggerState.COMPLETE, jobStore.getTriggerState(trigger1.getKey()));

    final String jobHashKey = schema.jobHashKey(job.getKey());
    assertFalse(jedis.sismember(schema.blockedJobsSet(), jobHashKey));
}
 
protected void afterChange(Form<?> form, AjaxRequestTarget target) {
	Settings settings = (Settings) form.getModelObject();
	if (!oldCronExpression.equals(settings.getCleanHistory().getCronExpression())) {
		// reschedule clean history
		StdScheduler scheduler = (StdScheduler) NextServerApplication.get().getSpringBean("scheduler");
		CronTriggerImpl cronTrigger = (CronTriggerImpl) NextServerApplication.get()
				.getSpringBean("cleanHistoryTrigger");
		try {
			cronTrigger.setCronExpression(settings.getCleanHistory().getCronExpression());
			scheduler.rescheduleJob(cronTrigger.getKey(), cronTrigger);
		} catch (Exception e) {
			e.printStackTrace();
			LOG.error(e.getMessage(), e);
		}
	}
}
 
源代码21 项目: light-task-scheduler   文件: QuartzLTSProxyAgent.java
private Job buildCronJob(QuartzJobContext quartzJobContext) {

        CronTriggerImpl cronTrigger = (CronTriggerImpl) quartzJobContext.getTrigger();
        String cronExpression = cronTrigger.getCronExpression();
        String description = cronTrigger.getDescription();
        int priority = cronTrigger.getPriority();
        String name = quartzJobContext.getName();

        Job job = new Job();
        job.setTaskId(name);
        job.setPriority(priority);
        job.setCronExpression(cronExpression);
        job.setSubmitNodeGroup(quartzLTSConfig.getJobClientProperties().getNodeGroup());
        job.setTaskTrackerNodeGroup(quartzLTSConfig.getTaskTrackerProperties().getNodeGroup());
        job.setParam("description", description);
        setJobProp(job);

        return job;
    }
 
@Override
@SuppressWarnings({"unchecked"})
public void setValue(Object value) {

    List<Object> nativeQuartzTriggers = new ArrayList<Object>();

    if (value != null && value instanceof Collection) {

        Collection<Trigger> triggers = (Collection<Trigger>) value;
        List<QuartzJobContext> quartzJobContexts = new ArrayList<QuartzJobContext>(triggers.size());
        for (Trigger trigger : triggers) {
            if (trigger instanceof CronTriggerImpl) {
                quartzJobContexts.add(buildQuartzCronJob((CronTriggerImpl) trigger));
            } else if (trigger instanceof SimpleTriggerImpl) {
                quartzJobContexts.add(buildQuartzSimpleJob((SimpleTriggerImpl) trigger));
            } else {
                LOGGER.warn("Can't Proxy " + trigger.getClass().getName() + " Then Use Quartz Scheduler");
                nativeQuartzTriggers.add(trigger);
            }
        }
        context.getAgent().startProxy(quartzJobContexts);
    }
    super.setValue(nativeQuartzTriggers);
}
 
源代码23 项目: sk-admin   文件: QuartzManage.java
public void addJob(QuartzJob quartzJob){
    try {
        // 构建job信息
        JobDetail jobDetail = JobBuilder.newJob(ExecutionJob.class).
                withIdentity(JOB_NAME + quartzJob.getId()).build();

        //通过触发器名和cron 表达式创建 Trigger
        Trigger cronTrigger = newTrigger()
                .withIdentity(JOB_NAME + quartzJob.getId())
                .startNow()
                .withSchedule(CronScheduleBuilder.cronSchedule(quartzJob.getCronExpression()))
                .build();

        cronTrigger.getJobDataMap().put(QuartzJob.JOB_KEY, quartzJob);

        //重置启动时间
        ((CronTriggerImpl)cronTrigger).setStartTime(new Date());

        //执行定时任务
        scheduler.scheduleJob(jobDetail,cronTrigger);

        // 暂停任务
        if (quartzJob.getIsPause()) {
            pauseJob(quartzJob);
        }
    } catch (Exception e){
        log.error("创建定时任务失败", e);
        throw new SkException("创建定时任务失败");
    }
}
 
源代码24 项目: sk-admin   文件: QuartzManage.java
/**
 * 更新job cron表达式
 * @param quartzJob /
 */
public void updateJobCron(QuartzJob quartzJob){
    try {
        TriggerKey triggerKey = TriggerKey.triggerKey(JOB_NAME + quartzJob.getId());
        CronTrigger trigger = (CronTrigger) scheduler.getTrigger(triggerKey);
        // 如果不存在则创建一个定时任务
        if(trigger == null){
            addJob(quartzJob);
            trigger = (CronTrigger) scheduler.getTrigger(triggerKey);
        }
        CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(quartzJob.getCronExpression());
        trigger = trigger.getTriggerBuilder().withIdentity(triggerKey).withSchedule(scheduleBuilder).build();
        //重置启动时间
        ((CronTriggerImpl)trigger).setStartTime(new Date());
        trigger.getJobDataMap().put(QuartzJob.JOB_KEY,quartzJob);

        scheduler.rescheduleJob(triggerKey, trigger);
        // 暂停任务
        if (quartzJob.getIsPause()) {
            pauseJob(quartzJob);
        }
    } catch (Exception e){
        log.error("更新定时任务失败", e);
        throw new SkException("更新定时任务失败");
    }

}
 
@Override
public void afterPropertiesSet() throws ParseException {
	Assert.notNull(this.cronExpression, "Property 'cronExpression' is required");

	if (this.name == null) {
		this.name = this.beanName;
	}
	if (this.group == null) {
		this.group = Scheduler.DEFAULT_GROUP;
	}
	if (this.jobDetail != null) {
		this.jobDataMap.put("jobDetail", this.jobDetail);
	}
	if (this.startDelay > 0 || this.startTime == null) {
		this.startTime = new Date(System.currentTimeMillis() + this.startDelay);
	}
	if (this.timeZone == null) {
		this.timeZone = TimeZone.getDefault();
	}

	CronTriggerImpl cti = new CronTriggerImpl();
	cti.setName(this.name != null ? this.name : toString());
	cti.setGroup(this.group);
	if (this.jobDetail != null) {
		cti.setJobKey(this.jobDetail.getKey());
	}
	cti.setJobDataMap(this.jobDataMap);
	cti.setStartTime(this.startTime);
	cti.setCronExpression(this.cronExpression);
	cti.setTimeZone(this.timeZone);
	cti.setCalendarName(this.calendarName);
	cti.setPriority(this.priority);
	cti.setMisfireInstruction(this.misfireInstruction);
	cti.setDescription(this.description);
	this.cronTrigger = cti;
}
 
/**
    * fill job info
    *
    * @param jobInfo
    */
public static void fillJobInfo(XxlJobInfo jobInfo) {
	// TriggerKey : name + group
       String group = String.valueOf(jobInfo.getJobGroup());
       String name = String.valueOf(jobInfo.getId());
       TriggerKey triggerKey = TriggerKey.triggerKey(name, group);

       try {
		Trigger trigger = scheduler.getTrigger(triggerKey);

		TriggerState triggerState = scheduler.getTriggerState(triggerKey);
		
		// parse params
		if (trigger!=null && trigger instanceof CronTriggerImpl) {
			String cronExpression = ((CronTriggerImpl) trigger).getCronExpression();
			jobInfo.setJobCron(cronExpression);
		}

		//JobKey jobKey = new JobKey(jobInfo.getJobName(), String.valueOf(jobInfo.getJobGroup()));
           //JobDetail jobDetail = scheduler.getJobDetail(jobKey);
           //String jobClass = jobDetail.getJobClass().getName();

		if (triggerState!=null) {
			jobInfo.setJobStatus(triggerState.name());
		}
		
	} catch (SchedulerException e) {
		logger.error(e.getMessage(), e);
	}
}
 
/**
    * fill job info
    *
    * @param jobInfo
    */
public static void fillJobInfo(XxlJobInfo jobInfo) {

       String group = String.valueOf(jobInfo.getJobGroup());
       String name = String.valueOf(jobInfo.getId());

       // trigger key
       TriggerKey triggerKey = TriggerKey.triggerKey(name, group);
       try {

           // trigger cron
		Trigger trigger = scheduler.getTrigger(triggerKey);
		if (trigger!=null && trigger instanceof CronTriggerImpl) {
			String cronExpression = ((CronTriggerImpl) trigger).getCronExpression();
			jobInfo.setJobCron(cronExpression);
		}

           // trigger state
           TriggerState triggerState = scheduler.getTriggerState(triggerKey);
		if (triggerState!=null) {
			jobInfo.setJobStatus(triggerState.name());
		}

           //JobKey jobKey = new JobKey(jobInfo.getJobName(), String.valueOf(jobInfo.getJobGroup()));
           //JobDetail jobDetail = scheduler.getJobDetail(jobKey);
           //String jobClass = jobDetail.getJobClass().getName();
		
	} catch (SchedulerException e) {
		logger.error(e.getMessage(), e);
	}
}
 
源代码28 项目: web-flash   文件: TaskUtils.java
/**
 * 判断cron时间表达式正确性
 *
 * @param cronExpression
 * @return
 */
public static boolean isValidExpression(final String cronExpression) {
	CronTriggerImpl trigger = new CronTriggerImpl();
	try {
		trigger.setCronExpression(cronExpression);
		Date date = trigger.computeFirstFireTime(null);
		return date != null && date.after(new Date());
	} catch (ParseException e) {
		logger.error(e.getMessage(), e);
	}
	return false;
}
 
源代码29 项目: java-master   文件: CronUtils.java
public static boolean isValidExpression(final String cronExpression) {
    CronTriggerImpl trigger = new CronTriggerImpl();
    try {
        trigger.setCronExpression(cronExpression);
        Date date = trigger.computeFirstFireTime(null);
        return date != null && date.after(new Date());
    } catch (Exception e) {
        logger.error("invalid expression:{},error msg:{}", cronExpression, e.getMessage());
    }
    return false;
}
 
源代码30 项目: zuihou-admin-boot   文件: XxlJobDynamicScheduler.java
/**
 * fill job info
 *
 * @param jobInfo
 */
public static void fillJobInfo(XxlJobInfo jobInfo) {

    String group = String.valueOf(jobInfo.getJobGroup());
    String name = String.valueOf(jobInfo.getId());

    // trigger key
    TriggerKey triggerKey = TriggerKey.triggerKey(name, group);
    try {

        // trigger cron
        Trigger trigger = scheduler.getTrigger(triggerKey);
        if (trigger != null && trigger instanceof CronTriggerImpl) {
            String cronExpression = ((CronTriggerImpl) trigger).getCronExpression();
            jobInfo.setJobCron(cronExpression);
        }

        // trigger state
        TriggerState triggerState = scheduler.getTriggerState(triggerKey);
        if (triggerState != null) {
            jobInfo.setJobStatus(triggerState.name());
        }

    } catch (SchedulerException e) {
        logger.error(e.getMessage(), e);
    }
}
 
 类所在包
 同包方法