2 Replies Latest reply on Jul 19, 2011 12:31 AM by hrushikesh.chidley

    How to cancel Timer Event

    hrushikesh.chidley

      Hi,

      I am a newbie to jBPM and recently started working with jBPM v5.1.

       

      I want to use the timer event in the process flow. My requirement is something like this -

      - I want to initiate a process and then start the timeout for that process using timer task

      - If the process finishes first and gives me result before the timer expires then I want to cancel the timer event.

      - If in case the process does not complete and timer expired first, then I want to stop the process and raise a exception.

       

      I am able to sort out almost every part of this requirement using jBPM 5.1 but the 'cancelling of timer part'.

      Could anyone please let me know how can I cancel a timer event in the jBPM process?

       

      Thank you for help.

        • 1. Re: How to cancel Timer Event
          melc

          Hello,

          One simple approach could be to use a parameter as a flag (i.e. boolean timeout ) within your process and then simply raise it or not when completing the logic of your process (i.e. right before exiting) or after the timer node. Then at a gateway check the flag's value and decide whether you should raise an exception or not.

           

          In addition a quote from the documentation http://docs.jboss.org/jbpm/v5.1/userguide/ch05.html#sec.timers "The timer is cancelled if the timer node is cancelled (e.g., by completing or aborting the enclosing process instance)." . Actually you don't need to cancel a timer event if it is part of your process logic, instead use your logic inside your process to act accordingly (i.e. as instructed above).

          1 of 1 people found this helpful
          • 2. Re: How to cancel Timer Event
            hrushikesh.chidley

            Hello Chris,

            Thank you for the reply. Indeed the approach of boolean parameter is correct. I had thought about that earlier but there is one issue that makes me not use it.

            Consider, the process is supposed to take around 2 days to complete (may be because of some human task involved). Now I can not set the timer to anything less than 2 days. In this case, if the process, fortunately completes within an hour or so of starting it, then the whole remaining time is wasted just to wait for timer to expire. Thus, canceling the timer option came to my mind.

            About your comment from the user guide, thanks a ton for it. I was under the impression that there would be some special api of xml tags for canceling the timer. But it seems, to cancel timer, the enclosing process needs to be aborted.

             

            However, I have made a few modification myself. I am now using the timer as boundary event. The process to which I wanted to apply timeout, has been declared as subprocess. To this sub-process I have attached timer event as boundary condition. I was expecting that, should the process take more time than the timeout defined in the boundary condition, then timer event will trigger and then I can handle it.

            However this is also not working. Currently my process is taking around 10 secinds to complete and i have configured boundary condition with timer of 2 seconds. Still timer is not getting triggered.

             

            I know this is a bit off the track than my initial post, but any help would be greatly appreciated. Thank you.