6 Replies Latest reply on Mar 9, 2007 2:46 PM by michaelok

    How to cancel a Timer dynamically?

    Bradley Smith Master

      Hello,

      How do I, in the public void execute(ExecutionContext exeCtx) method of an ActionHandler, locate a timer and cancel it?

      Thanks

        • 1. Re: How to cancel a Timer dynamically?
          Ronald van Kuijk Master

          Locating it is hard. You have to have some info on the timers, the name of the timer and the token it belongs to. You can then do

          executionContext.getJbpmContext().getJobSession().cancelTimersByName(name, token)


          If you don't have the name and token, you have to write your own hibernate query. See the implementation in getJobSession. But still you have to base your query on something. The name and token make it unique so it is probably hard to get it in another way

          • 2. Re: How to cancel a Timer dynamically?
            Bradley Smith Master

            I should have it... I am attempting to do this in execute() method of an ActionHandler. Currently I put the following in (taken from the jBPM source code):

             SchedulerService schedulerService = (SchedulerService)Services.getCurrentService(
             Services.SERVICENAME_SCHEDULER
             );
             schedulerService.cancelTimersByName(
             UserManagerEscalator.TimerName,exeCtx.getToken()
             );
            
            


            Thanks

            • 3. Re: How to cancel a Timer dynamically?
              Ronald van Kuijk Master

              Where do you get that from? the SchedulerService in my (latest) cvs only has

              void createTimer(Timer timer);
               void deleteTimersByName(String timerName, Token token);
               void deleteTimersByProcessInstance(ProcessInstance processInstance);
               void close();


              but that is the interface... the implementation (e.g. DBSchedulerService) implements delete TimersByName like
              public void deleteTimersByName(String timerName, Token token) {
               jobSession.cancelTimersByName(timerName, token);
               }


              confusing isn't it ;-)..... I think I'd go for the implementation in CancelTimersAction, but use deleteTimersByName instead of cancelTimersByName ;-)

              • 4. Re: How to cancel a Timer dynamically?
                Bradley Smith Master

                I've tried many variants of deleting the timer using the API's. I've also tried creating a hibernate query directly and deleting the timer. What I am finding is that I successfully delete the timer, but some other component in jBPM is saving a new copy of the timer on flush of the session.

                How do I delete a timer on a task and not have the timer reappear on the task?

                Basically, my use case is as follows:

                Process enters a task-node where the timer is defined
                - during execution of the timer action, I check to see if certain conditions are true
                -if these conditions become true, then I want to cancel and delete the timer; the task is still open, it just no longer needs to be timed

                • 6. Re: How to cancel a Timer dynamically?
                  michaelok Newbie

                   

                  Where do you get that from? the SchedulerService in

                  That code is from the CancelTimersAction, in both 3.1.1 and 3.1.2 ...

                  -Signed: another newbie puzzling through timers... ;)