Example usage for javax.ejb ScheduleExpression hour

List of usage examples for javax.ejb ScheduleExpression hour

Introduction

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

Prototype

public ScheduleExpression hour(int h) 

Source Link

Document

Set the hour attribute.

Usage

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);
    }//from  ww  w.j  a va 2s .co 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;
}

From source file:h2backup.BackupTimerService.java

@PostConstruct
public void init() {
    if (!enabled) {
        log.info("H2 database backup is disabled");
        return;/*from   w  w w.  j av  a 2s  .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:pl.psnc.synat.wrdz.mdz.config.MdzConfiguration.java

/**
 * Reads the schedule definition from the given configuration subset. Handles the hour, minute, day of week, day of
 * month, and month values./*from   w  w w . j a v a2s .c  o m*/
 * 
 * @param config
 *            configuration subset
 * @return configured schedule object to be used with a timer
 */
private ScheduleExpression readSchedule(Configuration config) {
    ScheduleExpression expression = new ScheduleExpression();
    if (config.containsKey(SCHEDULE_HOUR)) {
        expression.hour(config.getString(SCHEDULE_HOUR));
    }
    if (config.containsKey(SCHEDULE_MINUTE)) {
        expression.minute(config.getString(SCHEDULE_MINUTE));
    }
    if (config.containsKey(SCHEDULE_DAY_OF_WEEK)) {
        expression.dayOfWeek(config.getString(SCHEDULE_DAY_OF_WEEK));
    }
    if (config.containsKey(SCHEDULE_DAY_OF_MONTH)) {
        expression.dayOfMonth(config.getString(SCHEDULE_DAY_OF_MONTH));
    }
    if (config.containsKey(SCHEDULE_MONTH)) {
        expression.month(config.getString(SCHEDULE_MONTH));
    }
    return expression;
}