本文整理汇总了Java中org.quartz.DateBuilder.IntervalUnit类的典型用法代码示例。如果您正苦于以下问题:Java IntervalUnit类的具体用法?Java IntervalUnit怎么用?Java IntervalUnit使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IntervalUnit类属于org.quartz.DateBuilder包,在下文中一共展示了IntervalUnit类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTriggerPropertyBundle
import org.quartz.DateBuilder.IntervalUnit; //导入依赖的package包/类
@Override
protected TriggerPropertyBundle getTriggerPropertyBundle(SimplePropertiesTriggerProperties props) {
TimeZone tz = null; // if we use null, that's ok as system default tz will be used
String tzId = props.getString2();
if(tzId != null && tzId.trim().length() != 0) // there could be null entries from previously released versions
tz = TimeZone.getTimeZone(tzId);
ScheduleBuilder<?> sb = CalendarIntervalScheduleBuilder.calendarIntervalSchedule()
.withInterval(props.getInt1(), IntervalUnit.valueOf(props.getString1()))
.inTimeZone(tz)
.preserveHourOfDayAcrossDaylightSavings(props.isBoolean1())
.skipDayIfHourDoesNotExist(props.isBoolean2());
int timesTriggered = props.getInt2();
String[] statePropertyNames = { "timesTriggered" };
Object[] statePropertyValues = { timesTriggered };
return new TriggerPropertyBundle(sb, statePropertyNames, statePropertyValues);
}
示例2: addScheduledJob
import org.quartz.DateBuilder.IntervalUnit; //导入依赖的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;
}
示例3: addScheduledJobAfterDelay
import org.quartz.DateBuilder.IntervalUnit; //导入依赖的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;
}
示例4: setRepeatIntervalUnit
import org.quartz.DateBuilder.IntervalUnit; //导入依赖的package包/类
/**
* <p>Set the interval unit - the time unit on with the interval applies.</p>
*
* @param intervalUnit The repeat interval unit. The only intervals that are valid for this type of trigger are
* {@link IntervalUnit#SECOND}, {@link IntervalUnit#MINUTE}, and {@link IntervalUnit#HOUR}.
*/
public void setRepeatIntervalUnit(IntervalUnit intervalUnit) {
if (repeatIntervalUnit == null ||
!((repeatIntervalUnit.equals(IntervalUnit.SECOND) ||
repeatIntervalUnit.equals(IntervalUnit.MINUTE) ||
repeatIntervalUnit.equals(IntervalUnit.HOUR))))
throw new IllegalArgumentException("Invalid repeat IntervalUnit (must be SECOND, MINUTE or HOUR).");
this.repeatIntervalUnit = intervalUnit;
}
示例5: validate
import org.quartz.DateBuilder.IntervalUnit; //导入依赖的package包/类
/**
* <p>
* Validates whether the properties of the <code>JobDetail</code> are
* valid for submission into a <code>Scheduler</code>.
*
* @throws IllegalStateException
* if a required property (such as Name, Group, Class) is not
* set.
*/
@Override
public void validate() throws SchedulerException {
super.validate();
if (repeatIntervalUnit == null || !(repeatIntervalUnit.equals(IntervalUnit.SECOND) ||
repeatIntervalUnit.equals(IntervalUnit.MINUTE) ||repeatIntervalUnit.equals(IntervalUnit.HOUR)))
throw new SchedulerException("Invalid repeat IntervalUnit (must be SECOND, MINUTE or HOUR).");
if (repeatInterval < 1) {
throw new SchedulerException("Repeat Interval cannot be zero.");
}
// Ensure interval does not exceed 24 hours
long secondsInHour = 24 * 60 * 60L;
if (repeatIntervalUnit == IntervalUnit.SECOND && repeatInterval > secondsInHour) {
throw new SchedulerException("repeatInterval can not exceed 24 hours (" + secondsInHour + " seconds). Given " + repeatInterval);
}
if (repeatIntervalUnit == IntervalUnit.MINUTE && repeatInterval > secondsInHour / 60L) {
throw new SchedulerException("repeatInterval can not exceed 24 hours (" + secondsInHour / 60L + " minutes). Given " + repeatInterval);
}
if (repeatIntervalUnit == IntervalUnit.HOUR && repeatInterval > 24 ) {
throw new SchedulerException("repeatInterval can not exceed 24 hours. Given " + repeatInterval + " hours.");
}
// Ensure timeOfDay is in order.
if (getEndTimeOfDay() != null && !getStartTimeOfDay().before(getEndTimeOfDay())) {
throw new SchedulerException("StartTimeOfDay " + startTimeOfDay + " should not come after endTimeOfDay " + endTimeOfDay);
}
}
示例6: startLoading
import org.quartz.DateBuilder.IntervalUnit; //导入依赖的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;
}
}
示例7: getRepeatIntervalUnit
import org.quartz.DateBuilder.IntervalUnit; //导入依赖的package包/类
public IntervalUnit getRepeatIntervalUnit() {
return repeatIntervalUnit;
}
示例8: setRepeatIntervalUnit
import org.quartz.DateBuilder.IntervalUnit; //导入依赖的package包/类
/**
* <p>Set the interval unit - the time unit on with the interval applies.</p>
*/
public void setRepeatIntervalUnit(IntervalUnit intervalUnit) {
this.repeatIntervalUnit = intervalUnit;
}
示例9: getFinalFireTime
import org.quartz.DateBuilder.IntervalUnit; //导入依赖的package包/类
/**
* <p>
* Returns the final time at which the <code>DateIntervalTrigger</code> will
* fire, if there is no end time set, null will be returned.
* </p>
*
* <p>
* Note that the return time may be in the past.
* </p>
*/
@Override
public Date getFinalFireTime() {
if (complete || getEndTime() == null) {
return null;
}
// back up a second from end time
Date fTime = new Date(getEndTime().getTime() - 1000L);
// find the next fire time after that
fTime = getFireTimeAfter(fTime, true);
// the the trigger fires at the end time, that's it!
if(fTime.equals(getEndTime()))
return fTime;
// otherwise we have to back up one interval from the fire time after the end time
Calendar lTime = Calendar.getInstance();
if(timeZone != null)
lTime.setTimeZone(timeZone);
lTime.setTime(fTime);
lTime.setLenient(true);
if(getRepeatIntervalUnit().equals(IntervalUnit.SECOND)) {
lTime.add(java.util.Calendar.SECOND, -1 * getRepeatInterval());
}
else if(getRepeatIntervalUnit().equals(IntervalUnit.MINUTE)) {
lTime.add(java.util.Calendar.MINUTE, -1 * getRepeatInterval());
}
else if(getRepeatIntervalUnit().equals(IntervalUnit.HOUR)) {
lTime.add(java.util.Calendar.HOUR_OF_DAY, -1 * getRepeatInterval());
}
else if(getRepeatIntervalUnit().equals(IntervalUnit.DAY)) {
lTime.add(java.util.Calendar.DAY_OF_YEAR, -1 * getRepeatInterval());
}
else if(getRepeatIntervalUnit().equals(IntervalUnit.WEEK)) {
lTime.add(java.util.Calendar.WEEK_OF_YEAR, -1 * getRepeatInterval());
}
else if(getRepeatIntervalUnit().equals(IntervalUnit.MONTH)) {
lTime.add(java.util.Calendar.MONTH, -1 * getRepeatInterval());
}
else if(getRepeatIntervalUnit().equals(IntervalUnit.YEAR)) {
lTime.add(java.util.Calendar.YEAR, -1 * getRepeatInterval());
}
return lTime.getTime();
}
示例10: endingDailyAfterCount
import org.quartz.DateBuilder.IntervalUnit; //导入依赖的package包/类
/**
* Calculate and set the endTimeOfDay using count, interval and starTimeOfDay. This means
* that these must be set before this method is call.
*
* @return the updated DailyTimeIntervalScheduleBuilder
*/
public DailyTimeIntervalScheduleBuilder endingDailyAfterCount(int count) {
if(count <=0)
throw new IllegalArgumentException("Ending daily after count must be a positive number!");
if(startTimeOfDay == null)
throw new IllegalArgumentException("You must set the startDailyAt() before calling this endingDailyAfterCount()!");
Date today = new Date();
Date startTimeOfDayDate = startTimeOfDay.getTimeOfDayForDate(today);
Date maxEndTimeOfDayDate = TimeOfDay.hourMinuteAndSecondOfDay(23, 59, 59).getTimeOfDayForDate(today);
long remainingMillisInDay = maxEndTimeOfDayDate.getTime() - startTimeOfDayDate.getTime();
long intervalInMillis;
if (intervalUnit == IntervalUnit.SECOND)
intervalInMillis = interval * 1000L;
else if (intervalUnit == IntervalUnit.MINUTE)
intervalInMillis = interval * 1000L * 60;
else if (intervalUnit == IntervalUnit.HOUR)
intervalInMillis = interval * 1000L * 60 * 24;
else
throw new IllegalArgumentException("The IntervalUnit: " + intervalUnit + " is invalid for this trigger.");
if (remainingMillisInDay - intervalInMillis <= 0)
throw new IllegalArgumentException("The startTimeOfDay is too late with given Interval and IntervalUnit values.");
long maxNumOfCount = (remainingMillisInDay / intervalInMillis);
if (count > maxNumOfCount)
throw new IllegalArgumentException("The given count " + count + " is too large! The max you can set is " + maxNumOfCount);
long incrementInMillis = (count - 1) * intervalInMillis;
Date endTimeOfDayDate = new Date(startTimeOfDayDate.getTime() + incrementInMillis);
if (endTimeOfDayDate.getTime() > maxEndTimeOfDayDate.getTime())
throw new IllegalArgumentException("The given count " + count + " is too large! The max you can set is " + maxNumOfCount);
Calendar cal = Calendar.getInstance();
cal.setTime(endTimeOfDayDate);
int hour = cal.get(Calendar.HOUR_OF_DAY);
int minute = cal.get(Calendar.MINUTE);
int second = cal.get(Calendar.SECOND);
endTimeOfDay = TimeOfDay.hourMinuteAndSecondOfDay(hour, minute, second);
return this;
}
示例11: createUpdateWeatherDataScheduler
import org.quartz.DateBuilder.IntervalUnit; //导入依赖的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;
}
示例12: DailyTimeIntervalTriggerImpl
import org.quartz.DateBuilder.IntervalUnit; //导入依赖的package包/类
/**
* <p>
* Create a <code>DailyTimeIntervalTrigger</code> that will occur at the given time,
* and repeat at the the given interval until the given end time.
* </p>
*
* @param startTime
* A <code>Date</code> set to the time for the <code>Trigger</code>
* to fire.
* @param endTime
* A <code>Date</code> set to the time for the <code>Trigger</code>
* to quit repeat firing.
* @param startTimeOfDay
* The <code>TimeOfDay</code> that the repeating should begin occurring.
* @param endTimeOfDay
* The <code>TimeOfDay</code> that the repeating should stop occurring.
* @param intervalUnit The repeat interval unit. The only intervals that are valid for this type of trigger are
* {@link IntervalUnit#SECOND}, {@link IntervalUnit#MINUTE}, and {@link IntervalUnit#HOUR}.
* @param repeatInterval
* The number of milliseconds to pause between the repeat firing.
* @throws IllegalArgumentException if an invalid IntervalUnit is given, or the repeat interval is zero or less.
*/
public DailyTimeIntervalTriggerImpl(String name, String group, Date startTime,
Date endTime, TimeOfDay startTimeOfDay, TimeOfDay endTimeOfDay,
IntervalUnit intervalUnit, int repeatInterval) {
super(name, group);
setStartTime(startTime);
setEndTime(endTime);
setRepeatIntervalUnit(intervalUnit);
setRepeatInterval(repeatInterval);
setStartTimeOfDay(startTimeOfDay);
setEndTimeOfDay(endTimeOfDay);
}
示例13: CalendarIntervalTriggerImpl
import org.quartz.DateBuilder.IntervalUnit; //导入依赖的package包/类
/**
* <p>
* Create a <code>DateIntervalTrigger</code> that will occur at the given time,
* and repeat at the the given interval until the given end time.
* </p>
*
* @param startTime
* A <code>Date</code> set to the time for the <code>Trigger</code>
* to fire.
* @param endTime
* A <code>Date</code> set to the time for the <code>Trigger</code>
* to quit repeat firing.
* @param intervalUnit
* The repeat interval unit (minutes, days, months, etc).
* @param repeatInterval
* The number of milliseconds to pause between the repeat firing.
*/
public CalendarIntervalTriggerImpl(String name, String group, Date startTime,
Date endTime, IntervalUnit intervalUnit, int repeatInterval) {
super(name, group);
setStartTime(startTime);
setEndTime(endTime);
setRepeatIntervalUnit(intervalUnit);
setRepeatInterval(repeatInterval);
}
示例14: withInterval
import org.quartz.DateBuilder.IntervalUnit; //导入依赖的package包/类
/**
* Specify the time unit and interval for the Trigger to be produced.
*
* @param timeInterval the interval at which the trigger should repeat.
* @param unit the time unit (IntervalUnit) of the interval. The only intervals that are valid for this type of
* trigger are {@link IntervalUnit#SECOND}, {@link IntervalUnit#MINUTE}, and {@link IntervalUnit#HOUR}.
* @return the updated DailyTimeIntervalScheduleBuilder
* @see DailyTimeIntervalTrigger#getRepeatInterval()
* @see DailyTimeIntervalTrigger#getRepeatIntervalUnit()
*/
public DailyTimeIntervalScheduleBuilder withInterval(int timeInterval, IntervalUnit unit) {
if (unit == null || !(unit.equals(IntervalUnit.SECOND) ||
unit.equals(IntervalUnit.MINUTE) ||unit.equals(IntervalUnit.HOUR)))
throw new IllegalArgumentException("Invalid repeat IntervalUnit (must be SECOND, MINUTE or HOUR).");
validateInterval(timeInterval);
this.interval = timeInterval;
this.intervalUnit = unit;
return this;
}
示例15: withInterval
import org.quartz.DateBuilder.IntervalUnit; //导入依赖的package包/类
/**
* Specify the time unit and interval for the Trigger to be produced.
*
* @param timeInterval the interval at which the trigger should repeat.
* @param unit the time unit (IntervalUnit) of the interval.
* @return the updated CalendarIntervalScheduleBuilder
* @see CalendarIntervalTrigger#getRepeatInterval()
* @see CalendarIntervalTrigger#getRepeatIntervalUnit()
*/
public CalendarIntervalScheduleBuilder withInterval(int timeInterval, IntervalUnit unit) {
if(unit == null)
throw new IllegalArgumentException("TimeUnit must be specified.");
validateInterval(timeInterval);
this.interval = timeInterval;
this.intervalUnit = unit;
return this;
}