4 Replies Latest reply on Aug 3, 2006 11:58 AM by Brad O'Hearne

    Timers and transitions

    Brad O'Hearne Newbie

      Using jbpm 3.1.1, I am trying to accomplish the following:

      1) Create a timer.
      2) Execute some action as the result of the timer waking up and being serviced.

      My question regards how to structure the business process in conjunction with the proper setting of the timer's transition. I have created a single business process which includes a node that creates the timer -- works without a problem. But I need the result of the timer waking up to execute another node in the process which performs an action. I thought this was simple as specifying the transition to this other node using the setTransitionName() method. However, the node specified is never being executed. Any ideas on why the transition to node isn't being executed, even though the timer is being processed?

      Secondly, am I correct in assuming that the "transition to" node must be contained within the same business process of the node which creates the timer? If this is correct, then is the proper structure of the business process not to transition programmatically after the node which creates the timer is executed? (so that the business process execution exits and processing may continue while the timer awaits).

      Thanks for your help.


        • 1. Re: Timers and transitions
          Ronald van Kuijk Master


          As is the other post, please post the pd.xml and the code. It is easier then to comment.

          • 2. Re: Timers and transitions
            Brad O'Hearne Newbie

            Here is the code of my business process:

            <?xml version="1.0" encoding="UTF-8"?>
             xmlns="" name="Solicit">
             <start-state name="start">
             <transition name="" to="validateSecurityToken"></transition>
             <end-state name="end1"></end-state>
             <node name="validateSecurityToken">
             <action class="com.capitolsystems.nodeapp.process.ValidateSecurityTokenActionHandler"></action>
             <transition name="" to="saveSolicitRequest"></transition>
             <node name="saveSolicitRequest">
             <action class="com.capitolsystems.nodeapp.process.SaveSolicitRequestActionHandler"></action>
             <transition name="" to="createSolicitTimer"></transition>
             <node name="createSolicitTimer">
             <action class="com.capitolsystems.nodeapp.process.CreateSolicitTimerActionHandler"></action>
             <transition name="" to="solicitQuery"></transition>
             <node name="solicitQuery">
             <transition name="" to="end1"></transition>
             <action class="com.capitolsystems.nodeapp.process.SolicitQueryActionHandler"></action>

            Here is the code to my CreateSolicitTimerActionHandler:

            public void execute(ExecutionContext executionContext) throws Exception {
             log.debug("[execute]: Enter.");
             try {
             log.debug("[execute]: Getting context variables.");
             String transactionId = (String) executionContext.getVariable(NetworkNode.PVAR_transactionId);
             log.debug("[execute]: Creating solicit timer: " + executionContext.getTaskInstance());
             Timer timer = new Timer(executionContext.getToken());
             timer.setName("Solicit: " + transactionId);
             BusinessCalendar businessCalendar = new BusinessCalendar();
             //Date dueDate = businessCalendar.findStartOfNextDay(new Date());
             GregorianCalendar cal = new GregorianCalendar();
             cal.setTime(new Date(System.currentTimeMillis()));
             System.out.println("Calendar time before is: " + cal.getTime().toString());
             cal.add(Calendar.MINUTE, 1);
             System.out.println("Calendar time after is: " + cal.getTime().toString());
             Date dueDate = cal.getTime();
             log.debug("[execute]: Creating solicit timer with scheduler: " + timer);
             SchedulerService schedulerService = (SchedulerService) Services.getCurrentService(Services.SERVICENAME_SCHEDULER);
             log.info("[execute]: Solicit timer created with scheduler: " + timer);
             } catch (Exception ex) {
             if (ex instanceof NodeException) {
             throw ex;
             log.error("[execute]: Error creating solicit timer: " + ex.getMessage());
             throw new NodeException("Error creating solicit timer: " + ex.getMessage(),
             ex, IErrorCode.Code.E_UNKNOWN_ERROR);
             } finally {
             log.debug("[execute]: Exit.");

            I have stepped through the execution of SchedulerThread's processing on the server, and what is happening is that for some reason, when it processes the timer in question, the org.jbpm.graph.def.Node class is returning false when executing the hasLeavingTransitions() method. I'm not quite sure why this is, as it is clear from the business process definition that the createSolicitTimer node has a transition to solicitQuery.

            I'm sure this is probably something simple I'm missing. Your help is appreciated.



            • 3. Re: Timers and transitions
              Ronald van Kuijk Master

              The transitions have no names.

              • 4. Re: Timers and transitions
                Brad O'Hearne Newbie

                Ah yes, my dunce alarm wasn't faulty. Thanks for the tip. Somehow from looking at examples I was under the impression that transitions could reference names of the nodes transitioned to, not the name of the transition itself. Thanks for the help -- I added a transition name and it worked.