Example usage for javax.ejb Timer getInfo

List of usage examples for javax.ejb Timer getInfo

Introduction

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

Prototype

public Serializable getInfo()
        throws java.lang.IllegalStateException, javax.ejb.NoSuchObjectLocalException, javax.ejb.EJBException;

Source Link

Document

Get the information associated with the timer at the time of creation.

Usage

From source file:Employee.java

  public void doAction() {
  String item = "item 1";

  for (Object obj : timerService.getTimers()) {
    javax.ejb.Timer timer = (javax.ejb.Timer) obj;
    String scheduled = (String) timer.getInfo();
    if (scheduled.equals(item)) {
      timer.cancel();//from w w  w. ja va2 s.com
    }
  }

  timerService.createTimer(new Date(System.currentTimeMillis() + 1000), item);

}

From source file:Employee.java

  @Timeout
public void maintenance(javax.ejb.Timer timer) {
  System.out.println("TIMEOUT METHOD CALLED");
  String scheduled = (String) timer.getInfo();
  System.out.println(scheduled);//  w  w w .j  av  a  2s .  c  om
}

From source file:gov.nih.nci.firebird.service.periodic.DailyJobServiceBean.java

private boolean isDailyJobServiceTimer(Timer timer) {
    return DAILY_JOB_SERVICE_BEAN_TIMER_MARKER.equals(timer.getInfo());
}

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

/**
 * {@inheritDoc}/*from  ww w  .j  a  va2 s  .c om*/
 */
public void cancelTimers(String timerInfo) {
    Collection<Timer> timers = this.timerService.getTimers();
    for (Timer timer : timers) {
        if (timer.getInfo() != null) {
            if (timer.getInfo().equals(timerInfo)) {
                timer.cancel();
                LOG.debug("cancel timer: " + timerInfo);
            }
        }
    }
}

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

public void cancelTimers() {

    Collection<Timer> timers = this.timerService.getTimers();
    for (Timer timer : timers) {
        if (timer.getInfo() != null) {
            if (timer.getInfo().equals(TIMER_ID)) {
                timer.cancel();/*  w  ww.j ava2  s .  co  m*/
                LOG.debug("cancel timer: " + TIMER_ID);
            }
        }
    }
}

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

/**
 * {@inheritDoc}//  www  .  ja  va  2s .com
 */
@Timeout
public void timeOut(Timer timer) {

    String timerInfo = (String) timer.getInfo();
    if (null == timerInfo) {
        LOG.error("no timer info ?? cancel timer");
        timer.cancel();
        return;
    }

    LOG.debug("scheduler timeout for: " + timerInfo);
    if (timerInfo.equals(TrustServiceConstants.CLOCK_DRIFT_TIMER)) {
        handleClockDriftTimeout();
    } else {
        handleTrustPointTimeout(timerInfo);
    }
}

From source file:h2backup.BackupTimerService.java

