/** * This method is similar to {@link #getSchedule()}, except that this method does <i>not</i> check the timer state * and hence does <i>not</i> throw either {@link IllegalStateException} or {@link javax.ejb.NoSuchObjectLocalException} * or {@link javax.ejb.EJBException}. * * @return */ public ScheduleExpression getScheduleExpression() { return this.calendarTimeout.getScheduleExpression(); }
public Calendar getNextTimeout(Calendar currentCal) { return getNextTimeout(currentCal, true); }
private boolean noMoreTimeouts(Calendar cal) { if (cal.get(Calendar.YEAR) > Year.MAX_YEAR || isAfterEnd(cal)) { return true; } return false; }
public IntegerBasedExpression(String value) { this.origValue = value; this.scheduleExpressionType = ScheduleExpressionTypeUtil.getType(value); if (this.accepts(scheduleExpressionType) == false) { throw EjbLogger.EJB3_TIMER_LOGGER.invalidScheduleExpressionType(value, this.getClass().getName(), this.scheduleExpressionType.toString()); RangeValue range = new RangeValue(value); this.processRangeValue(range); break; ListValue list = new ListValue(value); this.processListValue(list); break; IncrementValue incrValue = new IncrementValue(value); this.processIncrement(incrValue); break; SingleValue singleValue = new SingleValue(value); this.processSingleValue(singleValue); break;
private Calendar computeNextDayOfMonth(Calendar nextCal) { Integer nextDayOfMonth = this.dayOfMonth.getNextMatch(nextCal); if (this.monthHasDate(nextCal, nextDayOfMonth)) { resetTimeToFirstValues(nextCal); nextCal = this.advanceTillMonthHasDate(nextCal, nextDayOfMonth); resetTimeToFirstValues(nextCal); nextCal = this.computeNextMonth(nextCal); if (nextCal == null) { return null; nextDayOfMonth = this.dayOfMonth.getFirstMatch(nextCal); if (nextDayOfMonth == null) { return null; nextCal = this.advanceTillMonthHasDate(nextCal, nextDayOfMonth);
protected void processListItem(String listItem) { // check what type of a value the list item is. // Each item in the list must be an individual attribute value or a range. // List items can not themselves be lists, wild-cards, or increments. ScheduleExpressionType listItemType = ScheduleExpressionTypeUtil.getType(listItem); switch (listItemType) { case SINGLE_VALUE: SingleValue singleVal = new SingleValue(listItem); this.processSingleValue(singleVal); return; case RANGE: RangeValue range = new RangeValue(listItem); this.processRangeValue(range); return; default: throw EjbLogger.EJB3_TIMER_LOGGER.invalidListValue(listItem); } }
private Calendar getNextTimeout(Calendar currentCal, boolean increment) { if (this.noMoreTimeouts(currentCal)) { return null; nextCal = this.computeNextTime(nextCal); if (nextCal == null) { return null; nextCal = this.computeNextMonth(nextCal); if (nextCal == null) { return null; nextCal = this.computeNextDate(nextCal); if (nextCal == null) { return null; nextCal = this.computeNextYear(nextCal); if (nextCal == null) { return null; if (this.noMoreTimeouts(nextCal)) { return null;
private Calendar computeNextDate(Calendar nextCal) { if (this.isDayOfMonthWildcard()) { return this.computeNextDayOfWeek(nextCal); } if (this.isDayOfWeekWildcard()) { return this.computeNextDayOfMonth(nextCal); } // both day-of-month and day-of-week are *non-wildcards* Calendar nextDayOfMonthCal = this.computeNextDayOfMonth((Calendar) nextCal.clone()); Calendar nextDayOfWeekCal = this.computeNextDayOfWeek((Calendar) nextCal.clone()); if (nextDayOfMonthCal == null) { return nextDayOfWeekCal; } if (nextDayOfWeekCal == null) { return nextDayOfMonthCal; } return nextDayOfWeekCal.getTime().before(nextDayOfMonthCal.getTime()) ? nextDayOfWeekCal : nextDayOfMonthCal; }
private Calendar advanceTillMonthHasDate(Calendar cal, Integer date) { resetTimeToFirstValues(cal); // make sure the month can handle the date while (monthHasDate(cal, date) == false) { if (cal.get(Calendar.YEAR) > Year.MAX_YEAR) { return null; } // this month can't handle the date, so advance month to next month // and get the next suitable matching month cal.add(Calendar.MONTH, 1); cal = this.computeNextMonth(cal); if (cal == null) { return null; } date = this.dayOfMonth.getFirstMatch(cal); if (date == null) { return null; } } cal.set(Calendar.DAY_OF_MONTH, date); return cal; }
/** * * @param calendar */ private void resetTimeToFirstValues(Calendar calendar) { final int currentHour = calendar.get(Calendar.HOUR_OF_DAY); final int currentMinute = calendar.get(Calendar.MINUTE); final int currentSecond = calendar.get(Calendar.SECOND); final int firstHour = this.hour.getFirst(); final int firstMinute = this.minute.getFirst(); final int firstSecond = this.second.getFirst(); if (currentHour != firstHour || currentMinute != firstMinute || currentSecond != firstSecond) { setTime(calendar, firstHour, firstMinute, firstSecond); } }
private Calendar computeNextYear(Calendar nextCal) { Integer nextYear = this.year.getNextMatch(nextCal); if (nextYear == null || nextYear > Year.MAX_YEAR) { return null; } int currentYear = nextCal.get(Calendar.YEAR); // if the current year is a match, then nothing else to // do. Just return back the calendar if (currentYear == nextYear) { return nextCal; } // If the next year is lesser than the current year, then // we have no more timeouts for the calendar expression if (nextYear < currentYear) { return null; } // at this point we have chosen a year which is greater than the current // year. // set the chosen year nextCal.set(Calendar.YEAR, nextYear); // since we are moving to a different year (as compared to the current year), // we should reset all other calendar attribute expressions appropriately, to their first possible // values nextCal.set(Calendar.MONTH, this.month.getFirstMatch()); nextCal.set(Calendar.DAY_OF_MONTH, 1); resetTimeToFirstValues(nextCal); // recompute date nextCal = this.computeNextDate(nextCal); return nextCal; }
Integer nextSecond = this.second.getNextMatch(currentSecond); if (nextSecond == null) { return null; currentMinute++; Integer nextMinute = this.minute.getNextMatch(currentMinute < 60 ? currentMinute : 0); if (nextMinute == null) { return null; nextSecond = this.second.getNextMatch(0); currentHour++; Integer nextHour = this.hour.getNextMatch(currentHour < 24 ? currentHour : 0); if (nextHour == null) { return null; nextSecond = this.second.getNextMatch(0); nextMinute = this.minute.getNextMatch(0); setTime(nextCal, nextHour, nextMinute, nextSecond);
private Calendar computeNextDayOfWeek(Calendar nextCal) { Integer nextDayOfWeek = this.dayOfWeek.getNextMatch(nextCal); resetTimeToFirstValues(nextCal); nextCal = computeNextMonth(nextCal);
private Calendar computeNextMonth(Calendar nextCal) { Integer nextMonth = this.month.getNextMatch(nextCal); nextCal.set(Calendar.DAY_OF_WEEK, this.dayOfWeek.getFirst()); nextCal.set(Calendar.DAY_OF_MONTH, 1); resetTimeToFirstValues(nextCal);
s.end(builder.scheduleExprEndDate); s.timezone(builder.scheduleExprTimezone); this.calendarTimeout = new CalendarBasedTimeout(s); Calendar nextTimeout = this.calendarTimeout.getNextTimeout(); if (nextTimeout != null) { this.nextExpiration = nextTimeout.getTime();
private void setFirstTimeout() { Calendar currentCal = new GregorianCalendar(this.timezone); Date start = this.scheduleExpression.getStart(); if (start != null) { currentCal.setTime(start); } else { resetTimeToFirstValues(currentCal); } this.firstTimeout = getNextTimeout(currentCal, false); }
public CalendarBasedTimeout getCalendarTimeout() { if (this.calendarTimeout == null) { this.calendarTimeout = new CalendarBasedTimeout(this.getScheduleExpression()); } return this.calendarTimeout; }
public Calendar getNextTimeout() { return getNextTimeout(new GregorianCalendar(this.timezone), true); }
/** * {@inheritDoc} * * @see #getScheduleExpression() */ @Override public ScheduleExpression getSchedule() throws IllegalStateException, EJBException { this.assertTimerState(); return this.calendarTimeout.getScheduleExpression(); }
@Override protected Date calculateNextTimeout(TimerImpl timer) { // The next timeout for the calendar timer will have to be computed using the // current "nextExpiration" Date currentTimeout = timer.getNextExpiration(); if (currentTimeout == null) { return null; } Calendar cal = new GregorianCalendar(); cal.setTime(currentTimeout); // now compute the next timeout date Calendar nextTimeout = ((CalendarTimer) timer).getCalendarTimeout().getNextTimeout(cal); if (nextTimeout != null) { return nextTimeout.getTime(); } return null; }