本文整理汇总了Java中org.quartz.DateBuilder类的典型用法代码示例。如果您正苦于以下问题:Java DateBuilder类的具体用法?Java DateBuilder怎么用?Java DateBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DateBuilder类属于org.quartz包,在下文中一共展示了DateBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: serverTasks
import org.quartz.DateBuilder; //导入依赖的package包/类
public serverTasks() throws SchedulerException, ParseException{
/*
* 循环式的
*/
SchedulerFactory factory = new StdSchedulerFactory();
Scheduler scheduler = factory.getScheduler();
//设置启动时间
DateBuilder.evenMinuteDate(new Date());
JobDetail job = JobBuilder.newJob(job.class).withIdentity("job1", "group1").build();
//job.getJobDataMap().put("a", true);//实现传参
// @NOTICE
// 与SimpleTrigger对比:类不同了,现在的是Trigger的子类CronTrigger;withSchedule中的参数变为CronScheduleBuilder了
// CronScheduleBuilder可以通过类似"0/13 * * * * ?"这种表达式来创建定时任务
// 当前这个表达式的定义是30分钟执行一次
CronTrigger trigger = TriggerBuilder.newTrigger().withIdentity("trigger1", "group1")
.withSchedule(CronScheduleBuilder.cronSchedule("1 0/30 * * * ?")).build();
scheduler.scheduleJob(job, trigger);
scheduler.start();
//scheduler.shutdown(true);
}
示例2: toIntervalUnit
import org.quartz.DateBuilder; //导入依赖的package包/类
private static DateBuilder.IntervalUnit toIntervalUnit(TimeUnit unit)
{
switch (unit)
{
case MILLISECONDS:
return DateBuilder.IntervalUnit.MILLISECOND;
case SECONDS:
return DateBuilder.IntervalUnit.SECOND;
case MINUTES:
return DateBuilder.IntervalUnit.MINUTE;
case HOURS:
return DateBuilder.IntervalUnit.HOUR;
case DAYS:
return DateBuilder.IntervalUnit.DAY;
case WEEKS:
return DateBuilder.IntervalUnit.WEEK;
case MONTHS:
return DateBuilder.IntervalUnit.MONTH;
case YEARS:
return DateBuilder.IntervalUnit.YEAR;
default:
checkState(false, "Invalid time unit" + unit);
return null;
}
}
示例3: TriggerWrapper
import org.quartz.DateBuilder; //导入依赖的package包/类
private TriggerWrapper(OperableTrigger trigger, TriggerState state) {
if (trigger == null) {
throw new IllegalArgumentException("Trigger cannot be null!");
}
this.trigger = trigger;
key = trigger.getKey();
this.jobKey = trigger.getJobKey();
this.state = state;
// Change to normal if acquired is not released in 5 seconds
if (state == TriggerState.ACQUIRED) {
acquiredAt = DateBuilder.newDate().build().getTime();
} else {
acquiredAt = null;
}
}
示例4: addScheduledJob
import org.quartz.DateBuilder; //导入依赖的package包/类
/** {@inheritDoc} */
public String addScheduledJob(int interval, IScheduledJob job) {
String name = getJobName();
// Store reference to applications job and service
JobDataMap jobData = new JobDataMap();
jobData.put(QuartzSchedulingServiceJob.SCHEDULING_SERVICE, this);
jobData.put(QuartzSchedulingServiceJob.SCHEDULED_JOB, job);
// detail
JobDetail jobDetail = JobBuilder.newJob(QuartzSchedulingServiceJob.class).withIdentity(name).usingJobData(jobData).build();
// create trigger that fires indefinitely every <interval> milliseconds
Trigger trigger = TriggerBuilder.newTrigger().withIdentity(String.format("Trigger_%s", name)).startAt(DateBuilder.futureDate(1, IntervalUnit.MILLISECOND)).forJob(jobDetail).withSchedule(SimpleScheduleBuilder.simpleSchedule().withIntervalInMilliseconds(interval).repeatForever()).build();
// store keys by name
TriggerKey tKey = trigger.getKey();
JobKey jKey = trigger.getJobKey();
log.debug("Job key: {} Trigger key: {}", jKey, tKey);
ScheduledJobKey key = new ScheduledJobKey(tKey, jKey);
keyMap.put(name, key);
// schedule
scheduleJob(trigger, jobDetail);
return name;
}
示例5: addScheduledJobAfterDelay
import org.quartz.DateBuilder; //导入依赖的package包/类
/** {@inheritDoc} */
public String addScheduledJobAfterDelay(int interval, IScheduledJob job, int delay) {
String name = getJobName();
// Store reference to applications job and service
JobDataMap jobData = new JobDataMap();
jobData.put(QuartzSchedulingServiceJob.SCHEDULING_SERVICE, this);
jobData.put(QuartzSchedulingServiceJob.SCHEDULED_JOB, job);
// detail
JobDetail jobDetail = JobBuilder.newJob(QuartzSchedulingServiceJob.class).withIdentity(name, null).usingJobData(jobData).build();
// Create trigger that fires indefinitely every <interval> milliseconds
Trigger trigger = TriggerBuilder.newTrigger().withIdentity(String.format("Trigger_%s", name)).startAt(DateBuilder.futureDate(delay, IntervalUnit.MILLISECOND)).forJob(jobDetail).withSchedule(SimpleScheduleBuilder.simpleSchedule().withIntervalInMilliseconds(interval).repeatForever()).build();
// store keys by name
TriggerKey tKey = trigger.getKey();
JobKey jKey = trigger.getJobKey();
log.debug("Job key: {} Trigger key: {}", jKey, tKey);
ScheduledJobKey key = new ScheduledJobKey(tKey, jKey);
keyMap.put(name, key);
// schedule
scheduleJob(trigger, jobDetail);
return name;
}
示例6: computeFirstFireTime
import org.quartz.DateBuilder; //导入依赖的package包/类
/**
* <p>
* Called by the scheduler at the time a <code>Trigger</code> is first
* added to the scheduler, in order to have the <code>Trigger</code>
* compute its first fire time, based on any associated calendar.
* </p>
*
* <p>
* After this method has been called, <code>getNextFireTime()</code>
* should return a valid answer.
* </p>
*
* @return the first time at which the <code>Trigger</code> will be fired
* by the scheduler, which is also the same value <code>getNextFireTime()</code>
* will return (until after the first firing of the <code>Trigger</code>).
* </p>
*/
@Override
public Date computeFirstFireTime(org.quartz.Calendar calendar) {
Date sTime = getStartTime();
Date startTimeOfDayDate = getStartTimeOfDay().getTimeOfDayForDate(sTime);
if(DateBuilder.evenSecondDate(startTime).equals(startTimeOfDayDate)) {
return startTime;
}
else if (sTime.after(startTimeOfDayDate)) {
// If startTime is after the timeOfDay, then look for the next time
nextFireTime = getFireTimeAfter(sTime);
} else {
// If startTime is before the timeOfDay then advance to timeOfDay (and if necessary dayOfWeek)
nextFireTime = advanceToNextDayOfWeekIfNecessary(startTimeOfDayDate, false);
}
// Check calendar for date-time exclusion
while (nextFireTime != null && calendar != null
&& !calendar.isTimeIncluded(nextFireTime.getTime())) {
nextFireTime = getFireTimeAfter(nextFireTime);
if(nextFireTime == null)
break;
//avoid infinite loop
java.util.Calendar c = java.util.Calendar.getInstance();
c.setTime(nextFireTime);
if (c.get(java.util.Calendar.YEAR) > YEAR_TO_GIVEUP_SCHEDULING_AT) {
return null;
}
}
return nextFireTime;
}
示例7: exportQuartz
import org.quartz.DateBuilder; //导入依赖的package包/类
public String exportQuartz() {
Map<String, Long> result = new HashMap<>();
for(JobKey key:manager.listAll(QUARTZ_JOB_GROUP_NAME)) {
Pair<JobDetail, Trigger> pair = manager.findInfo(key);
String name = ((SpiderInfo)pair.getLeft().getJobDataMap().get("spiderInfo")).getId();
Long hours = ((SimpleTrigger)((SimpleScheduleBuilder)pair.getRight().getScheduleBuilder()).build()).getRepeatInterval()/DateBuilder.MILLISECONDS_IN_HOUR;
result.put(name, hours);
}
return gson.toJson(result);
}
示例8: createTrigger
import org.quartz.DateBuilder; //导入依赖的package包/类
@SuppressWarnings("ConstantConditions")
static Trigger createTrigger(RollupTask task)
{
Duration executionInterval = task.getExecutionInterval();
return newTrigger()
.withIdentity(task.getId(), GROUP_ID)
.startAt(DateBuilder.futureDate((int) executionInterval.getValue(), toIntervalUnit(executionInterval.getUnit())))
.withSchedule(calendarIntervalSchedule()
.withInterval((int) executionInterval.getValue(), toIntervalUnit(executionInterval.getUnit())))
.build();
}
示例9: start
import org.quartz.DateBuilder; //导入依赖的package包/类
public void start() throws SchedulerException {
JobDetail job = JobBuilder.newJob(ScheduleExecutor.class)
.withIdentity(jobname, "group1")
.requestRecovery()
.usingJobData("configPath", configPath)
.usingJobData("logDirectory", logDirectory)
.build();
// schedule
int timeInterval = 1;
SimpleScheduleBuilder simpleScheduleBuilder = null;
simpleScheduleBuilder = SimpleScheduleBuilder.simpleSchedule();
simpleScheduleBuilder.withIntervalInHours(timeInterval * 24).repeatForever();
Trigger trigger = TriggerBuilder
.newTrigger()
.withIdentity(triggername, "group1")
.withSchedule(simpleScheduleBuilder)
.startAt(DateBuilder.dateOf(23, 55, 0))
.forJob(job)
.build();
scheduler = new StdSchedulerFactory(configPath+"config/quartz.properties").getScheduler();
scheduler.start();
scheduler.scheduleJob(job, trigger);
}
示例10: applyMisfire
import org.quartz.DateBuilder; //导入依赖的package包/类
private boolean applyMisfire(TriggerWrapper tw)
throws JobPersistenceException {
long misfireTime = DateBuilder.newDate().build().getTime();
if (misfireThreshold > 0) {
misfireTime -= misfireThreshold;
}
Date tnft = tw.trigger.getNextFireTime();
if (tnft == null
|| tnft.getTime() > misfireTime
|| tw.trigger.getMisfireInstruction() == Trigger.MISFIRE_INSTRUCTION_IGNORE_MISFIRE_POLICY) {
return false;
}
Calendar cal = null;
if (tw.trigger.getCalendarName() != null) {
cal = retrieveCalendar(tw.trigger.getCalendarName());
}
this.schedSignaler
.notifyTriggerListenersMisfired((OperableTrigger) tw.trigger.clone());
tw.trigger.updateAfterMisfire(cal);
if (tw.trigger.getNextFireTime() == null) {
storeTriggerWrapper(newTriggerWrapper(tw, STATE_COMPLETED));
schedSignaler.notifySchedulerListenersFinalized(tw.trigger);
} else if (tnft.equals(tw.trigger.getNextFireTime())) {
return false;
}
return true;
}
示例11: testAcquireNextTrigger
import org.quartz.DateBuilder; //导入依赖的package包/类
@Test
public void testAcquireNextTrigger()
throws Exception {
long baseFireTime = DateBuilder.newDate().build().getTime();
JobDetail job = JobBuilder.newJob(NoOpJob.class).build();
jobStore.storeJob(job, true);
OperableTrigger t1 = buildAndComputeTrigger("trigger1", "testAcquireNextTrigger", job, baseFireTime + 2000);
OperableTrigger t2 = buildAndComputeTrigger("trigger2", "testAcquireNextTrigger", job, baseFireTime + 500);
OperableTrigger t3 = buildAndComputeTrigger("trigger3", "testAcquireNextTrigger", job, baseFireTime + 1000);
assertTrue(jobStore.acquireNextTriggers(baseFireTime, 1, 0L).isEmpty());
jobStore.storeTrigger(t1, false);
assertEquals(jobStore.acquireNextTriggers(baseFireTime + 2000, 1, 0L).get(0), t1);
jobStore.storeTrigger(t2, false);
assertEquals(jobStore.acquireNextTriggers(baseFireTime + 600, 1, 0L).get(0), t2);
assertTrue(jobStore.acquireNextTriggers(baseFireTime + 600, 1, 0L).isEmpty());
jobStore.storeTrigger(t3, false);
assertEquals(jobStore.acquireNextTriggers(baseFireTime + 5000, 1, 0L).get(0), t3);
// release trigger3
jobStore.releaseAcquiredTrigger(t3);
assertEquals(jobStore.acquireNextTriggers(t3.getNextFireTime().getTime() + 5000, 1, 1L).get(0), t3);
assertTrue(jobStore.acquireNextTriggers(baseFireTime + 10000, 1, 0L).isEmpty());
jobStore.removeTrigger(t1.getKey());
jobStore.removeTrigger(t2.getKey());
jobStore.removeTrigger(t3.getKey());
}
示例12: testTriggersFired
import org.quartz.DateBuilder; //导入依赖的package包/类
@Test
public void testTriggersFired()
throws Exception {
long baseFireTime = DateBuilder.newDate().build().getTime();
JobDetail newJob = JobBuilder.newJob(NoOpJob.class).withIdentity("job1", "testTriggersFired").build();
jobStore.storeJob(newJob, false);
OperableTrigger trigger1 = buildAndComputeTrigger("triggerFired1",
"triggerFiredGroup",
newJob,
baseFireTime + 100,
baseFireTime + 100);
jobStore.storeTrigger(trigger1, false);
long firstFireTime = new Date(trigger1.getNextFireTime().getTime()).getTime();
List<OperableTrigger> acquiredTriggers = jobStore.acquireNextTriggers(firstFireTime + 500, 1, 0L);
assertEquals(acquiredTriggers.size(), 1);
List<TriggerFiredResult> triggerFired = jobStore.triggersFired(acquiredTriggers);
assertEquals(triggerFired.size(), 1);
assertTrue(jobStore.checkExists(trigger1.getKey()));
assertEquals(jobStore.getTriggerState(trigger1.getKey()), Trigger.TriggerState.COMPLETE);
jobStore.removeTrigger(trigger1.getKey());
}
示例13: scheduleIn
import org.quartz.DateBuilder; //导入依赖的package包/类
@Override
public String scheduleIn(Class<? extends Job> clz, JobDataMap data,
int millis, int interval) throws SchedulerException {
return schedule(clz, data, DateBuilder.futureDate(millis,
DateBuilder.IntervalUnit.MILLISECOND), interval,
SimpleTrigger.REPEAT_INDEFINITELY, null);
}
示例14: startLoading
import org.quartz.DateBuilder; //导入依赖的package包/类
public void startLoading() {
if (execService != null) {
return;
}
log.trace("starting execution...");
int i = 0;
for (final CalendarRuntime eventRuntime : EventStorage.getInstance().getEventCache().values()) {
try {
JobDetail job = JobBuilder.newJob().ofType(EventReloaderJob.class)
.usingJobData(EventReloaderJob.KEY_CONFIG, eventRuntime.getConfig().getKey())
.withIdentity(eventRuntime.getConfig().getKey(), JOB_NAME_EVENT_RELOADER).storeDurably()
.build();
this.scheduler.addJob(job, false);
SimpleTrigger jobTrigger = TriggerBuilder.newTrigger().forJob(job)
.withIdentity(eventRuntime.getConfig().getKey(), JOB_NAME_EVENT_RELOADER)
.startAt(DateBuilder.futureDate(10 + i, IntervalUnit.SECOND)).withSchedule(SimpleScheduleBuilder
.repeatMinutelyForever(eventRuntime.getConfig().getReloadMinutes()))
.build();
this.scheduler.scheduleJob(jobTrigger);
log.info("reload job scheduled for: {}", eventRuntime.getConfig().getKey());
} catch (SchedulerException e) {
log.warn("Cannot schedule calendar reloader", e);
}
// next event 10 seconds later
i += 10;
}
}
示例15: createTrigger
import org.quartz.DateBuilder; //导入依赖的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();
}