Java Code Examples for org.quartz.DateBuilder.IntervalUnit#MINUTE
The following examples show how to use
org.quartz.DateBuilder.IntervalUnit#MINUTE .
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: DailyTimeIntervalTriggerImpl.java From lams with GNU General Public License v2.0 | 5 votes |
/** * <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); } }
Example 2
Source File: DailyTimeIntervalScheduleBuilder.java From lams with GNU General Public License v2.0 | 4 votes |
/** * 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; }
Example 3
Source File: CalendarIntervalScheduleBuilder.java From lams with GNU General Public License v2.0 | 3 votes |
/** * Specify an interval in the IntervalUnit.MINUTE that the produced * Trigger will repeat at. * * @param intervalInMinutes the number of minutes at which the trigger should repeat. * @return the updated CalendarIntervalScheduleBuilder * @see CalendarIntervalTrigger#getRepeatInterval() * @see CalendarIntervalTrigger#getRepeatIntervalUnit() */ public CalendarIntervalScheduleBuilder withIntervalInMinutes(int intervalInMinutes) { validateInterval(intervalInMinutes); this.interval = intervalInMinutes; this.intervalUnit = IntervalUnit.MINUTE; return this; }