Java Code Examples for org.quartz.TriggerBuilder#endAt()

The following examples show how to use org.quartz.TriggerBuilder#endAt() . 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: AbstractQuartzTaskManager.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
private Trigger getTriggerFromInfo(String taskName, String taskGroup, TaskInfo.TriggerInfo triggerInfo)
        throws TaskException {
    TriggerBuilder<Trigger> triggerBuilder = TriggerBuilder.newTrigger().withIdentity(taskName, taskGroup);
    if (triggerInfo.getStartTime() == null) {
        triggerBuilder = triggerBuilder.startNow();
    } else {
        triggerBuilder = triggerBuilder.startAt(triggerInfo.getStartTime());
    }
    if (triggerInfo.getEndTime() != null) {
        triggerBuilder.endAt(triggerInfo.getEndTime());
    }
    Trigger trigger;
    if (triggerInfo.getCronExpression() != null) {
        trigger = triggerBuilder.withSchedule(this.getCronScheduleBuilder(triggerInfo)).build();
    } else {
        if (triggerInfo.getRepeatCount() == 0) {
            /* only once executed */
            trigger = triggerBuilder.build();
        } else {
            trigger = triggerBuilder.withSchedule(this.getSimpleScheduleBuilder(triggerInfo)).build();
        }
    }
    return trigger;
}
 
Example 2
Source File: QuartzUtil.java    From FoxBPM with Apache License 2.0 6 votes vote down vote up
/**
 * 创建复杂触发器
 * 
 * @param jobName
 *            作业名
 * @param groupName
 *            组名
 * @param cronExpression
 *            cron表达式
 * @param startTime
 *            开始时间
 * @param endTime
 *            结束时间
 * @return
 */
public final static Trigger createCronTrigger(ListenerExecutionContext executionContext,
    String cronExpression, Date startTime, Date endTime) {
	
	TriggerBuilder<CronTrigger> triggerBuilder = newTrigger().withIdentity(GuidUtil.CreateGuid(), executionContext.getProcessInstanceId()).withSchedule(cronSchedule(cronExpression));
	
	if (startTime != null) {
		triggerBuilder.startAt(startTime);
	}
	if (endTime != null) {
		triggerBuilder.endAt(endTime);
	}
	
	CronTrigger trigger = triggerBuilder.build();
	return trigger;
}
 
Example 3
Source File: QuartzUtil.java    From fixflow with Apache License 2.0 6 votes vote down vote up
/**
 * 创建复杂触发器
 * @param jobName 作业名
 * @param groupName 组名
 * @param cronExpression cron表达式
 * @param startTime 开始时间
 * @param endTime 结束时间
 * @return
 */
public static Trigger createCronTrigger(ExecutionContext executionContext, String cronExpression,Date startTime,Date endTime) {
	
	TriggerBuilder<CronTrigger> triggerBuilder=newTrigger()
	         .withIdentity(GuidUtil.CreateGuid(), executionContext.getProcessDefinition().getId())
	         .withSchedule(cronSchedule(cronExpression));
	
	if(startTime!=null){
		triggerBuilder.startAt(startTime);
	}
	if(endTime!=null){
		triggerBuilder.endAt(endTime);
	}
	
	 CronTrigger trigger = triggerBuilder
        .build();
	return trigger;
}
 
Example 4
Source File: TriggerServiceStrategy.java    From quartz-web with Apache License 2.0 4 votes vote down vote up
public JSONResult addTrigger(String schedulerName, String jobName, String jobGroup,
                             String triggerName, String triggerGroup, String cronExpression, String description,
                             String priority, Date startDate, Date endDate, Map<String, Object> dataMap) {

    try {
        Assert.notEmpty(schedulerName, "schedulerName can not be empty");
        Assert.notEmpty(jobName, "jobName can not be empty");
        Assert.notEmpty(jobGroup, "jobGroup can not be empty");
        Assert.notEmpty(triggerName, "triggerName can not be empty");
        Assert.notEmpty(triggerGroup, "triggerGroup can not be empty");
        Assert.isCronExpression(cronExpression, "cronExpression is error");
        TriggerBuilder<Trigger> triggerTriggerBuilder = TriggerBuilder.newTrigger();
        triggerTriggerBuilder = triggerTriggerBuilder.withIdentity(triggerName, triggerGroup);
        if (!StringUtils.isEmpty(description)) {
            triggerTriggerBuilder = triggerTriggerBuilder.withDescription(description);
        }
        if (!StringUtils.isEmpty(priority) && StringUtils.isInteger(priority)) {
            Assert.isInteger(priority, "priority must be int");
            triggerTriggerBuilder.withPriority(Integer.parseInt(priority));
        }
        if (startDate != null) {
            triggerTriggerBuilder.startAt(startDate);
        }
        if (endDate != null) {
            triggerTriggerBuilder.endAt(endDate);
        }
        //jobDataMap
        if (dataMap != null && dataMap.size() > 0) {
            JobDataMap jobDataMap = new JobDataMap();
            for (Map.Entry<String, Object> dataKey : dataMap.entrySet()) {
                if (!StringUtils.isEmpty(dataKey.getKey())) {
                    jobDataMap.put(dataKey.getKey(), dataKey.getValue());
                }
            }
            triggerTriggerBuilder.usingJobData(jobDataMap);
        }
        triggerTriggerBuilder.forJob(jobName, jobGroup);
        CronTrigger trigger = triggerTriggerBuilder.withSchedule(CronScheduleBuilder.cronSchedule(cronExpression))
                .build();
        //JobDetail jobDetail = QuartzWebManager.getJob(schedulerName, jobName, jobGroup);
        // 存在更新不存在,添加
        if (!QuartzWebManager.checkTriggerExists(schedulerName, triggerName, triggerGroup)) {
            QuartzWebManager.addTriggerForJob(schedulerName, trigger);
        } else {
            QuartzWebManager.updateTriggerForJob(schedulerName, trigger);
        }

        return JSONResult.build(JSONResult.RESULT_CODE_SUCCESS, "ok");
    } catch (Exception e) {
        e.printStackTrace();
        return JSONResult.build(JSONResult.RESULT_CODE_ERROR, e.getMessage());
    }
}