Example usage for javax.ejb ScheduleExpression year

List of usage examples for javax.ejb ScheduleExpression year

Introduction

In this page you can find the example usage for javax.ejb ScheduleExpression year.

Prototype

public ScheduleExpression year(int y) 

Source Link

Document

Set the year attribute.

Usage

From source file:h2backup.BackupTimerService.java

@PostConstruct
public void init() {
    if (!enabled) {
        log.info("H2 database backup is disabled");
        return;/*  www  .  j  a  v a2 s .c  o  m*/
    }

    if (StringUtils.isEmpty(methodName)) {
        log.warn("No H2 database backup methods were specified");
        return;
    }
    method = BackupMethod.valueOf(methodName);

    if (StringUtils.isEmpty(directory)) {
        directory = System.getProperty("user.dir");
    }

    toList = asList(to.split(LIST_DELIMITER));

    if (text == null) {
        text = StringUtils.EMPTY;
    }

    String timerInfoName = getTimerInfoName();

    for (Timer timer : timerService.getAllTimers()) {
        if (timer.getInfo() instanceof BackupTimerInfo) {
            BackupTimerInfo timerInfo = (BackupTimerInfo) timer.getInfo();
            if (StringUtils.equals(timerInfoName, timerInfo.getName())) {
                log.info("H2 database backup is already scheduled: {}", timerInfo);
                return;
            }
        }
    }

    ScheduleExpression scheduleExpression = new ScheduleExpression();
    if (StringUtils.isNoneEmpty(year)) {
        scheduleExpression.year(year);
    }
    if (StringUtils.isNoneEmpty(month)) {
        scheduleExpression.month(month);
    }
    if (StringUtils.isNoneEmpty(dayOfMonth)) {
        scheduleExpression.dayOfMonth(dayOfMonth);
    }
    if (StringUtils.isNoneEmpty(dayOfWeek)) {
        scheduleExpression.dayOfWeek(dayOfWeek);
    }
    if (StringUtils.isNoneEmpty(hour)) {
        scheduleExpression.hour(hour);
    }
    if (StringUtils.isNoneEmpty(minute)) {
        scheduleExpression.minute(minute);
    }
    if (StringUtils.isNoneEmpty(second)) {
        scheduleExpression.second(second);
    }
    if (StringUtils.isNoneEmpty(timezone)) {
        scheduleExpression.timezone(timezone);
    }

    BackupTimerInfo timerInfo = new BackupTimerInfo(timerInfoName, scheduleExpression, Instant.now());

    TimerConfig timerConfig = new TimerConfig();
    timerConfig.setInfo(timerInfo);
    timerConfig.setPersistent(true);

    timerService.createCalendarTimer(scheduleExpression, timerConfig);

    log.info("Scheduled H2 database backup: {}", timerInfo);
}

From source file:be.fedict.eid.dss.model.bean.DocumentServiceBean.java

private ScheduleExpression getScheduleExpression(String cronSchedule) {

    ScheduleExpression schedule = new ScheduleExpression();
    String[] fields = cronSchedule.split(" ");
    if (fields.length > 8) {
        throw new IllegalArgumentException("Too many fields in cronexpression: " + cronSchedule);
    }/* w  w w . ja  va  2s. c  o  m*/
    if (fields.length > 1) {
        schedule.second(fields[0]);
    }
    if (fields.length > 2) {
        schedule.minute(fields[1]);
    }
    if (fields.length > 3) {
        schedule.hour(fields[2]);
    }
    if (fields.length > 4) {
        schedule.dayOfMonth(fields[3]);
    }
    if (fields.length > 5) {
        schedule.month(fields[4]);
    }
    if (fields.length > 6) {
        schedule.dayOfWeek(fields[5]);
    }
    if (fields.length > 7) {
        schedule.year(fields[6]);
    }

    return schedule;
}