本文整理汇总了Java中org.springframework.scheduling.support.CronSequenceGenerator类的典型用法代码示例。如果您正苦于以下问题:Java CronSequenceGenerator类的具体用法?Java CronSequenceGenerator怎么用?Java CronSequenceGenerator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CronSequenceGenerator类属于org.springframework.scheduling.support包,在下文中一共展示了CronSequenceGenerator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: saveJob
import org.springframework.scheduling.support.CronSequenceGenerator; //导入依赖的package包/类
/**
* @param job {@link JobsDTO}
*/
@Trace(metricName = "QuartzService{saveJob}", async = true, dispatcher = true)
public void saveJob(JobsDTO job) throws BadRequestException, SchedulerException {
checkIfAlreadyRegistered(job);
switch (job.getAsync()) {
case PERIODIC:
Trigger trigger = scheduler.getTrigger(TriggerKey.triggerKey(getTriggerFormat(job), QuartzContants.THREAD_GROUP_PERIODIC));
selectStatus(job, trigger);
break;
case CRON:
if (!CronSequenceGenerator.isValidExpression(job.getCron())) {
throw new BadRequestException(String.format("%s is not valid", job.getCron()));
}
trigger = scheduler.getTrigger(TriggerKey.triggerKey(getTriggerFormat(job), QuartzContants.THREAD_GROUP_CRON));
selectStatus(job, trigger);
break;
}
}
示例2: calculateNextCronDate
import org.springframework.scheduling.support.CronSequenceGenerator; //导入依赖的package包/类
protected long calculateNextCronDate(ScheduledTask task, long date, long currentDate, long frame) {
StopWatch sw = new Slf4JStopWatch("Cron next date calculations");
CronSequenceGenerator cronSequenceGenerator = new CronSequenceGenerator(task.getCron(), getCurrentTimeZone());
//if last start = 0 (task never has run) or to far in the past, we use (NOW - FRAME) timestamp for pivot time
//this approach should work fine cause cron works with absolute time
long pivotPreviousTime = Math.max(date, currentDate - frame);
Date currentStart = null;
Date nextDate = cronSequenceGenerator.next(new Date(pivotPreviousTime));
while (nextDate.getTime() < currentDate) {//if next date is in past try to find next date nearest to now
currentStart = nextDate;
nextDate = cronSequenceGenerator.next(nextDate);
}
if (currentStart == null) {
currentStart = nextDate;
}
log.trace("{}\n now={} frame={} currentStart={} lastStart={} cron={}",
task, currentDate, frame, currentStart, task.getCron());
sw.stop();
return currentStart.getTime();
}
示例3: assertWindowTZ
import org.springframework.scheduling.support.CronSequenceGenerator; //导入依赖的package包/类
private void assertWindowTZ(String tzname, String expression) throws ParseException {
ZoneId zone = ZoneId.of(tzname);
Cron s1 = new Cron(expression);
CronSequenceGenerator s2 = new CronSequenceGenerator(expression, TimeZone.getTimeZone(tzname));
ZonedDateTime date = Support.brt("2016-02-21 13:14:00").withZoneSameLocal(zone);
for (int i = 0; i < 100; i++) {
long dateMillis = date.toInstant().toEpochMilli();
ZonedDateTime next = s1.next(date);
Date expected = s2.next(new Date(dateMillis));
ZonedDateTime expectedNext = ZonedDateTime.ofInstant(Instant.ofEpochMilli(expected.getTime()), zone);
assertEquals(expectedNext, next);
date = next;
}
}
示例4: getCronExpression
import org.springframework.scheduling.support.CronSequenceGenerator; //导入依赖的package包/类
public CronSequenceGenerator getCronExpression(String cron) throws ParseException {
String[] splits = cron.split("\\s+");
if (splits.length < MINIMAL_CRON_SEGMENT_LENGTH && splits.length > MINIMAL_USER_DEFINED_CRON_SEGMENT_LENGTH) {
for (int i = splits.length; i < MINIMAL_CRON_SEGMENT_LENGTH; i++) {
switch (i) {
case DAY_OF_WEEK_FIELD: cron = String.format("%s ?", cron);
break;
default: cron = String.format("%s *", cron);
break;
}
}
}
try {
return new CronSequenceGenerator(cron);
} catch (Exception e) {
throw new ParseException(e.getMessage(), 0);
}
}
示例5: validate
import org.springframework.scheduling.support.CronSequenceGenerator; //导入依赖的package包/类
@Override
public List<String> validate() {
ArrayList<String> errors = new ArrayList<>();
ValidationUtils.notNull(errors, name, "Please provide the notifier a name");
ValidationUtils.isTrue(errors, (period != null) || (schedulingCronExpression != null), "Please provide the notifier a period or a schedulingCronExpression");
ValidationUtils.isTrue(errors, schedulingCronExpression == null || CronSequenceGenerator.isValidExpression(schedulingCronExpression), "Invalid cron expressions : " + schedulingCronExpression);
return errors;
}
示例6: CacheDefinition
import org.springframework.scheduling.support.CronSequenceGenerator; //导入依赖的package包/类
public CacheDefinition(Class<T> clz) {
this.clz = clz;
CacheEntity cacheEntity = clz.getAnnotation(CacheEntity.class);
this.cacheSize = cacheEntity.size();
this.persisterType = cacheEntity.persister().type();
if (persisterType.equals(PersisterType.NORMAL)) {
this.cronGenerator = new CronSequenceGenerator(
(String) AnnotationUtils.getDefaultValue(cacheEntity.persister(), "value"), TimeZone.getDefault());
} else {
this.cronGenerator = new CronSequenceGenerator(cacheEntity.persister().value(), TimeZone.getDefault());
}
validate(clz);
init(clz);
}
示例7: validate
import org.springframework.scheduling.support.CronSequenceGenerator; //导入依赖的package包/类
@Override
public void validate(Object value) throws ValidationException {
if (value != null) {
ServerInfoService serverInfoService = AppBeans.get(ServerInfoService.NAME);
Messages messages = AppBeans.get(Messages.NAME);
try {
new CronSequenceGenerator(value.toString(), serverInfoService.getTimeZone());
} catch (Exception e) {
throw new ValidationException(messages.getMessage(CronValidator.class, "validation.cronInvalid"));
}
}
}
示例8: cronExpressionIsValid
import org.springframework.scheduling.support.CronSequenceGenerator; //导入依赖的package包/类
private boolean cronExpressionIsValid(String cronExpression) {
try {
// Unix cron does not contain seconds but spring cron does
new CronSequenceGenerator("0 " + cronExpression);
return true;
} catch (Exception e) {
LOG.warn("Provided cron expression {} is invalid. Changes will not be applied", cronExpression);
return false;
}
}
示例9: deploy
import org.springframework.scheduling.support.CronSequenceGenerator; //导入依赖的package包/类
private void deploy(AgentDeploy deployment, Flow flow, ProjectVersion projectVersion) {
DeploymentStatus status = deployment.getDeploymentStatus();
if (!status.equals(DeploymentStatus.DISABLED) && !status.equals(DeploymentStatus.REQUEST_DISABLE)
&& !status.equals(DeploymentStatus.REQUEST_REMOVE)) {
try {
log.info("Deploying '{}' to '{}'", deployment.getName(), agent.getName());
deployResources(flow);
AgentProjectVersionFlowDeployment agentProjectVersionFlowDeployment = new AgentProjectVersionFlowDeployment(deployment, flow,
projectVersion);
doComponentDeploymentEvent(agentProjectVersionFlowDeployment,
(l, f, s, c) -> l.onDeploy(agent, agentProjectVersionFlowDeployment, s, c));
if (deployment.asStartType() == StartType.SCHEDULED_CRON) {
String cron = deployment.getStartExpression();
log.info("Scheduling '{}' on '{}' with a cron expression of '{}' The next run time should be at: {}",
new Object[] { flow.getName(), agent.getName(), cron, new CronSequenceGenerator(cron).next(new Date()) });
ScheduledFuture<?> future = this.flowExecutionScheduler
.schedule(new FlowRunner("metl cron", agentProjectVersionFlowDeployment), new CronTrigger(cron));
scheduledDeployments.put(deployment, future);
}
deployment.setStatus(DeploymentStatus.ENABLED.name());
deployment.setMessage("");
deployed.add(agentProjectVersionFlowDeployment);
log.info("Flow '{}' has been deployed", deployment.getName());
} catch (Exception e) {
log.warn("Failed to start '{}'", deployment.getName(), e);
deployment.setStatus(DeploymentStatus.ERROR.name());
deployment.setMessage(ExceptionUtils.getRootCauseMessage(e));
}
operationsService.save(deployment);
}
}
示例10: isTrigger
import org.springframework.scheduling.support.CronSequenceGenerator; //导入依赖的package包/类
public boolean isTrigger(String cron, String timeZone, long monitorUpdateRate) {
try {
CronSequenceGenerator cronExpression = getCronExpression(cron);
DateTime currentTime = dateTimeUtils.getCurrentDate(timeZone);
Date nextTime = cronExpression.next(currentTime.toDate());
DateTime nextDateTime = dateTimeUtils.getDateTime(nextTime, timeZone).minus(monitorUpdateRate);
long interval = nextDateTime.toDate().getTime() - currentTime.toDate().getTime();
return interval > 0 && interval < monitorUpdateRate;
} catch (ParseException e) {
LOGGER.warn("Invalid cron expression, {}", e.getMessage());
return false;
}
}
示例11: test
import org.springframework.scheduling.support.CronSequenceGenerator; //导入依赖的package包/类
@Test
public void test() throws ParseException {
if (this.exception.isPresent()) {
thrown.expect(this.exception.get());
}
CronSequenceGenerator cronExpression = underTest.getCronExpression(this.input);
if (!this.exception.isPresent()) {
Assert.assertEquals(String.format("CronSequenceGenerator: %s", this.expected.orElse("This should be null")), cronExpression.toString());
}
}
示例12: toCron
import org.springframework.scheduling.support.CronSequenceGenerator; //导入依赖的package包/类
/**
* 得到 {@link CronSequenceGenerator}
*/
public CronSequenceGenerator toCron () {
return new CronSequenceGenerator( this.toCronString() );
}
示例13: checkCronAndSetStartDate
import org.springframework.scheduling.support.CronSequenceGenerator; //导入依赖的package包/类
private void checkCronAndSetStartDate(String schedule) {
Assert.hasText(schedule, "parameters.schedule is empty or null");
Assert.isTrue(CronSequenceGenerator.isValidExpression(schedule), "Cron expression is not valid: " + schedule);
updateNextStart(calculateNextStart(schedule));
}
示例14: calculateNextStart
import org.springframework.scheduling.support.CronSequenceGenerator; //导入依赖的package包/类
private LocalDateTime calculateNextStart(String schedule) {
Date next = new CronSequenceGenerator(schedule).next(new Date());
return LocalDateTime.ofInstant(next.toInstant(), ZoneId.systemDefault());
}
示例15: validateCron
import org.springframework.scheduling.support.CronSequenceGenerator; //导入依赖的package包/类
/**
* @param cron cron expression to validate.
* @throws IllegalArgumentException if cron expression is invalid
* @see CronSequenceGenerator
*/
public static void validateCron(String cron) {
//Internally, we use the org.springframework.scheduling.support.CronTrigger which has a different syntax than the official crontab syntax.
//Therefore we use the internal validation of CronTrigger
new CronSequenceGenerator(cron);
}