/** * Computes the nearest future timestamp that matches this cron tab. * <p> * More precisely, given the time 't', computes another smallest time x such that: * * <ul> * <li>x ≥ t (inclusive) * <li>x matches this crontab * </ul> * * <p> * Note that if t already matches this cron, it's returned as is. */ public Calendar ceil(long t) { Calendar cal = new GregorianCalendar(Locale.US); cal.setTimeInMillis(t); return ceil(cal); }
@Restricted(NoExternalUse.class) // just for form validation public @CheckForNull Calendar next() { Calendar nearest = null; for (CronTab tab : tabs) { Calendar scheduled = tab.ceil(tab.getTimeZone() == null ? Calendar.getInstance() : Calendar.getInstance(tab.getTimeZone())); if (nearest == null || nearest.after(scheduled)) { nearest = scheduled; } } return nearest; }
int next = f.ceil(this,cur); if (cur==next) continue; // this field is already in a good shape. move on to next
/** * Computes the nearest future timestamp that matches this cron tab. <p> * More precisely, given the time 't', computes another smallest time x such * that: * * <ul> <li>x >= t (inclusive) <li>x matches this crontab </ul> * * <p> Note that if t already matches this cron, it's returned as is. */ public Calendar ceil(long t) { Calendar cal = new GregorianCalendar(Locale.US); cal.setTimeInMillis(t); return ceil(cal); }
/** * Computes the nearest future timestamp that matches this cron tab. * <p> * More precisely, given the time 't', computes another smallest time x such that: * * <ul> * <li>x >= t (inclusive) * <li>x matches this crontab * </ul> * * <p> * Note that if t already matches this cron, it's returned as is. */ public Calendar ceil(long t) { Calendar cal = new GregorianCalendar(Locale.US); cal.setTimeInMillis(t); return ceil(cal); }
/** * Computes the nearest future timestamp that matches this cron tab. * <p> * More precisely, given the time 't', computes another smallest time x such that: * * <ul> * <li>x >= t (inclusive) * <li>x matches this crontab * </ul> * * <p> * Note that if t already matches this cron, it's returned as is. */ public Calendar ceil(long t) { Calendar cal = new GregorianCalendar(Locale.US); cal.setTimeInMillis(t); return ceil(cal); }
/** * Computes the nearest future timestamp that matches this cron tab. * <p> * More precisely, given the time 't', computes another smallest time x such that: * * <ul> * <li>x ≥ t (inclusive) * <li>x matches this crontab * </ul> * * <p> * Note that if t already matches this cron, it's returned as is. */ public Calendar ceil(long t) { Calendar cal = new GregorianCalendar(Locale.US); cal.setTimeInMillis(t); return ceil(cal); }
/** * Computes the nearest future timestamp that matches this cron tab. * <p> * More precisely, given the time 't', computes another smallest time x such that: * * <ul> * <li>x >= t (inclusive) * <li>x matches this crontab * </ul> * * <p> * Note that if t already matches this cron, it's returned as is. */ public Calendar ceil(long t) { Calendar cal = new GregorianCalendar(Locale.US); cal.setTimeInMillis(t); return ceil(cal); }
@Override public long getRecurrencePeriod() { try { CronTab tab = getCronTab(); GregorianCalendar now = new GregorianCalendar(); Calendar nextExecution = tab.ceil(now.getTimeInMillis()); long period = nextExecution.getTimeInMillis() - now.getTimeInMillis(); if(nextExecution.getTimeInMillis() - now.getTimeInMillis()<=60000) period = period + 60000l; //add one minute to not shedule it during one minute one than once return period; } catch (Exception ex) { logger.log(Level.SEVERE, null, ex); //it should not happen return 1000*60*6; } }
@Restricted(NoExternalUse.class) // just for form validation public @CheckForNull Calendar next() { Calendar nearest = null; for (CronTab tab : tabs) { Calendar scheduled = tab.ceil(tab.getTimeZone() == null ? Calendar.getInstance() : Calendar.getInstance(tab.getTimeZone())); if (nearest == null || nearest.after(scheduled)) { nearest = scheduled; } } return nearest; }
long calculateDelay(final long currentTime, final BackupType backupType, final String cron) { CronTab cronTab; try { if (StringUtils.isEmpty(cron)) { return -1; } cronTab = new CronTab(cron); final Calendar nextExecution = cronTab.ceil(currentTime); final long delay = nextExecution.getTimeInMillis() - currentTime; LOGGER.fine(MessageFormat.format("Current time: {0,date,medium} {0,time,long}. Next execution ({3}) in {2} seconds which is {1,date,medium} {1,time,long}", new Date(currentTime), nextExecution.getTime(), TimeUnit.MILLISECONDS.toSeconds(delay), backupType)); if (delay < 0) { final String msg = "Delay is a negative number, which means the next execution is in the past! This happens for Hudson/Jenkins installations with version 1.395 or below. Please upgrade to fix this."; LOGGER.severe(msg); throw new IllegalStateException(msg); } return delay; } catch (final ANTLRException e) { LOGGER.warning(MessageFormat.format( "Cannot parse the specified ''Backup schedule for {0} backups''. Check cron notation.", backupType.toString())); return -1; } }
int next = f.ceil(this,cur); if (cur==next) continue; // this field is already in a good shape. move on to next
/** * See {@link #ceil(long)}. * * This method modifies the given calendar and returns the same object. */ public Calendar ceil(Calendar cal) { OUTER: while (true) { for (CalendarField f : CalendarField.ADJUST_ORDER) { int cur = f.valueOf(cal); int next = f.ceil(this,cur); if (cur==next) continue; // this field is already in a good shape. move on to next // we are modifying this field, so clear all the lower level fields for (CalendarField l=f.lowerField; l!=null; l=l.lowerField) l.clear(cal); if (next<0) { // we need to roll over to the next field. f.rollUp(cal, 1); f.setTo(cal,f.first(this)); // since higher order field is affected by this, we need to restart from all over continue OUTER; } else { f.setTo(cal,next); if (f.redoAdjustmentIfModified) continue OUTER; // when we modify DAY_OF_MONTH and DAY_OF_WEEK, do it all over from the top } } return cal; // all fields adjusted } }
/** * See {@link #ceil(long)}. * * This method modifies the given calendar and returns the same object. */ public Calendar ceil(Calendar cal) { OUTER: while (true) { for (CalendarField f : CalendarField.ADJUST_ORDER) { int cur = f.valueOf(cal); int next = f.ceil(this,cur); if (cur==next) continue; // this field is already in a good shape. move on to next // we are modifying this field, so clear all the lower level fields for (CalendarField l=f.lowerField; l!=null; l=l.lowerField) l.clear(cal); if (next<0) { // we need to roll over to the next field. f.rollUp(cal, 1); f.setTo(cal,f.first(this)); // since higher order field is affected by this, we need to restart from all over continue OUTER; } else { f.setTo(cal,next); if (f.redoAdjustmentIfModified) continue OUTER; // when we modify DAY_OF_MONTH and DAY_OF_WEEK, do it all over from the top } } return cal; // all fields adjusted } }
/** * See {@link #ceil(long)}. * * This method modifies the given calendar and returns the same object. */ public Calendar ceil(Calendar cal) { OUTER: while (true) { for (CalendarField f : CalendarField.ADJUST_ORDER) { int cur = f.valueOf(cal); int next = f.ceil(this,cur); if (cur==next) continue; // this field is already in a good shape. move on to next // we are modifying this field, so clear all the lower level fields for (CalendarField l=f.lowerField; l!=null; l=l.lowerField) l.clear(cal); if (next<0) { // we need to roll over to the next field. f.rollUp(cal, 1); f.setTo(cal,f.first(this)); // since higher order field is affected by this, we need to restart from all over continue OUTER; } else { f.setTo(cal,next); if (f.redoAdjustmentIfModified) continue OUTER; // when we modify DAY_OF_MONTH and DAY_OF_WEEK, do it all over from the top } } return cal; // all fields adjusted } }
for (CalendarField f : CalendarField.ADJUST_ORDER) { int cur = f.valueOf(cal); int next = f.ceil(this, cur); if (cur == next) { continue; // this field is already in a good shape. move on to next