Java Code Examples for org.quartz.impl.triggers.CronTriggerImpl#setCronExpression()

The following examples show how to use org.quartz.impl.triggers.CronTriggerImpl#setCronExpression() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ScheduledInfo.java    From GOAi with GNU Affero General Public License v3.0 7 votes vote down vote up
/**
 * 设置触发器
 */
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);
    }
}
 
Example 2
Source File: SchedulerServiceImpl.java    From uflo with Apache License 2.0 6 votes vote down vote up
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);
	}
}
 
Example 3
Source File: CronTriggerSupport.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public static OperableTrigger newTrigger(CompositeData cData) throws ParseException {
    CronTriggerImpl result = new CronTriggerImpl();
    result.setCronExpression((String) cData.get("cronExpression"));
    if(cData.containsKey("timeZone")) {
        result.setTimeZone(TimeZone.getTimeZone((String)cData.get("timeZone")));
    }
    TriggerSupport.initializeTrigger(result, cData);
    return result;
}
 
Example 4
Source File: InstanceDetection.java    From uflo with Apache License 2.0 5 votes vote down vote up
private Trigger initTrigger(){
	CronTriggerImpl trigger=new CronTriggerImpl();
	trigger.setName("UfloHeartbeatTrigger");
	trigger.setKey(new TriggerKey("UfloHeartbeatTrigger"));
	try {
		trigger.setCronExpression(detectionCron);
		return trigger;
	} catch (ParseException e1) {
		throw new RuntimeException(e1);
	}
}
 
Example 5
Source File: HeartbeatDetectionJob.java    From uflo with Apache License 2.0 5 votes vote down vote up
private Trigger buildHeartJobTrigger() {
	CronTriggerImpl trigger=new CronTriggerImpl();
	trigger.setName("UfloHeartJobTrigger");
	try {
		trigger.setCronExpression(heartJobCronExpression);
		return trigger;
	} catch (ParseException e) {
		throw new RuntimeException(e);
	}
}
 
Example 6
Source File: CBCronTriggerRunner.java    From NewsRecommendSystem with MIT License 5 votes vote down vote up
public void task(List<Long> users,String cronExpression) throws SchedulerException
{
    // Initiate a Schedule Factory
    SchedulerFactory schedulerFactory = new StdSchedulerFactory();
    // Retrieve a scheduler from schedule factory
    Scheduler scheduler = schedulerFactory.getScheduler();
    
    // Initiate JobDetail with job name, job group, and executable job class
    JobDetailImpl jobDetailImpl = 
    	new JobDetailImpl();
    jobDetailImpl.setJobClass(CBJob.class);
    jobDetailImpl.setKey(new JobKey("CBJob1"));
    jobDetailImpl.getJobDataMap().put("users", users);
    // Initiate CronTrigger with its name and group name
    CronTriggerImpl cronTriggerImpl = new CronTriggerImpl();
    cronTriggerImpl.setName("CBCronTrigger1");
    
    try {
        // setup CronExpression
        CronExpression cexp = new CronExpression(cronExpression);
        // Assign the CronExpression to CronTrigger
        cronTriggerImpl.setCronExpression(cexp);
    } catch (Exception e) {
        e.printStackTrace();
    }
    // schedule a job with JobDetail and Trigger
    scheduler.scheduleJob(jobDetailImpl, cronTriggerImpl);
    
    // start the scheduler
    scheduler.start();
}
 
Example 7
Source File: HRCronTriggerRunner.java    From NewsRecommendSystem with MIT License 5 votes vote down vote up
public void task(List<Long> users,String cronExpression) throws SchedulerException
{
    // Initiate a Schedule Factory
    SchedulerFactory schedulerFactory = new StdSchedulerFactory();
    // Retrieve a scheduler from schedule factory
    Scheduler scheduler = schedulerFactory.getScheduler();
    
    // Initiate JobDetail with job name, job group, and executable job class
    JobDetailImpl jobDetailImpl = 
    	new JobDetailImpl();
    jobDetailImpl.setJobClass(HRJob.class);
    jobDetailImpl.setKey(new JobKey("HRJob1"));
    jobDetailImpl.getJobDataMap().put("users",users);
    // Initiate CronTrigger with its name and group name
    CronTriggerImpl cronTriggerImpl = new CronTriggerImpl();
    cronTriggerImpl.setName("HRCronTrigger1");
    
    try {
        // setup CronExpression
        CronExpression cexp = new CronExpression(cronExpression);
        // Assign the CronExpression to CronTrigger
        cronTriggerImpl.setCronExpression(cexp);
    } catch (Exception e) {
        e.printStackTrace();
    }
    // schedule a job with JobDetail and Trigger
    scheduler.scheduleJob(jobDetailImpl, cronTriggerImpl);
    
    // start the scheduler
    scheduler.start();
}
 