@PostConstruct
public void init() {
    if (!enabled) {
        log.info("H2 database backup is disabled");
        return;//w w  w.j a  v  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:be.fedict.eid.dss.model.bean.DocumentServiceBean.java

/**
 * {@inheritDoc}/*from  w  ww  .  ja  v a2  s.  c  o m*/
 */
@Timeout
public void timeOut(Timer timer) {

    String timerInfo = (String) timer.getInfo();
    LOG.debug("timeout: " + timerInfo);
    if (null == timerInfo) {
        LOG.error("no timer info ?? cancel timer");
        timer.cancel();
        return;
    }

    if (timerInfo.equals(TIMER_ID)) {
        cleanup();
        LOG.debug("Next cleanup: " + timer.getNextTimeout());
    }
}

From source file:de.fatalix.bookery.bl.background.importer.CalibriImporter.java

@Override
public void executeJob(Timer timer) {
    logger.debug("Starting batch job...");
    DateTimeZone.setDefault(DateTimeZone.UTC);
    BatchJobConfiguration jobConfig = (BatchJobConfiguration) timer.getInfo();
    Gson gson = new Gson();
    CalibriImporterConfiguration config = gson.fromJson(jobConfig.getConfigurationXML(),
            CalibriImporterConfiguration.class);

    File importFolder = new File(config.getImportFolder());
    if (importFolder.isDirectory()) {
        File[] zipFiles = importFolder.listFiles(new FilenameFilter() {

            @Override/* w  ww.j av a  2 s . com*/
            public boolean accept(File dir, String name) {
                return name.endsWith(".zip");
            }
        });
        for (File zipFile : zipFiles) {
            try {
                processArchive(zipFile.toPath(), config.getBatchSize());
                logger.info("Processed file " + zipFile.getName());
            } catch (IOException ex) {
                logger.error("Cannot process " + zipFile.getName(), ex);

            }
        }
    } else {
        logger.error("Import folder: " + importFolder.getAbsolutePath() + " cannot be read!");
    }
}

From source file:com.hiperium.bo.control.impl.TaskBOImpl.java

/**
 * {@inheritDoc}//from  w ww .  j  a va  2  s  .co m
 */
@Timeout
public void excecute(Timer timer) {
    Long taskId = (Long) timer.getInfo();
    this.log.debug("excecuteTask - START: task ID = " + taskId);
    try {
        Task task = super.getDaoFactory().getTaskDAO().findById(taskId, false, true);
        if (task != null && task.getActive()) {
            List<Device> deviceList = super.getDaoFactory().getDeviceDAO().findByTaskId(taskId);
            for (Device device : deviceList) {
                if (task.getAction().equals(EnumDeviceAction.ACTIVATE)
                        || task.getAction().equals(EnumDeviceAction.LOCK)) {
                    device.setActive(true);
                } else if (task.getAction().equals(EnumDeviceAction.DEACTIVATE)
                        || task.getAction().equals(EnumDeviceAction.UNLOCK)) {
                    device.setActive(false);
                }
                super.getDaoFactory().getDeviceDAO().update(device);

                // TODO: SEND TO THE HIPERIUM CLOUD
                //               DeviceGsonConverter jsonConverter = new DeviceGsonConverter();
                //               Long homeId = this.zoneRepositoryLocal.findHomeIdByZoneId(device.getZoneId(), 
                //                     EnumPlatformSessionID.INSTANCE.getSessionId());
            }

            //CREATE A NEW TIMER SERVICE FOR FREQUENCY MORE THAN DAILY
            if (EnumFrequency.WEEKLY.equals(task.getFrequency())
                    || EnumFrequency.MONTHLY.equals(task.getFrequency())
                    || EnumFrequency.QUARTERLY.equals(task.getFrequency())
                    || EnumFrequency.SEMIANNUAL.equals(task.getFrequency())
                    || EnumFrequency.ANNUAL.equals(task.getFrequency())) {
                Calendar calendar = Calendar.getInstance();
                calendar.setTime(new Date());
                switch (task.getFrequency()) {
                case WEEKLY:
                    this.log.debug("excecuteTask - WEEKLY");
                    calendar.add(Calendar.DAY_OF_MONTH, 7);
                    break;
                case MONTHLY:
                    this.log.debug("excecuteTask - MONTHLY");
                    calendar.add(Calendar.MONTH, 1);
                    break;
                case QUARTERLY:
                    this.log.debug("excecuteTask - QUARTERLY");
                    calendar.add(Calendar.MONTH, 3);
                    break;
                case SEMIANNUAL:
                    this.log.debug("excecuteTask - SEMIANNUAL");
                    calendar.add(Calendar.MONTH, 6);
                    break;
                case ANNUAL:
                    this.log.debug("excecuteTask - ANNUAL");
                    calendar.add(Calendar.YEAR, 1);
                    break;
                default:
                    break;
                }
                // We recreate the task with the new manipulated date time.
                this.timerService.createSingleActionTimer(calendar.getTime(),
                        new TimerConfig(task.getId(), true));
            }
        }
    } catch (Exception e) {
        this.log.error("Error: " + e.getMessage());
    }
    timer.cancel();
    this.log.debug("excecuteTask - END");
}