Example usage for javax.ejb TimerConfig setInfo

List of usage examples for javax.ejb TimerConfig setInfo

Introduction

In this page you can find the example usage for javax.ejb TimerConfig setInfo.

Prototype

public void setInfo(Serializable i) 

Source Link

Document

Set the info object made available to timer callbacks.

Usage

From source file:be.fedict.trust.service.bean.SchedulingServiceBean.java

/**
 * {@inheritDoc}//  w  ww. j  av  a 2 s  .  c o m
 */
public void startTimerNow(TrustPointEntity trustPoint) {

    TimerConfig timerConfig = new TimerConfig();
    timerConfig.setInfo(trustPoint.getName());
    timerConfig.setPersistent(false);

    Timer timer = this.timerService.createSingleActionTimer(1000 * 10, timerConfig);

    LOG.debug("created single action timer for trustpoint " + trustPoint.getName() + " at "
            + timer.getNextTimeout().toString());
}

From source file:h2backup.BackupTimerService.java

@PostConstruct
public void init() {
    if (!enabled) {
        log.info("H2 database backup is disabled");
        return;//from ww w  .  java  2s.co  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.trust.service.bean.SchedulingServiceBean.java

/**
 * {@inheritDoc}//  w w  w.j  a  v  a2s .  c  o m
 */
public void startTimer(ClockDriftConfigEntity clockDriftConfig) throws InvalidCronExpressionException {
    LOG.debug("start timer for clock drift detection");

    if (null == clockDriftConfig.getCronSchedule() || clockDriftConfig.getCronSchedule().isEmpty()) {
        LOG.debug("no interval set for clock drift, ignoring...");
        return;
    }

    // remove old timers
    cancelTimers(TrustServiceConstants.CLOCK_DRIFT_TIMER);

    TimerConfig timerConfig = new TimerConfig();
    timerConfig.setInfo(TrustServiceConstants.CLOCK_DRIFT_TIMER);
    timerConfig.setPersistent(false);

    ScheduleExpression schedule = getScheduleExpression(clockDriftConfig.getCronSchedule());

    Timer timer;
    try {
        timer = this.timerService.createCalendarTimer(schedule, timerConfig);
    } catch (Exception e) {
        LOG.error("Exception while creating timer for clock drift: " + e.getMessage(), e);
        throw new InvalidCronExpressionException(e);
    }

    LOG.debug("created timer for clock drift at " + timer.getNextTimeout().toString());
    clockDriftConfig.setFireDate(timer.getNextTimeout());
}

From source file:be.fedict.trust.service.bean.SchedulingServiceBean.java

/**
 * {@inheritDoc}/*from   w ww  .ja  v  a2 s . c  o  m*/
 */
public void startTimer(TrustPointEntity trustPoint) throws InvalidCronExpressionException {

    LOG.debug("start timer for " + trustPoint.getName());

    if (null == trustPoint.getCrlRefreshCronSchedule() || trustPoint.getCrlRefreshCronSchedule().isEmpty()) {
        LOG.debug("no CRL refresh set for trust point " + trustPoint.getName() + " ignoring...");
        return;
    }

    // remove old timers
    cancelTimers(trustPoint.getName());

    TimerConfig timerConfig = new TimerConfig();
    timerConfig.setInfo(trustPoint.getName());
    timerConfig.setPersistent(false);

    ScheduleExpression schedule = getScheduleExpression(trustPoint.getCrlRefreshCronSchedule());

    Timer timer;
    try {
        timer = this.timerService.createCalendarTimer(schedule, timerConfig);
    } catch (Exception e) {
        LOG.error("Exception while creating timer for clock drift: " + e.getMessage(), e);
        throw new InvalidCronExpressionException(e);
    }

    LOG.debug("created timer for trustpoint " + trustPoint.getName() + " at "
            + timer.getNextTimeout().toString());
    trustPoint.setFireDate(timer.getNextTimeout());
}

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

/**
 * {@inheritDoc}//from  w w w . j a v  a 2s .c  o m
 */
public void startTimer(String cronSchedule) throws InvalidCronExpressionException {

    LOG.debug("start document service's cleanup task timer");

    if (null == cronSchedule || cronSchedule.isEmpty()) {
        // TODO: error message sufficient? or explode here?...
        LOG.error("No interval set for document service cleanup task!");
        return;
    }

    // remove old timers
    cancelTimers();

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

    ScheduleExpression schedule = getScheduleExpression(cronSchedule);

    Timer timer;
    try {
        timer = this.timerService.createCalendarTimer(schedule, timerConfig);
    } catch (Exception e) {
        LOG.error("Exception while creating timer for document service " + "cleanup task: " + e.getMessage(),
                e);
        throw new InvalidCronExpressionException(e);
    }

    LOG.debug("created timer for document service cleanup task: next=" + timer.getNextTimeout().toString());
}