Example 8
Source File: CFCronTriggerRunner.java    From NewsRecommendSystem with MIT License 5 votes vote down vote up
public void task(List<Long> users,String cronExpression) throws SchedulerException
{
    // Initiate a Schedule Factory
    SchedulerFactory schedulerFactory = new StdSchedulerFactory();
    // Retrieve a scheduler from schedule factory
    Scheduler scheduler = schedulerFactory.getScheduler();
    
    // Initiate JobDetail with job name, job group, and executable job class
    JobDetailImpl jobDetailImpl = 
    	new JobDetailImpl();
    jobDetailImpl.setJobClass(CFJob.class);
    jobDetailImpl.setKey(new JobKey("CFJob1"));
    jobDetailImpl.getJobDataMap().put("users", users);
    // Initiate CronTrigger with its name and group name
    CronTriggerImpl cronTriggerImpl = new CronTriggerImpl();
    cronTriggerImpl.setName("CFCronTrigger1");
    try {
        // setup CronExpression
        CronExpression cexp = new CronExpression(cronExpression);
        // Assign the CronExpression to CronTrigger
        cronTriggerImpl.setCronExpression(cexp);
    } catch (Exception e) {
        e.printStackTrace();
    }
    // schedule a job with JobDetail and Trigger
    scheduler.scheduleJob(jobDetailImpl, cronTriggerImpl);
    
    // start the scheduler
    scheduler.start();
}
 
Example 9
Source File: PageUtils.java    From JobX with Apache License 2.0 5 votes vote down vote up
public static List<String> getRecentTriggerTime(String cron) {
    List<String> list = new ArrayList<String>();
    try {
        CronTriggerImpl cronTriggerImpl = new CronTriggerImpl();
        cronTriggerImpl.setCronExpression(cron);
        List<Date> dates = TriggerUtils.computeFireTimes(cronTriggerImpl, null, 5);
        for (Date date : dates) {
            list.add(DateUtils.parseStringFromDate(date,DateUtils.format));
        }
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return list;
}
 
Example 10
Source File: CronTriggerSupport.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public static OperableTrigger newTrigger(Map<String, Object> attrMap) throws ParseException {
    CronTriggerImpl result = new CronTriggerImpl();
    result.setCronExpression((String) attrMap.get("cronExpression"));
    if(attrMap.containsKey("timeZone")) {
        result.setTimeZone(TimeZone.getTimeZone((String)attrMap.get("timeZone")));
    }
    TriggerSupport.initializeTrigger(result, attrMap);
    return result;
}
 
Example 11
Source File: CronScheduleBuilder.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Build the actual Trigger -- NOT intended to be invoked by end users, but
 * will rather be invoked by a TriggerBuilder which this ScheduleBuilder is
 * given to.
 * 
 * @see TriggerBuilder#withSchedule(ScheduleBuilder)
 */
@Override
public MutableTrigger build() {

    CronTriggerImpl ct = new CronTriggerImpl();

    ct.setCronExpression(cronExpression);
    ct.setTimeZone(cronExpression.getTimeZone());
    ct.setMisfireInstruction(misfireInstruction);

    return ct;
}
 
Example 12
Source File: RedisJobStore.java    From redis-quartz with MIT License 5 votes vote down vote up
private OperableTrigger toOperableTrigger(TriggerKey triggerKey, Map<String, String> trigger) {
	if (TRIGGER_TYPE_SIMPLE.equals(trigger.get(TRIGGER_TYPE))) {
		SimpleTriggerImpl simpleTrigger = new SimpleTriggerImpl();
		setOperableTriggerFields(triggerKey, trigger, simpleTrigger);
		if (trigger.get(REPEAT_COUNT) != null && !trigger.get(REPEAT_COUNT).isEmpty())
			simpleTrigger.setRepeatCount(Integer.parseInt(trigger.get(REPEAT_COUNT)));
		if (trigger.get(REPEAT_INTERVAL) != null && !trigger.get(REPEAT_INTERVAL).isEmpty())
			simpleTrigger.setRepeatInterval(Long.parseLong(trigger.get(REPEAT_INTERVAL)));
		if (trigger.get(TIMES_TRIGGERED) != null && !trigger.get(TIMES_TRIGGERED).isEmpty())
			simpleTrigger.setTimesTriggered(Integer.parseInt(trigger.get(TIMES_TRIGGERED)));
		
		return simpleTrigger;
	} else if (TRIGGER_TYPE_CRON.equals(trigger.get(TRIGGER_TYPE))) {
		CronTriggerImpl cronTrigger = new CronTriggerImpl();
		setOperableTriggerFields(triggerKey, trigger, cronTrigger);
		if (trigger.get(TIME_ZONE_ID) != null && !trigger.get(TIME_ZONE_ID).isEmpty())
			cronTrigger.getTimeZone().setID(trigger.get(TIME_ZONE_ID).isEmpty() ? null : trigger.get(TIME_ZONE_ID));
		try {
			if (trigger.get(CRON_EXPRESSION) != null && !trigger.get(CRON_EXPRESSION).isEmpty())
				cronTrigger.setCronExpression(trigger.get(CRON_EXPRESSION).isEmpty() ? null : trigger.get(CRON_EXPRESSION));
		} catch (ParseException ex) {
			log.warn("could not parse cron_expression: " + trigger.get(CRON_EXPRESSION) + " for trigger: " + createTriggerHashKey(triggerKey.getGroup(), triggerKey.getName()));
		}
		
		return cronTrigger;					
	} else { // other trigger types are not supported
		 throw new UnsupportedOperationException();
	}
}
 
Example 13
Source File: SynchronizerSettingsPanel.java    From nextreports-server with Apache License 2.0 5 votes vote down vote up
protected void afterChange(Form<?> form, AjaxRequestTarget target) {	
    	Settings settings = (Settings)form.getModelObject();	    	    
    	if (!oldCronExpression.equals(settings.getSynchronizer().getCronExpression())) {	    		
    		// reschedule user synchronizer
    		StdScheduler scheduler = (StdScheduler) NextServerApplication.get().getSpringBean("scheduler");
    		CronTriggerImpl cronTrigger = (CronTriggerImpl) NextServerApplication.get().getSpringBean("userSynchronizerTrigger");
    		try {
				cronTrigger.setCronExpression(settings.getSynchronizer().getCronExpression());										
				scheduler.rescheduleJob(cronTrigger.getKey(), cronTrigger);					
			} catch (Exception e) {					
				e.printStackTrace();
				LOG.error(e.getMessage(), e);
			}	    		
    	}
}
 
Example 14
Source File: QuartzCronUtils.java    From super-cloudops with Apache License 2.0 5 votes vote down vote up
/**
 * Get the expression next numTimes -- run time
 */
public static List<String> getNextExecTime(String expression, Integer numTimes) {
	CronTriggerImpl cronTriggerImpl = new CronTriggerImpl();
	try {
		cronTriggerImpl.setCronExpression(expression);
	} catch (ParseException e) {
		throw new IllegalArgumentException(e);
	}
	return safeList(computeFireTimes(cronTriggerImpl, null, numTimes)).stream().map(d -> formatDate(d, "yyyy-MM-dd HH:mm:ss"))
			.collect(toList());
}
 
Example 15
Source File: CronTriggerFactoryBean.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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;
}
 
