Example usage for javax.ejb TimerService getTimers

List of usage examples for javax.ejb TimerService getTimers

Introduction

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

Prototype

public Collection<Timer> getTimers() throws java.lang.IllegalStateException, javax.ejb.EJBException;

Source Link

Document

Returns all active timers associated with this bean.

Usage

From source file:org.jbpm.scheduler.ejbtimer.TimerServiceBean.java

public void cancelTimersByName(String timerName, Token token) {

    // TODO make the scanning of timers for cancellation optional by only deleting the timerjobs in the db.
    // of course, the corresponding ejb timer notifications have to be ignored. 

    log.debug("cancelling timers with name " + timerName + " from the ejb timer service");

    TimerService timerService = sessionContext.getTimerService();
    Iterator iter = timerService.getTimers().iterator();
    while (iter.hasNext()) {
        javax.ejb.Timer ejbTimer = (javax.ejb.Timer) iter.next();
        if (ejbTimer.getInfo() instanceof TimerInfo) {
            TimerInfo timerInfo = (TimerInfo) ejbTimer.getInfo();
            if (timerInfo.matchesName(timerName, token)) {
                ejbTimer.cancel();/*from  w ww .  j a v a  2s.c o m*/
            }
        }
    }
}

From source file:org.jbpm.scheduler.ejbtimer.TimerServiceBean.java

public void deleteTimersForProcessInstance(ProcessInstance processInstance) {

    // TODO make the scanning of timers for cancellation optional by only deleting the timerjobs in the db.
    // of course, the corresponding ejb timer notifications have to be ignored. 

    log.debug("deleting timers for process instance " + processInstance + " from the ejb timer service");

    TimerService timerService = sessionContext.getTimerService();
    Iterator iter = timerService.getTimers().iterator();
    while (iter.hasNext()) {
        javax.ejb.Timer ejbTimer = (javax.ejb.Timer) iter.next();
        if (ejbTimer.getInfo() instanceof TimerInfo) {
            TimerInfo timerInfo = (TimerInfo) ejbTimer.getInfo();
            if (timerInfo.matchesProcessInstance(processInstance)) {
                ejbTimer.cancel();// ww w .ja  v a  2  s.  co  m
            }
        }
    }
}