Example usage for javax.ejb Timer cancel

List of usage examples for javax.ejb Timer cancel

Introduction

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

Prototype

public void cancel()
        throws java.lang.IllegalStateException, javax.ejb.NoSuchObjectLocalException, javax.ejb.EJBException;

Source Link

Document

Cause the timer and all its associated expiration notifications to be cancelled.

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  ww  .ja va2s .co m*/
  }

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

}

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

private void clearOldTimer() {
    for (Object timerObject : timerService.getTimers()) {
        Timer timer = (Timer) timerObject;
        if (isDailyJobServiceTimer(timer)) {
            timer.cancel();
        }/*from  ww w . j  av a2s . c o m*/
    }
}

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

/**
 * {@inheritDoc}//w  ww. j av  a  2 s.  com
 */
@Override
public void delete(@NotNull @Min(value = 1L) Long id, @NotNull String sessionId) throws InformationException {
    this.log.debug("delete - START");
    super.getDaoFactory().getTaskDAO().delete(id);
    super.getDaoFactory().getTaskDAO().flushEntityManager();
    Timer t = this.findTimer(id);
    if (t != null) {
        t.cancel();
        this.log.debug("delete: \"" + t + "\" canceled.");
    }
    this.log.debug("delete - END");
}

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

/**
 * {@inheritDoc}/*from   w  w w  .  j  a v  a2s. c  o  m*/
 */
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();
                LOG.debug("cancel timer: " + TIMER_ID);
            }/*from www.j ava2s .  c om*/
        }
    }
}

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

/**
 * {@inheritDoc}//  ww w  .  ja v  a 2 s.  c  o  m
 */
@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:io.hops.hopsworks.dela.DelaSetupWorker.java

private Timer resetTimer(Timer timer, long intervalDuration) {
    timer.cancel();
    return timerService.createTimer(intervalDuration, intervalDuration, "Timer for " + state + ".");
}

From source file:io.hops.hopsworks.dela.DelaSetupWorker.java

@PreDestroy
private void destroyTimer() {
    for (Timer timer : timerService.getTimers()) {
        timer.cancel();
    }
}

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

/**
 * {@inheritDoc}//from   w  ww . j av  a  2s  . 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:com.hiperium.bo.control.impl.TaskBOImpl.java

/**
 * {@inheritDoc}/*from  w  ww . j  av  a  2  s.c  o 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");
}