本文整理匯總了Java中org.quartz.CronExpression.getNextValidTimeAfter方法的典型用法代碼示例。如果您正苦於以下問題:Java CronExpression.getNextValidTimeAfter方法的具體用法?Java CronExpression.getNextValidTimeAfter怎麽用?Java CronExpression.getNextValidTimeAfter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.quartz.CronExpression
的用法示例。
在下文中一共展示了CronExpression.getNextValidTimeAfter方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: isCronIntervalLessThanMinimum
import org.quartz.CronExpression; //導入方法依賴的package包/類
/**
* Checks if the given cron expression interval is less or equals to a certain minimum.
*
* @param cronExpression the cron expression to check
*/
public static boolean isCronIntervalLessThanMinimum(String cronExpression) {
try {
// If input is empty or invalid simply return false as default
if (StringUtils.isBlank(cronExpression) || !isValid(cronExpression)) {
return false;
}
CronExpression cron = new CronExpression(cronExpression);
final Date firstExecution = cron.getNextValidTimeAfter(new Date(System.currentTimeMillis()));
final Date secondExecution = cron.getNextValidTimeAfter(firstExecution);
Minutes intervalMinutes = Minutes.minutesBetween(new DateTime(firstExecution),
new DateTime(secondExecution));
return !intervalMinutes.isGreaterThan(MINIMUM_ALLOWED_MINUTES);
} catch (ParseException e) {
throw new IllegalArgumentException(e.getMessage());
}
}
示例2: getNextExecutionDate
import org.quartz.CronExpression; //導入方法依賴的package包/類
/**
* Retrieves the next execution time based on the schedule and
* the supplied date.
* @param after The date to get the next invocation after.
* @return The next execution time.
*/
public Date getNextExecutionDate(Date after) {
try {
CronExpression expression = new CronExpression(this.getCronPattern());
Date next = expression.getNextValidTimeAfter(DateUtils.latestDate(after, new Date()));
if(next == null) {
return null;
}
else if(endDate != null && next.after(endDate)) {
return null;
}
else {
return next;
}
}
catch(ParseException ex) {
System.out.println(" Encountered ParseException for cron expression: " + this.getCronPattern() + " in schedule: " + this.getOid());
return null;
}
}
示例3: oneTimeDate
import org.quartz.CronExpression; //導入方法依賴的package包/類
private void oneTimeDate(List<OLEBatchProcessScheduleBo> oleBatchProcessScheduleBoList) {
try {
for (OLEBatchProcessScheduleBo oleBatchProcessScheduleBo : oleBatchProcessScheduleBoList) {
CronExpression exp = new CronExpression(oleBatchProcessScheduleBo.getCronExpression());
Date date = exp.getNextValidTimeAfter(new Date());
if (date != null) {
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
Timestamp nextRunTime = new Timestamp(date.getTime());
oleBatchProcessScheduleBo.setNextRunTime(nextRunTime);
}
}
} catch (ParseException e) {
LOG.error("Error while validating cron exp::" + oleBatchProcessScheduleBoList.get(0).getCronExpression(), e);
}
}
示例4: initializeTriggersForModule
import org.quartz.CronExpression; //導入方法依賴的package包/類
/**
* method initializes triggers for the given jobName - Job name here is the schedule id
* the name will always be suffixed with "BATCH_JOB_"
*
* @param jobName
* @param cronExpression
*/
public void initializeTriggersForModule(String jobName, String cronExpression) throws Exception {
try {
CronExpression exp = new CronExpression(cronExpression);
Date date = exp.getNextValidTimeAfter(new Date());
if (date == null) {
throw new RuntimeException("given cron expression already past its valid time::" + cronExpression);
} else {
LOG.info("Next valid run time is:: " + date.toString() + " for the schedule job :: " + jobName);
addTrigger(getCronTriggerBean(jobName, cronExpression));
}
} catch (Exception e) {
LOG.info("given cron expression already past its valid time::" + cronExpression, e);
throw e;
}
}
示例5: computeResumeStartTime
import org.quartz.CronExpression; //導入方法依賴的package包/類
/**
* Returns the start time of the first detection job for the current backfill. The start time is determined in the
* following:
* 1. If there exists any previously left detection job, then start backfill from that job.
* 1a. if that job is finished, then start a job next to it.
* 1b. if that job is unfinished, then restart that job.
* 2. If there exists no previous left job, then start the job from the beginning.
*
* @param cronExpression the cron expression that is used to calculate the alignment of start time.
* @return the start time for the first detection job of this backfilling.
*/
private DateTime computeResumeStartTime(long functionId, CronExpression cronExpression, DateTime backfillStartTime, DateTime backfillEndTime) {
DateTime currentStart;
JobDTO previousJob = getPreviousJob(functionId, backfillStartTime.getMillis(), backfillEndTime.getMillis());
if (previousJob != null) {
long previousStartTime = previousJob.getWindowStartTime();
cleanUpJob(previousJob);
if (previousJob.getStatus().equals(JobStatus.COMPLETED)) {
// Schedule a job after previous job
currentStart = new DateTime(cronExpression.getNextValidTimeAfter(new Date(previousStartTime)));
} else {
// Reschedule the previous incomplete job
currentStart = new DateTime(previousStartTime);
}
LOG.info("Backfill starting from {} for function {} because a previous unfinished job found.", currentStart,
functionId);
} else {
// Schedule a job starting from the beginning
currentStart = backfillStartTime;
}
return currentStart;
}
示例6: getServiceResult
import org.quartz.CronExpression; //導入方法依賴的package包/類
@Override
protected void getServiceResult(HttpServletRequest request, Document document) throws Exception {
if (request != null) {
AbstractSchedule as = Engine.theApp.schedulerManager.getSchedulerXML().getSchedule(request.getParameter("name"));
Element rootElement = document.getDocumentElement();
Element cronsElement = document.createElement("crons");
// Compute nextTime only if not type of ScheduleRunNow (info = RunNow)
if (!(as instanceof ScheduleRunNow)) {
int iteration = Integer.parseInt(request.getParameter("iteration"));
String cronExpression = request.getParameter("input");
cronExpression = cronExpression.replaceFirst("(?:.*)\\[(.*)\\]", "$1");
long start = new Date().getTime();
boolean bContinue = true;
while (iteration-- > 0 && bContinue) {
Date nextTime;
String nDate;
try {
CronExpression exp = new CronExpression(cronExpression);
nextTime = exp.getNextValidTimeAfter(new Date(start));
start = nextTime.getTime() + 1;
nDate = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(new Date(start));
addNextTimeToCronsElement(document, cronsElement, nDate);
} catch (Exception e) {
addElementToCronsElement(document, cronsElement, "error", e.getMessage());
nDate = "";
bContinue = false;
}
}
} else {
addNextTimeToCronsElement(document, cronsElement, "n/a");
}
rootElement.appendChild(cronsElement);
}
}
示例7: parseCronExpression
import org.quartz.CronExpression; //導入方法依賴的package包/類
@DataProvider
public Collection<CronDate> parseCronExpression(String cron) throws Exception{
CronExpression expr=new CronExpression(cron);
List<CronDate> dates=new ArrayList<CronDate>();
Date startDate=new Date();
for(int i=0;i<50;i++){
startDate=expr.getNextValidTimeAfter(startDate);
CronDate cd=new CronDate();
cd.setDate(startDate);
dates.add(cd);
}
return dates;
}
示例8: getNextExecution
import org.quartz.CronExpression; //導入方法依賴的package包/類
/**
* Returns the next execution time based on the given Cron Expression
*
* @param cronExpression A Cron Expression
* @return Date - The next time the given Cron Expression should fire
*/
public static Date getNextExecution(String cronExpression) {
try {
CronExpression cron = new CronExpression(cronExpression);
return cron.getNextValidTimeAfter(new Date(System.currentTimeMillis()));
} catch (ParseException e) {
throw new IllegalArgumentException(e.getMessage());
}
}
示例9: handleView
import org.quartz.CronExpression; //導入方法依賴的package包/類
protected ModelAndView handleView(HttpServletRequest request, HttpServletResponse response, Object comm, BindException errors) throws Exception {
TargetSchedulesCommand command = (TargetSchedulesCommand) comm;
Schedule aSchedule = (Schedule) getEditorContext(request).getObject(Schedule.class, command.getSelectedItem());
TargetSchedulesCommand newCommand = TargetSchedulesCommand.buildFromModel(aSchedule);
List<Date> testResults = new LinkedList<Date>();
ModelAndView mav = getEditView(request, response, newCommand, errors);
mav.addObject("testResults", testResults);
mav.addObject("viewMode", new Boolean(true));
newCommand.setHeatMap(buildHeatMap());
newCommand.setHeatMapThresholds(buildHeatMapThresholds());
if(newCommand.getScheduleType() < 0) {
mav.addObject("monthOptions", getMonthOptionsByType(newCommand.getScheduleType()));
}
try {
CronExpression expr = new CronExpression(aSchedule.getCronPattern());
Date d = DateUtils.latestDate(new Date(), newCommand.getStartDate());
Date nextDate = null;
for(int i = 0; i<10; i++) {
nextDate = expr.getNextValidTimeAfter(d);
if(nextDate == null || newCommand.getEndDate() != null && nextDate.after(newCommand.getEndDate())) {
break;
}
testResults.add(nextDate);
d = nextDate;
}
}
catch(ParseException ex) {
ex.printStackTrace();
}
return mav;
}
示例10: handleTest
import org.quartz.CronExpression; //導入方法依賴的package包/類
protected ModelAndView handleTest(HttpServletRequest request, HttpServletResponse response, Object comm, BindException errors) throws Exception {
TargetSchedulesCommand command = (TargetSchedulesCommand) comm;
if(errors.hasErrors()) {
return getEditView(request, response, comm, errors);
}
else {
List<Date> testResults = new LinkedList<Date>();
ModelAndView mav = getEditView(request, response, comm, errors);
mav.addObject("testResults", testResults);
try {
CronExpression expr = new CronExpression(command.getCronExpression());
Date d = DateUtils.latestDate(new Date(), command.getStartDate());
Date nextDate = null;
for(int i = 0; i<10; i++) {
nextDate = expr.getNextValidTimeAfter(d);
if(nextDate == null || command.getEndDate() != null && nextDate.after(command.getEndDate())) {
break;
}
testResults.add(nextDate);
d = nextDate;
}
}
catch(ParseException ex) {
ex.printStackTrace();
}
return mav;
}
}
示例11: toInterval
import org.quartz.CronExpression; //導入方法依賴的package包/類
protected FiniteDuration toInterval(CronExpression cronExpression, Date now) {
log.debug("computing interval based on cron expression: {}", cronExpression.getCronExpression());
Date next = cronExpression.getNextValidTimeAfter(now);
if(log.isDebugEnabled()) {
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
log.debug("next time: {}", dateFormat.format(next));
}
return Duration.apply(next.getTime() - now.getTime(), TimeUnit.MILLISECONDS);
}
示例12: getExpectedRuntime
import org.quartz.CronExpression; //導入方法依賴的package包/類
private Optional<Long> getExpectedRuntime(SingularityRequest request, SingularityTaskId taskId) {
if (request.getScheduledExpectedRuntimeMillis().isPresent()) {
return request.getScheduledExpectedRuntimeMillis();
} else {
final Optional<SingularityDeployStatistics> deployStatistics = deployManager.getDeployStatistics(taskId.getRequestId(), taskId.getDeployId());
if (deployStatistics.isPresent() && deployStatistics.get().getAverageRuntimeMillis().isPresent()) {
return deployStatistics.get().getAverageRuntimeMillis();
}
String scheduleExpression = request.getScheduleTypeSafe() == ScheduleType.RFC5545 ? request.getSchedule().get() : request.getQuartzScheduleSafe();
Date nextRunAtDate;
try {
if (request.getScheduleTypeSafe() == ScheduleType.RFC5545) {
final RFC5545Schedule rfc5545Schedule = new RFC5545Schedule(scheduleExpression);
nextRunAtDate = rfc5545Schedule.getNextValidTime();
} else {
final CronExpression cronExpression = new CronExpression(scheduleExpression);
final Date startDate = new Date(taskId.getStartedAt());
nextRunAtDate = cronExpression.getNextValidTimeAfter(startDate);
}
if (nextRunAtDate == null) {
String msg = String.format("No next run date found for %s (%s)", taskId, scheduleExpression);
LOG.warn(msg);
exceptionNotifier.notify(msg, ImmutableMap.of("taskId", taskId.toString()));
return Optional.absent();
}
} catch (ParseException|InvalidRecurrenceRuleException e) {
LOG.warn("Unable to parse schedule of type {} for expression {} (taskId: {}, err: {})", request.getScheduleTypeSafe(), scheduleExpression, taskId, e);
exceptionNotifier.notify(String.format("Unable to parse schedule (%s)", e.getMessage()), e, ImmutableMap.of("taskId", taskId.toString(), "scheduleExpression", scheduleExpression, "scheduleType", request.getScheduleTypeSafe().toString()));
return Optional.absent();
}
return Optional.of(nextRunAtDate.getTime() - taskId.getStartedAt());
}
}
示例13: cronFireTimes
import org.quartz.CronExpression; //導入方法依賴的package包/類
public static LazySeq<Date> cronFireTimes(CronExpression expr, Date after) {
final Date nextFireTime = expr.getNextValidTimeAfter(after);
if (nextFireTime == null) {
return empty();
} else {
return cons(nextFireTime, cronFireTimes(expr, nextFireTime));
}
}
示例14: getNextRunAt
import org.quartz.CronExpression; //導入方法依賴的package包/類
private Optional<Long> getNextRunAt(SingularityRequest request, RequestState state, SingularityDeployStatistics deployStatistics, PendingType pendingType,
Optional<SingularityPendingDeploy> maybePendingDeploy) {
final long now = System.currentTimeMillis();
long nextRunAt = now;
if (request.isScheduled()) {
if (pendingType == PendingType.IMMEDIATE || pendingType == PendingType.RETRY) {
LOG.info("Scheduling requested immediate run of {}", request.getId());
} else {
try {
final CronExpression cronExpression = new CronExpression(request.getQuartzScheduleSafe());
final Date scheduleFrom = new Date(now);
final Date nextRunAtDate = cronExpression.getNextValidTimeAfter(scheduleFrom);
if (nextRunAtDate == null) {
return Optional.absent();
}
LOG.trace("Calculating nextRunAtDate for {} (schedule: {}): {} (from: {})", request.getId(), request.getSchedule(), nextRunAtDate, scheduleFrom);
nextRunAt = Math.max(nextRunAtDate.getTime(), now); // don't create a schedule that is overdue as this is used to indicate that singularity is not fulfilling requests.
LOG.trace("Scheduling next run of {} (schedule: {}) at {} (from: {})", request.getId(), request.getSchedule(), nextRunAtDate, scheduleFrom);
} catch (ParseException pe) {
throw Throwables.propagate(pe);
}
}
}
if (pendingType == PendingType.TASK_DONE && request.getWaitAtLeastMillisAfterTaskFinishesForReschedule().or(0L) > 0) {
nextRunAt = Math.max(nextRunAt, now + request.getWaitAtLeastMillisAfterTaskFinishesForReschedule().get());
LOG.trace("Adjusted next run of {} to {} (by {}) due to waitAtLeastMillisAfterTaskFinishesForReschedule", request.getId(), nextRunAt,
JavaUtils.durationFromMillis(request.getWaitAtLeastMillisAfterTaskFinishesForReschedule().get()));
}
if (state == RequestState.SYSTEM_COOLDOWN && pendingType != PendingType.NEW_DEPLOY) {
final long prevNextRunAt = nextRunAt;
nextRunAt = Math.max(nextRunAt, now + TimeUnit.SECONDS.toMillis(configuration.getCooldownMinScheduleSeconds()));
LOG.trace("Adjusted next run of {} to {} (from: {}) due to cooldown", request.getId(), nextRunAt, prevNextRunAt);
}
return Optional.of(nextRunAt);
}
示例15: getNextExecutionTime
import org.quartz.CronExpression; //導入方法依賴的package包/類
static Date getNextExecutionTime() throws Exception {
CronExpression cronExpression = new CronExpression("0 0 7 * * ?");
return cronExpression.getNextValidTimeAfter(new Date());
}