Example usage for javax.ejb TimerConfig setPersistent

List of usage examples for javax.ejb TimerConfig setPersistent

Introduction

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

Prototype

public void setPersistent(boolean p) 

Source Link

Document

Specify whether the timer is persistent.

Usage

From source file:eu.agilejava.snoop.scan.SnoopClient.java

public void register(final String clientId) {
    sendMessage(REGISTER_ENDPOINT, clientId);

    ScheduleExpression schedule = new ScheduleExpression();
    schedule.second("*/10").minute("*").hour("*").start(Calendar.getInstance().getTime());

    TimerConfig config = new TimerConfig();
    config.setPersistent(false);

    Timer timer = timerService.createCalendarTimer(schedule, config);

    LOGGER.config(() -> timer.getSchedule().toString());
}

From source file:eu.agilejava.snoop.eureka.scan.EurekaClient.java

@PostConstruct
private void init() {

    LOGGER.config("Checking if snoop eureka is enabled");
    LOGGER.config(() -> "YES: " + SnoopEurekaExtensionHelper.isEurekaEnabled());

    if (SnoopEurekaExtensionHelper.isEurekaEnabled()) {

        readProperties();//from  w  ww  .  j  a  v a  2  s  . co  m

        EurekaConfig eurekaConfig = new EurekaConfig();
        eurekaConfig.setHostName(applicationName);
        eurekaConfig.setApp(applicationName);
        eurekaConfig.setIpAddr("localhost");
        eurekaConfig.setPort(8080);
        eurekaConfig.setStatus("UP");
        eurekaConfig.setHomePageUrl(applicationHome);

        Entity<InstanceConfig> entity = Entity.entity(new InstanceConfig(eurekaConfig),
                MediaType.APPLICATION_JSON);

        Response response = ClientBuilder.newClient().target(serviceUrl + "apps/" + applicationName).request()
                .post(entity);

        LOGGER.config(() -> "POST resulted in: " + response.getStatus() + ", " + response.getEntity());

        ScheduleExpression schedule = new ScheduleExpression();
        schedule.second("*/10").minute("*").hour("*").start(Calendar.getInstance().getTime());

        TimerConfig config = new TimerConfig();
        config.setPersistent(false);

        Timer timer = timerService.createCalendarTimer(schedule, config);

        LOGGER.config(() -> timer.getSchedule().toString());

    } else {
        LOGGER.config("Snoop Eureka is not enabled. Use @EnableEurekaClient!");
    }
}

From source file:eu.agilejava.snoop.scan.SnoopRegistrationClient.java

public void register(final String clientId) {

    sendMessage(REGISTER_ENDPOINT, applicationConfig.toJSON());

    ScheduleExpression schedule = new ScheduleExpression();
    schedule.second("*/10").minute("*").hour("*").start(Calendar.getInstance().getTime());

    TimerConfig config = new TimerConfig();
    config.setPersistent(false);

    Timer timer = timerService.createCalendarTimer(schedule, config);

    LOGGER.config(() -> timer.getSchedule().toString());
}

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  ava 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}/*from   www .j a  v  a  2 s .  com*/
 */
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:be.fedict.trust.service.bean.SchedulingServiceBean.java

/**
 * {@inheritDoc}//from w  ww .j a  v  a  2 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 ww .  j  ava2  s . com*/
 */
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());
}

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

/**
 * {@inheritDoc}/*from   ww  w.ja va 2s  . 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());
}