Example 16
Source File: TaskUtils.java    From flash-waimai with MIT License 5 votes vote down vote up
/**
 * 判断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;
}
 
Example 17
Source File: CronUtils.java    From java-master with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 18
Source File: TaskUtils.java    From web-flash with MIT License 5 votes vote down vote up
/**
 * 判断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;
}
 
Example 19
Source File: CronTriggerFactoryBean.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@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;
}
 
Example 20
Source File: SchedulerServiceImpl.java    From uflo with Apache License 2.0 4 votes vote down vote up
public void addReminderJob(TaskReminder reminder,ProcessInstance processInstance,Task task) {
	JobKey jobKey=new JobKey(JOB_NAME_PREFIX+reminder.getId(),JOB_GROUP_PREFIX);
	try {
		if(scheduler.checkExists(jobKey)){
			return;
		}
		AbstractTrigger<? extends Trigger> trigger=null;
		if(reminder.getType().equals(ReminderType.Once)){
			SimpleTriggerImpl simpleTrigger=new SimpleTriggerImpl();
			simpleTrigger.setRepeatCount(0);
			trigger=simpleTrigger;
			long executeTime=reminder.getStartDate().getTime()+10000;
			long now=(new Date()).getTime();
			if(executeTime<=now){
				return;
			}
		}else{
			CronTriggerImpl cronTrigger=new CronTriggerImpl();
			cronTrigger.setCronExpression(reminder.getCron());
			trigger=cronTrigger;
		}
		trigger.setName("trigger_"+reminder.getId());
		trigger.setStartTime(reminder.getStartDate());
		ReminderJobDetail jobDetail=new ReminderJobDetail();
		jobDetail.setJobClass(ReminderJob.class);
		ReminderHandler handler=(ReminderHandler)applicationContext.getBean(reminder.getReminderHandlerBean());
		jobDetail.setReminderHandlerBean(handler);
		if(task==null){
			task=taskService.getTask(reminder.getTaskId());				
		}
		jobDetail.setTask(task);
		jobDetail.setProcessInstance(processService.getProcessInstanceById(task.getProcessInstanceId()));
		jobDetail.setKey(jobKey);
		Calendar calendar=getCalendar(reminder,processInstance,task);
		if(calendar!=null){
			String calendarName=REMINDER_CALENDAR_PREFIX+reminder.getId();
			scheduler.addCalendar(calendarName, calendar,false, false);
			trigger.setCalendarName(calendarName);
		}
		scheduler.scheduleJob(jobDetail, trigger);
	} catch (Exception e) {
		throw new RuntimeException(e);
	}	
}