• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java CronSequenceGenerator类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;
    }
}
 
开发者ID:farchanjo,项目名称:webcron,代码行数:21,代码来源:QuartzService.java


示例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();
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:23,代码来源:Scheduling.java


示例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;
    }
}
 
开发者ID:intelie,项目名称:omnicron,代码行数:19,代码来源:SpringCompatibilityTest.java


示例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);
        }

    }
 
开发者ID:hortonworks,项目名称:cloudbreak,代码行数:21,代码来源:DateUtils.java


示例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;
}
 
开发者ID:gilles-stragier,项目名称:quickmon,代码行数:9,代码来源:NotifierBuilder.java


示例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);
   }
 
开发者ID:ilivoo,项目名称:game,代码行数:15,代码来源:CacheDefinition.java


示例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"));
        }
    }
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:13,代码来源:CronValidator.java


示例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;
    }
}
 
开发者ID:SungardAS,项目名称:enhanced-snapshots,代码行数:11,代码来源:InitConfigurationServiceImpl.java


示例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);
    }
}
 
开发者ID:JumpMind,项目名称:metl,代码行数:38,代码来源:AgentRuntime.java


示例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;
    }
}
 
开发者ID:hortonworks,项目名称:cloudbreak,代码行数:14,代码来源:DateUtils.java


示例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());
    }
}
 
开发者ID:hortonworks,项目名称:cloudbreak,代码行数:11,代码来源:CronTest.java


示例12: toCron

import org.springframework.scheduling.support.CronSequenceGenerator; //导入依赖的package包/类
/**
 * 得到 {@link CronSequenceGenerator}
 */
public CronSequenceGenerator toCron () {
    return new CronSequenceGenerator( this.toCronString() );
}
 
开发者ID:yujunhao8831,项目名称:spring-boot-start-current,代码行数:7,代码来源:CustomizeCron.java


示例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));
}
 
开发者ID:codeabovelab,项目名称:haven-platform,代码行数:6,代码来源:ScheduledJobInstanceImpl.java


示例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());
}
 
开发者ID:codeabovelab,项目名称:haven-platform,代码行数:5,代码来源:ScheduledJobInstanceImpl.java


示例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);
}
 
开发者ID:otto-de,项目名称:edison-microservice,代码行数:11,代码来源:DefaultJobDefinition.java



注:本文中的org.springframework.scheduling.support.CronSequenceGenerator类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java VMSupport类代码示例发布时间:2022-05-22
下一篇:
Java AnnotationExpr类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap