本文整理汇总了Java中org.quartz.TriggerBuilder.withSchedule方法的典型用法代码示例。如果您正苦于以下问题:Java TriggerBuilder.withSchedule方法的具体用法?Java TriggerBuilder.withSchedule怎么用?Java TriggerBuilder.withSchedule使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.quartz.TriggerBuilder
的用法示例。
在下文中一共展示了TriggerBuilder.withSchedule方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildTrigger
import org.quartz.TriggerBuilder; //导入方法依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
private Trigger buildTrigger(String confId, JobScheduling conf, JobKey job) {
TriggerKey key = this.buildTiggerKey(confId);
TriggerBuilder trigger = TriggerBuilder.newTrigger().withIdentity(key);
// Set CRON value
if (StringUtils.isNotEmpty(conf.getValue())) {
trigger.withSchedule(CronScheduleBuilder.cronSchedule(conf.getValue()));
}
// Set DATE value
if (conf.getStartAt() > 0) {
trigger.startAt(new Date(conf.getStartAt()));
}
if (job != null) {
trigger.forJob(job);
}
return trigger.build();
}
示例2: getTrigger
import org.quartz.TriggerBuilder; //导入方法依赖的package包/类
@Override
public Trigger getTrigger() {
Checker.require(triggerKey).notNull();
TriggerBuilder<Trigger> triggerBuilder = newTrigger().withIdentity(triggerKey);
if (getStartTime() == null) {
triggerBuilder.startNow();
} else {
triggerBuilder.startAt(getStartTime());
}
if (getEndTime() != null) {
triggerBuilder.endAt(getEndTime());
}
if (isRepeatable()) {
SimpleScheduleBuilder scheduleBuilder = simpleSchedule();
scheduleBuilder.withIntervalInSeconds(getIntervalInSeconds());
if (isRepeatForever()) {
scheduleBuilder.repeatForever();
} else {
scheduleBuilder.withRepeatCount(getRepeatCount());
}
triggerBuilder.withSchedule(scheduleBuilder);
}
return triggerBuilder.build();
}
示例3: createMember
import org.quartz.TriggerBuilder; //导入方法依赖的package包/类
@Override
public void createMember(RequestContext ctx, ResourceState state, Responder responder) throws Exception {
String id = UUID.randomUUID().toString();
TriggerBuilder triggerBuilder = TriggerBuilder.newTrigger();
triggerBuilder.withSchedule(CronScheduleBuilder.cronSchedule((String) state.getProperty("cron")));
triggerBuilder.withIdentity(id);
Trigger trigger = triggerBuilder.build();
TriggerResource resource = new TriggerResource(this, trigger);
JobDataMap dataMap = new JobDataMap();
dataMap.put("resource", resource);
JobBuilder jobBuilder = JobBuilder.newJob();
jobBuilder.withIdentity(id);
jobBuilder.ofType(LiveOakJob.class);
jobBuilder.setJobData(dataMap);
JobDetail jobDetail = jobBuilder.build();
this.scheduler.scheduleJob(jobDetail, trigger);
this.children.put(id, resource);
responder.resourceCreated(resource);
}
示例4: getTrigger
import org.quartz.TriggerBuilder; //导入方法依赖的package包/类
public Trigger getTrigger(Trigger trigger) throws ParseException {
fixParameters();
TriggerBuilder<Trigger> builder = TriggerBuilder.newTrigger().forJob(trigger.getJobKey().getName(), trigger.getJobKey().getGroup())
.withIdentity(trigger.getKey().getName(), trigger.getKey().getGroup())
.startAt(startTime).endAt(endTime)
.usingJobData(JobDataMapUtils.fromDataMapStr(dataMap));
if (repeatCount == -1) {
builder.withSchedule(SimpleScheduleBuilder.simpleSchedule().repeatForever()
.withIntervalInMilliseconds(intervalInMilliseconds));
} else {
builder.withSchedule(SimpleScheduleBuilder.simpleSchedule().withRepeatCount(repeatCount)
.withIntervalInMilliseconds(intervalInMilliseconds));
}
return builder.build();
}
示例5: getTrigger
import org.quartz.TriggerBuilder; //导入方法依赖的package包/类
public Trigger getTrigger() throws ParseException {
fixParameters();
TriggerBuilder<Trigger> builder = TriggerBuilder.newTrigger().forJob(name.trim(), group.trim()).withIdentity(triggerName.trim(), triggerGroup.trim())
.startAt(startTime).endAt(endTime)
.usingJobData(JobDataMapUtils.fromDataMapStr(dataMap));
if (repeatCount == -1) {
builder.withSchedule(SimpleScheduleBuilder.simpleSchedule().repeatForever()
.withIntervalInMilliseconds(intervalInMilliseconds));
} else {
builder.withSchedule(SimpleScheduleBuilder.simpleSchedule().withRepeatCount(repeatCount)
.withIntervalInMilliseconds(intervalInMilliseconds));
}
return builder.build();
}
示例6: configureTriggerJob
import org.quartz.TriggerBuilder; //导入方法依赖的package包/类
private Trigger configureTriggerJob(String jobName, String jobGroup, Job job) {
TriggerBuilder<Trigger> triggerBuilder = TriggerBuilder.newTrigger();
// base trigger configuration
triggerBuilder.withIdentity(jobName, jobGroup);
if (job.getStartTime() != null)
triggerBuilder.startAt(job.getStartTime());
else {
if (job.getActive())
triggerBuilder.startNow();
}
if (job.getEndTime() != null)
triggerBuilder.endAt(job.getEndTime());
triggerBuilder.withPriority(job.getJobTriggerPriority());
// propietary trigger configuration
if (job.getJobTriggerType().getCode().equals(Job.JOB_TRIGGER_TYPE.SIMPLE.name())) {
SimpleScheduleBuilder simpleScheduleBuilder = SimpleScheduleBuilder.simpleSchedule();
if (job.getJobInterval() != null) {
if (job.getJobIntervalType().getCode().equals(Job.JOB_INTERVAL_TYPE.SECOND.name()))
simpleScheduleBuilder.withIntervalInSeconds(job.getJobInterval());
else if (job.getJobIntervalType().getCode().equals(Job.JOB_INTERVAL_TYPE.MINUTE.name()))
simpleScheduleBuilder.withIntervalInMinutes(job.getJobInterval());
else if (job.getJobIntervalType().getCode().equals(Job.JOB_INTERVAL_TYPE.HOUR.name()))
simpleScheduleBuilder.withIntervalInHours(job.getJobInterval());
else if (job.getJobIntervalType().getCode().equals(Job.JOB_INTERVAL_TYPE.DAY.name()))
simpleScheduleBuilder.withIntervalInHours(job.getJobInterval() * 24);
else if (job.getJobIntervalType().getCode().equals(Job.JOB_INTERVAL_TYPE.WEEK.name()))
simpleScheduleBuilder.withIntervalInHours(job.getJobInterval() * 24 * 7);
}
if (job.getRepeatCount() != null)
simpleScheduleBuilder.withRepeatCount(job.getRepeatCount());
else
simpleScheduleBuilder.repeatForever();
triggerBuilder.withSchedule(simpleScheduleBuilder);
}
else if (job.getJobTriggerType().getCode().equals(Job.JOB_TRIGGER_TYPE.CRON.name())) {
CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule(job.getCronExpression());
triggerBuilder.withSchedule(cronScheduleBuilder);
}
return triggerBuilder.build();
}
示例7: scheduleAfter
import org.quartz.TriggerBuilder; //导入方法依赖的package包/类
/**
* Schedules an event after a specified time with the specified interval.
*
* @param event event.
* @param delay delay in milliseconds.
* @param interval interval in milliseconds.
* @return scheduled event entry.
*/
@Override
public EventSchedulerEntry scheduleAfter(Event event, long delay, long interval) {
TriggerBuilder<Trigger> builder = newTrigger();
if (delay > 0) {
builder.startAt(Date.from(Instant.now().plusMillis(delay)));
}
if (interval > 0) {
builder.withSchedule(
simpleSchedule().withIntervalInMilliseconds(interval).repeatForever().withMisfireHandlingInstructionFireNow());
}
return doSchedule(event, builder.build(), interval == 0);
}
示例8: scheduleAt
import org.quartz.TriggerBuilder; //导入方法依赖的package包/类
/**
* Schedules an event at a specified time with the specified interval.
*
* @param event event.
* @param at time in milliseconds.
* @param interval interval in milliseconds.
* @return scheduled event entry.
*/
@Override
public EventSchedulerEntry scheduleAt(Event event, long at, long interval) {
TriggerBuilder<Trigger> builder = newTrigger();
if (at >= 0) {
builder.startAt(new Date(at));
}
if (interval > 0) {
builder.withSchedule(simpleSchedule().withIntervalInMilliseconds(interval).repeatForever());
}
return doSchedule(event, builder.build(), interval == 0);
}
示例9: newJob
import org.quartz.TriggerBuilder; //导入方法依赖的package包/类
@RequestMapping(method = RequestMethod.PUT)
public ResultVO newJob(@Valid JobVO jobVO, BindingResult bResult) throws SchedulerException {
ResultVO result = new ResultVO();
if (bResult.hasErrors()) {
for (FieldError fieldError : bResult.getFieldErrors()) {
result.addError(fieldError);
}
return result;
} else if (scheduler.getJobDetail(new JobKey(jobVO.getDataSetId(), CsvJob.GROUP)) != null) {
result.addError("job 已存在");
return result;
} else if (!validateSQL(jobVO)) {
result.addError("無法執行 sql");
return result;
}
JobDataMap map = new JobDataMap();
map.put(JobConstant.DATABASE_DRIVER_CLASS_NAME, jobVO.getDriverClassName());
map.put(JobConstant.DATABASE_URL, jobVO.getUrl());
map.put(JobConstant.DATABASE_USERNAME, jobVO.getUsername());
map.put(JobConstant.DATABASE_PASSWORD, jobVO.getPassword());
map.put(JobConstant.SQL, jobVO.getSql());
JobDetail job = JobBuilder.newJob(CsvJob.class).withIdentity(jobVO.getDataSetId(), CsvJob.GROUP)
.withDescription(jobVO.getDescription()).setJobData(map).build();
TriggerBuilder<Trigger> triggerBuilder = TriggerBuilder.newTrigger().forJob(job);
if (jobVO.getIntervalDay() != null) {
triggerBuilder.withSchedule(SimpleScheduleBuilder.repeatHourlyForever(jobVO.getIntervalDay() * 24));
}
if (jobVO.getStartTime() != null) {
triggerBuilder.startAt(jobVO.getStartTime());
} else {
triggerBuilder.startNow();
}
scheduler.scheduleJob(job, triggerBuilder.build());
return result;
}
示例10: createTrigger
import org.quartz.TriggerBuilder; //导入方法依赖的package包/类
private Trigger createTrigger(final AnnotatedQuartzJob annotatedJob,
final JobDetail jobDetail) {
final QuartzScheduledJob annotation = annotatedJob.getAnnotation();
final Class<? extends Job> jobClass = annotatedJob.getJobClass();
final TriggerBuilder<Trigger> triggerBuilder = TriggerBuilder.newTrigger();
final String cronExpression = resolveCronExpression(annotation);
final boolean cronEnabled = cronExpression != null;
final boolean fixedRateEnabled = annotation.fixedRate() > 0;
if (cronEnabled == fixedRateEnabled) {
throw new IllegalStateException("Exactly one of 'cronExpression', 'fixedRate' is required. Offending class "
+ jobClass.getName());
}
if (cronEnabled) {
triggerBuilder.withSchedule(CronScheduleBuilder.cronSchedule(cronExpression)
.inTimeZone(Constants.DEFAULT_TIMEZONE.toTimeZone()));
} else {
triggerBuilder.withSchedule(SimpleScheduleBuilder.simpleSchedule()
.withIntervalInMilliseconds(annotation.fixedRate())
.repeatForever());
}
return triggerBuilder.forJob(jobDetail)
.startNow()
.withIdentity(jobDetail.getKey().getName() + "_trigger", jobDetail.getKey().getGroup() + "_triggers")
.build();
}
示例11: createTrigger
import org.quartz.TriggerBuilder; //导入方法依赖的package包/类
protected Trigger createTrigger(JobDataMap data, Date start, int interval,
int repeat, Date end) {
TriggerBuilder<Trigger> triggerBuilder = TriggerBuilder.newTrigger();
if (data != null) {
triggerBuilder.usingJobData(data);
}
if (interval > 0) {
SimpleScheduleBuilder schedule = SimpleScheduleBuilder
.simpleSchedule();
schedule.withIntervalInMilliseconds(interval).withRepeatCount(
repeat);
triggerBuilder.withSchedule(schedule);
}
if (start != null) {
triggerBuilder.startAt(start);
} else {
triggerBuilder.startNow();
}
if (end != null) {
triggerBuilder.endAt(end);
}
return triggerBuilder.build();
}
示例12: initTrigger
import org.quartz.TriggerBuilder; //导入方法依赖的package包/类
protected Trigger initTrigger(String name, Options<ScheduleOption> opts) {
TriggerBuilder<Trigger> builder = TriggerBuilder.newTrigger()
.withIdentity(name, name());
if (opts.has(AT)) {
builder.startAt(opts.getDate(AT));
} else if (opts.has(IN)) {
builder.startAt(new java.util.Date(System.currentTimeMillis() + opts.getLong(IN)));
} else {
builder.startNow();
}
if (opts.has(UNTIL)) {
builder.endAt(opts.getDate(UNTIL));
}
if (opts.has(CRON)) {
builder.withSchedule(CronScheduleBuilder.cronSchedule(opts.getString(CRON)));
} else if (opts.has(EVERY)) {
SimpleScheduleBuilder schedule =
SimpleScheduleBuilder.simpleSchedule()
.withIntervalInMilliseconds(opts.getInt(EVERY));
if (opts.has(LIMIT)) {
schedule.withRepeatCount(opts.getInt(LIMIT) - 1);
} else {
schedule.repeatForever();
}
builder.withSchedule(schedule);
}
return builder.build();
}
示例13: addScript
import org.quartz.TriggerBuilder; //导入方法依赖的package包/类
private void addScript(ScheduledScript script) throws Exception {
TriggerBuilder triggerBuilder = TriggerBuilder.newTrigger();
triggerBuilder.withIdentity(script.getId());
if (script.getCron() != null) {
triggerBuilder.withSchedule(CronScheduleBuilder.cronSchedule(script.getCron()));
}
if (script.getAt() != null) {
triggerBuilder.startAt(script.getAt());
}
if (script.getUntil() != null) {
triggerBuilder.endAt(script.getUntil());
}
Trigger trigger = triggerBuilder.build();
JobDataMap dataMap = new JobDataMap();
dataMap.put(SCRIPT_DATAMAP_KEY, script);
dataMap.put(SCRIPT_MANAGER_DATAMAP_KEY, scriptManager);
JobBuilder jobBuilder = JobBuilder.newJob();
jobBuilder.withIdentity(script.getId());
jobBuilder.ofType(ScriptJob.class);
jobBuilder.setJobData(dataMap);
scheduler.scheduleJob(jobBuilder.build(), trigger);
}
示例14: createTrigger
import org.quartz.TriggerBuilder; //导入方法依赖的package包/类
public Trigger createTrigger(JobKey jobKey) {
TriggerBuilder tb = newTrigger()
.forJob(jobKey)
.withIdentity(getTriggerName());
if (getCronExpression() != null) {
tb.withSchedule(cronSchedule(getCronExpression()));
}
if (isTriggerAtStartup()) {
tb.startAt(futureDate(5, DateBuilder.IntervalUnit.SECOND));
}
return tb.build();
}
示例15: schedule
import org.quartz.TriggerBuilder; //导入方法依赖的package包/类
/**
* 根据job实体调度具体的任务
*/
public void schedule(JobEntity entity) {
AssertHelper.notNull(entity);
JobDataMap data = new JobDataMap(entity.getArgs());
data.put(KEY, entity.getId());
data.put(MODEL, entity.getModelName());
Class<? extends Job> jobClazz = null;
String jobId = "";
switch(entity.getJobType()) {
case 0:
jobClazz = ExecutorJob.class;
jobId = TYPE_EXECUTOR + entity.getTask().getId();
break;
case 1:
jobClazz = ReminderJob.class;
jobId = TYPE_REMINDER + entity.getTask().getId();
break;
}
if(jobClazz == null) {
log.error("Quartz不支持的JOB类型:{}", entity.getJobType());
return;
}
JobDetail job = JobBuilder
.newJob(jobClazz)
.usingJobData(data)
.withIdentity(jobId, GROUP)
.build();
Trigger trigger = null;
TriggerBuilder<Trigger> builder = TriggerBuilder
.newTrigger()
.withIdentity(StringHelper.getPrimaryKey(), GROUP)
.startAt(entity.getStartTime());
if(jobClazz == ReminderJob.class && entity.getPeriod() > 0) {
int count = ConfigHelper.getNumerProperty(CONFIG_REPEAT);
if(count <= 0) count = 1;
builder.withSchedule(SimpleScheduleBuilder.
repeatMinutelyForTotalCount(count, entity.getPeriod()));
if(isUseCalendar) {
builder.modifiedByCalendar(CALENDAR_NAME);
}
}
trigger = builder.build();
try {
log.info("jobId:{} class:{} starting......", jobId, jobClazz);
getScheduler().scheduleJob(job, trigger);
} catch (SchedulerException e) {
log.error(e.getMessage());
}
}