Package org.jbpm.scheduler.exe

Examples of org.jbpm.scheduler.exe.Timer


   
    processInstance = saveAndReload(processInstance);

    Iterator timersIter = schedulerSession.findTimersByDueDate();
    assertTrue(timersIter.hasNext());
    Timer timer = (Timer) timersIter.next();
    assertEquals("ceiling-timer", timer.getName());
  }
View Full Code Here


    newTransaction();
   
    // fetch the original duedate
    Iterator timersIter = schedulerSession.findTimersByDueDate();
    assertTrue(timersIter.hasNext());
    Timer timer = (Timer) timersIter.next();
    assertFalse(timersIter.hasNext());
    long originalDueDate = timer.getDueDate().getTime();
   
    commitAndCloseSession();

    // the timer executor creates its own JbpmSession.
    assertEquals(0, counter);
    new SchedulerThread().executeTimers();
    assertEquals(1, counter);

    // begin another transaction
    beginSessionTransaction();

    // check if the timer has be re-scheduled because of the repeat.
    timersIter = schedulerSession.findTimersByDueDate();
    assertTrue(timersIter.hasNext());
    timer = (Timer) timersIter.next();
    assertFalse(timersIter.hasNext());
    // check that the timer was rescheduled with a duedate 1 second after the original duedate.
    assertEquals(originalDueDate+10000, timer.getDueDate().getTime());
  }
View Full Code Here

    }
    transitionName = actionElement.attributeValue("transition");
  }

  public void execute(ExecutionContext executionContext) throws Exception {
    Timer timer = createTimer(executionContext);
    SchedulerService schedulerService = (SchedulerService) Services.getCurrentService(Services.SERVICENAME_SCHEDULER);
    schedulerService.createTimer(timer);
  }
View Full Code Here

    SchedulerService schedulerService = (SchedulerService) Services.getCurrentService(Services.SERVICENAME_SCHEDULER);
    schedulerService.createTimer(timer);
  }

  protected Timer createTimer(ExecutionContext executionContext) {
    Timer timer = new Timer(executionContext.getToken());
    timer.setName(timerName);
    timer.setRepeat(repeat);
    Duration duration = new Duration(dueDate);
    Date dueDate = businessCalendar.add( new Date(), duration );
    timer.setDueDate(dueDate);
    timer.setAction(timerAction);
    timer.setTransitionName(transitionName);
    timer.setGraphElement(executionContext.getEventSource());
    timer.setTaskInstance(executionContext.getTaskInstance());
   
    // if this action was executed for a graph element
    if ( (getEvent()!=null)
         && (getEvent().getGraphElement()!=null)
       ) {
View Full Code Here

      log.debug("checking for timers");
      Iterator iter = schedulerSession.findTimersByDueDate();
      while( (iter.hasNext())
             && (isDueDateInPast)
           ) {
        Timer timer = (Timer) iter.next();
        log.debug("found timer "+timer);
       
        // if this timer is due
        if (timer.isDue()) {
          log.debug("executing timer '"+timer+"'");
           
          // execute
          timer.execute();
         
          // save the process instance
          jbpmContext.save(timer.getProcessInstance());
           
          // notify the listeners (e.g. the scheduler servlet)
          notifyListeners(timer);
           
          // if there was an exception, just save the timer
          if (timer.getException()!=null) {
            schedulerSession.saveTimer(timer);
           
          // if repeat is specified
          } else if (timer.getRepeat()!=null) {
            // update timer by adding the repeat duration
            Date dueDate = timer.getDueDate();
           
            // suppose that it took the timer runner thread a
            // very long time to execute the timers.
            // then the repeat action dueDate could already have passed.
            while (dueDate.getTime()<=System.currentTimeMillis()) {
              dueDate = businessCalendar
                    .add(dueDate,
                      new Duration(timer.getRepeat()));
            }
            timer.setDueDate( dueDate );
            // save the updated timer in the database
            log.debug("saving updated timer for repetition '"+timer+"' in '"+(dueDate.getTime()-System.currentTimeMillis())+"' millis");
            schedulerSession.saveTimer(timer);
           
          } else {
            // delete this timer
            log.debug("deleting timer '"+timer+"'");
            schedulerSession.deleteTimer(timer);
          }

        } else { // this is the first timer that is not yet due
          isDueDateInPast = false;
          millisTillNextTimerIsDue = timer.getDueDate().getTime() - System.currentTimeMillis();
        }
      }
     
    } finally {
      jbpmContext.close();
View Full Code Here

TOP

Related Classes of org.jbpm.scheduler.exe.Timer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.