2 Replies Latest reply on Jul 6, 2007 10:49 AM by supterlobster

    flexible timers

    supterlobster

      What it takes to have more flexible timers to do something beyond the simple repeat times and interval. Say, I want the timer execution interval changed with retry times. With current enterprise approach, the only thing I can see is to dynamically cancel and create the new timers. Can we do this easily?

      Justin

        • 1. Re: flexible timers
          kukeltje

          In the enterprise version EJB Timers are used, so if you want flexibility beyond cancelling and creating go to the ejb spec designers ;-)

          btw, what is difficult about cancelling and creating new timers?

          • 2. Re: flexible timers
            supterlobster

            The creation of a new timer is not so obvious from the the jbpm api:

            Here is the code:

            protected Timer createTimer(ExecutionContext executionContext) {
             Timer timer = new Timer(executionContext.getToken());
             timer.setName(timerName);
             timer.setRepeat(repeat);
             if (dueDate!=null) {
             Duration duration = new Duration(dueDate);
             Date dueDateDate = businessCalendar.add( new Date(), duration );
             timer.setDueDate(dueDateDate);
             }
             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)
             ) {
             GraphElement graphElement = getEvent().getGraphElement();
             try {
             executionContext.setTimer(timer);
             // fire the create timer event on the same graph element
             graphElement.fireEvent("timer-create", executionContext);
             } finally {
             executionContext.setTimer(null);
             }
             }
            
             return timer;
             }


            So what I did instead is reuse the timer created by the system and change the dueDate of my preference. Seems worked to some extent. But I am not sure it is the right way to do. Under heavy volumn, TimerServiceBean can get runtime exception because of treecache errors. And some timers just hang in the timers table and been ignored. I will try to limit the pool size of the session bean to see if make any difference.

            Anyway, I think the flexible timers should be configurable from the processdefination and some interface to calculate the dueDate provided for that purpose. Right now, I have to create spring bean for this to happen.

            Justin