Example usage for javax.ejb TimerConfig TimerConfig

List of usage examples for javax.ejb TimerConfig TimerConfig

Introduction

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

Prototype

public TimerConfig() 

Source Link

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);/*from www . j a va2 s. co m*/

    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();//w  ww.j a v a 2  s .c  o 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);/*from w  w  w . j av a2s . c o  m*/

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

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

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:h2backup.BackupTimerService.java

@PostConstruct
public void init() {
    if (!enabled) {
        log.info("H2 database backup is disabled");
        return;//from  w  w  w .  j  av  a2  s .com
    }

    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  .  ja v  a 2  s . com*/
 */
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  ww  w.java  2s . co  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());
}

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

/**
 * {@inheritDoc}/*from  w w  w .j  a v  a2s . c  om*/
 */
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:org.niord.core.aton.AtonDefaultsService.java

/** Called upon application startup */
@PostConstruct/*  w ww .  j a  v a  2  s  .c o m*/
public void init() {
    // In order not to stall webapp deployment, wait 3 seconds before initializing the defaults
    timerService.createSingleActionTimer(3000, new TimerConfig());
}

From source file:org.niord.core.message.MessageLuceneIndex.java

/**
 * Initialize the index/*  w  w w.ja  v a2 s  .  co  m*/
 */
@PostConstruct
private void init() {
    // Create the lucene index directory
    if (!Files.exists(indexFolder)) {
        try {
            Files.createDirectories(indexFolder);
        } catch (IOException e) {
            log.error("Error creating index dir " + indexFolder, e);
        }
    }

    // Check if we need to delete the old index on start-up
    if (deleteOnStartup) {
        try {
            deleteIndex();
        } catch (IOException e) {
            log.error("Failed re-creating the index on startup", e);
        }
    }

    // Wait 5 seconds before initializing the message index
    timerService.createSingleActionTimer(5000, new TimerConfig());
}