本文整理汇总了Java中org.quartz.TriggerBuilder.startAt方法的典型用法代码示例。如果您正苦于以下问题:Java TriggerBuilder.startAt方法的具体用法?Java TriggerBuilder.startAt怎么用?Java TriggerBuilder.startAt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.quartz.TriggerBuilder
的用法示例。
在下文中一共展示了TriggerBuilder.startAt方法的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: createCronTrigger
import org.quartz.TriggerBuilder; //导入方法依赖的package包/类
/**
* 创建复杂触发器
* @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;
}
示例4: 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);
}
示例5: 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);
}
示例6: 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;
}
示例7: createCronTrigger
import org.quartz.TriggerBuilder; //导入方法依赖的package包/类
/**
* 创建复杂触发器
*
* @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;
}
示例8: scheduleCronTask
import org.quartz.TriggerBuilder; //导入方法依赖的package包/类
/**
* Schedules a new task using supplied cron expression.
*
* @param inJobName Name of new task.
* @param inTriggerName Name of trigger for the new task.
* @param inGroupName Name of group to which new task and trigger is to belong.
* @param inJobClass The job class that will be executed when the new task triggers.
* @param inCronExpression Cron expression specifying when task is to be
* executed.
* @param inJobDataMap Map holding information to be passed to the
* job being executed. Contents of map will be copied.
* @param inStartDate Point in time after which task is to start being
* scheduled for execution, or null if task is to be scheduled now.
* @param inEndDate Point in time after which the task will no longer
* be scheduled for execution, or null if task is to be scheduled
* indefinitely.
* @throws Exception If error occurs scheduling task.
*/
public void scheduleCronTask(final String inJobName, final String inTriggerName, final String inGroupName,
final Class<? extends Job> inJobClass, final String inCronExpression, final Map<String, Object> inJobDataMap,
final Date inStartDate, final Date inEndDate) throws Exception {
final JobDetail theJob = JobBuilder.newJob(inJobClass).withIdentity(inJobName, inGroupName).build();
/* Copy job data from the supplied map to the actual job data map. */
theJob.getJobDataMap().putAll(inJobDataMap);
/*
* Create builder that will create a schedule for the new task using
* the supplied cron expression.
*/
final CronScheduleBuilder theScheduleBuilder = CronScheduleBuilder.cronSchedule(inCronExpression);
/*
* Create a trigger builder using the schedule builder,
* the start and end dates, if supplied.
*/
TriggerBuilder<CronTrigger> theTriggerBuilder =
TriggerBuilder.newTrigger().withIdentity(inTriggerName, inGroupName).withSchedule(theScheduleBuilder);
/* If no start date supplied, start now, else start at start date. */
if (inStartDate == null) {
theTriggerBuilder = theTriggerBuilder.startNow();
} else {
theTriggerBuilder = theTriggerBuilder.startAt(inStartDate);
}
/* If an end date supplied end at that date, otherwise continue indefinitely. */
theTriggerBuilder = theTriggerBuilder.endAt(inEndDate);
/* Schedule the new task. */
mTaskScheduler.scheduleJob(theJob, theTriggerBuilder.build());
LOGGER.debug("Scheduled task {} in group {}", inJobName, inGroupName);
}
示例9: 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();
}
示例10: 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();
}
示例11: 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);
}
示例12: 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();
}
示例13: addTrigger
import org.quartz.TriggerBuilder; //导入方法依赖的package包/类
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());
}
}
示例14: createUpdateWeatherDataScheduler
import org.quartz.TriggerBuilder; //导入方法依赖的package包/类
private Scheduler createUpdateWeatherDataScheduler(int interval,
TimeUnit unit, ResourceBinder resourceBinder, int startDelay)
throws SchedulerException, IOException, URISyntaxException {
StdSchedulerFactory schedulerFactory = new StdSchedulerFactory();
Properties properties = new Properties();
properties.setProperty("org.quartz.threadPool.threadCount",
String.valueOf(1));
schedulerFactory.initialize(properties);
Scheduler scheduler = schedulerFactory.getScheduler();
JobDetail job = JobBuilder.newJob(UpdateWeatherData.class).build();
job.getJobDataMap().put("baseDir", ResourceBinder
.getDataDir(this.getClass()).toFile().getCanonicalPath());
job.getJobDataMap().put("resourceBinder", resourceBinder);
int secs = 60;
switch (unit) {
case HOUR:
secs = interval * 60 * 60;
break;
case MINUTE:
secs = interval * 60;
case SECOND:
secs = interval;
break;
default:
break;
}
ScheduleBuilder<SimpleTrigger> scheduleBuilder = SimpleScheduleBuilder
.simpleSchedule().withIntervalInSeconds(secs).repeatForever();
TriggerBuilder<Trigger> triggerBuilder = TriggerBuilder.newTrigger()
.withIdentity("trigger1", "group1");
if (startDelay < 1)
triggerBuilder.startNow();
else
triggerBuilder.startAt(
DateBuilder.futureDate(startDelay, IntervalUnit.SECOND));
Trigger trigger = triggerBuilder.withSchedule(scheduleBuilder).build();
scheduler.scheduleJob(job, trigger);
return scheduler;
}
示例15: setTriggerParam
import org.quartz.TriggerBuilder; //导入方法依赖的package包/类
/**
* 设置trigger
*
* @param job
* @param triggerKey
* @param trigger
* @param triggerBuilder
*/
public Trigger setTriggerParam(ScheduleJob job, TriggerKey triggerKey, TriggerBuilder triggerBuilder,
Trigger trigger) {
if (job.getTriggerType().equals("CronTrigger")) {
CronScheduleBuilder cronBuilder = CronScheduleBuilder.cronSchedule(job.getCronExpression());
// 按新的cronExpression表达式构建一个新的trigger
if (job.getStartTime() != null)
triggerBuilder.startAt(job.getStartTime());
if (job.getEndTime() != null)
triggerBuilder.endAt(job.getEndTime());
//int index=job.getDesc().indexOf(";repeatType:")>-1?job.getDesc().indexOf(";repeatType:"):job.getDesc().length();
trigger = triggerBuilder.withIdentity(triggerKey).withSchedule(cronBuilder).withDescription(
job.getDesc()).build();
} else if (job.getTriggerType().equals("SimpleTrigger")) {
SimpleScheduleBuilder simpleBuilder = SimpleScheduleBuilder.simpleSchedule();
if (job.getStartTime() != null)
triggerBuilder.startAt(job.getStartTime());
if (job.getEndTime() != null)
triggerBuilder.endAt(job.getEndTime());
if (StrUtil.isNotBlank(job.getRepeatType())) {
if (job.getRepeatType().equals("repeatForever")) {
simpleBuilder=simpleBuilderForever(simpleBuilder,job);
}
else if (job.getRepeatType().equals("repeatHourlyForever")) {
if (job.getRepeatInterval() != null)
simpleBuilder = simpleBuilder.repeatHourlyForever(job.getRepeatInterval());
else
simpleBuilder = simpleBuilder.repeatHourlyForever();
} else if (job.getRepeatType().equals("repeatMinutelyForever")) {
if (job.getRepeatInterval() != null)
simpleBuilder = simpleBuilder.repeatMinutelyForever(job.getRepeatInterval());
else
simpleBuilder = simpleBuilder.repeatMinutelyForever();
} else if (job.getRepeatType().equals("repeatSecondlyForever")) {
if (job.getRepeatInterval() != null)
simpleBuilder = simpleBuilder.repeatSecondlyForever(job.getRepeatInterval());
else
simpleBuilder = simpleBuilder.repeatSecondlyForever();
} else if (job.getRepeatType().equals("repeatHourlyForTotalCount")) {
if (job.getRepeatCount() != null && job.getRepeatInterval() != null)
simpleBuilder = simpleBuilder.repeatHourlyForTotalCount(job.getRepeatCount(), job
.getRepeatInterval());
else if (job.getRepeatCount() != null)
simpleBuilder = simpleBuilder.repeatHourlyForTotalCount(job.getRepeatCount());
} else if (job.getRepeatType().equals("repeatMinutelyForTotalCount")) {
if (job.getRepeatCount() != null && job.getRepeatInterval() != null)
simpleBuilder = simpleBuilder.repeatMinutelyForTotalCount(job.getRepeatCount(), job
.getRepeatInterval());
else if (job.getRepeatCount() != null)
simpleBuilder = simpleBuilder.repeatMinutelyForTotalCount(job.getRepeatCount());
} else if (job.getRepeatType().equals("repeatSecondlyForTotalCount")) {
if (job.getRepeatCount() != null && job.getRepeatInterval() != null)
simpleBuilder = simpleBuilder.repeatSecondlyForTotalCount(job.getRepeatCount(), job
.getRepeatInterval());
else if (job.getRepeatCount() != null)
simpleBuilder = simpleBuilder.repeatSecondlyForTotalCount(job.getRepeatCount());
}
}
if(StrUtil.isEmpty(job.getDesc()))
job.setDesc("");
int index=job.getDesc().indexOf(";repeatType:")>-1?job.getDesc().indexOf(";repeatType:"):job.getDesc().length();
trigger = triggerBuilder.withIdentity(triggerKey).withSchedule(simpleBuilder).withDescription(
job.getDesc().substring(0,index) + ";repeatType:" + job.getRepeatType()).build();
/*trigger = triggerBuilder.withIdentity(triggerKey).withSchedule(simpleBuilder).withDescription(
job.getDesc()).build();*/
}
return trigger;
}