12 Replies Latest reply on Nov 8, 2008 8:55 AM by koen.aers

    Timers in jBPL

      Hi,

      there is not much documentation regarding the actual use of timers. I want to implement a wait state which is left after the duration period. As I understood from description the following should do it:



      <cancel-timer name='reminder'/>




      But nothing happens. The state is left only on manually signalling. What's wrong in my understanding?
      Thanks.
      Juergen

        • 1. Re: Timers in jBPL

          Sorry, the code was cut during submitting it should look this:

          <state name="warte 1">
           <timer name='reminder'
           duedate='2 minutes'
           transition='ex1' >
           <cancel-timer name='reminder'/>
           </timer>
           <transition to="warte2" name="ex1"></transition>
           </state>
          


          • 2. Re: Timers in jBPL
            jbarrez

            Is the job scheduler correctly configured in the jbpm.cfg ? Please post the config here.

            • 3. Re: Timers in jBPL

               

              <jbpm-configuration>
              
               <!--
               This configuration is used when there is no jbpm.cfg.xml file found in the
               root of the classpath. It is a very basic configuration without persistence
               and message services. Only the authorization service installed.
               You can parse and create processes, but when you try to use one of the
               unavailable services, you'll get an exception.
               -->
              
               <jbpm-context>
               <service name="persistence" factory="org.jbpm.persistence.db.DbPersistenceServiceFactory" />
               <service name="tx" factory="org.jbpm.tx.TxServiceFactory" />
               <service name="message" factory="org.jbpm.msg.db.DbMessageServiceFactory" />
               <service name="scheduler" factory="org.jbpm.scheduler.db.DbSchedulerServiceFactory" />
               <service name="logging" factory="org.jbpm.logging.db.DbLoggingServiceFactory" />
               <service name="authentication" factory="org.jbpm.security.authentication.DefaultAuthenticationServiceFactory" />
               </jbpm-context>
              
               <!-- configuration property used by persistence service impl org.jbpm.persistence.db.DbPersistenceServiceFactory -->
               <string name="resource.hibernate.cfg.xml" value="hibernate.cfg.xml" />
              
               <!-- configuration resource files pointing to default configuration files in jbpm-{version}.jar -->
               <string name="resource.business.calendar" value="org/jbpm/calendar/jbpm.business.calendar.properties" />
               <string name="resource.default.modules" value="org/jbpm/graph/def/jbpm.default.modules.properties" />
               <string name="resource.converter" value="org/jbpm/db/hibernate/jbpm.converter.properties" />
               <string name="resource.action.types" value="org/jbpm/graph/action/action.types.xml" />
               <string name="resource.node.types" value="org/jbpm/graph/node/node.types.xml" />
               <string name="resource.parsers" value="org/jbpm/jpdl/par/jbpm.parsers.xml" />
               <string name="resource.varmapping" value="org/jbpm/context/exe/jbpm.varmapping.xml" />
               <string name="resource.mail.templates" value="jbpm.mail.templates.xml" />
              
               <int name="jbpm.byte.block.size" value="1024" singleton="true" />
               <bean name="jbpm.task.instance.factory" class="org.jbpm.taskmgmt.impl.DefaultTaskInstanceFactoryImpl" singleton="true" />
               <bean name="jbpm.variable.resolver" class="org.jbpm.jpdl.el.impl.JbpmVariableResolver" singleton="true" />
               <string name="jbpm.mail.smtp.host" value="localhost" />
               <bean name="jbpm.mail.address.resolver" class="org.jbpm.identity.mail.IdentityAddressResolver" singleton="true" />
               <string name="jbpm.mail.from.address" value="jbpm@noreply" />
              
               <bean name="jbpm.job.executor" class="org.jbpm.job.executor.JobExecutor">
               <field name="jbpmConfiguration"><ref bean="jbpmConfiguration" /></field>
               <field name="name"><string value="JbpmJobExecutor" /></field>
               <field name="nbrOfThreads"><int value="1" /></field>
               <field name="idleInterval"><int value="5000" /></field>
               <field name="maxIdleInterval"><int value="3600000" /></field> <!-- 1 hour -->
               <field name="historyMaxSize"><int value="20" /></field>
               <field name="maxLockTime"><int value="600000" /></field> <!-- 10 minutes -->
               <field name="lockMonitorInterval"><int value="60000" /></field> <!-- 1 minute -->
               <field name="lockBufferTime"><int value="5000" /></field> <!-- 5 seconds -->
               </bean>
              
              </jbpm-configuration>
              


              • 4. Re: Timers in jBPL
                jbarrez

                Looks fine at first sight.

                Is the executor started? Eg in a non-enterprise environment, have you called jbpmConfiguration.startJobExecutor() ?

                • 5. Re: Timers in jBPL

                  I think so. It should be started via the web.xml entry:

                  <!-- Job executor launcher (begin) -->
                   <listener>
                   <description>
                   Starts the job executor on servlet context initialization and stops it on
                   servlet context destruction.
                   </description>
                   <listener-class>org.jbpm.web.JobExecutorLauncher</listener-class>
                   </listener>
                   <!-- Job executor launcher (end) -->
                  


                  Meanwhile I played around a bit:
                  1) changed the timer to
                  <timer name='reminder'
                   duedate='2 minutes'
                   transition='ex1' >
                   <script>
                   System.out.println("Timer fired "+node);
                   Token.signal();
                   </script>
                   </timer>
                  

                  got the output "Timer fired State(warte 1)" but nothing else.

                  2) changed the script to
                  <script>
                   System.out.println("Timer fired "+node);
                   executionContext.getProcessInstance().signal();
                   </script>
                  

                  found the server locked in endless printing "Timer fired State(warte 1)"

                  • 6. Re: Timers in jBPL
                    kukeltje

                    any errors in the logging? turn on debug level to see what happens.

                    • 7. Re: Timers in jBPL
                      kukeltje

                      btw, your first example is wrong. You cannot (and should not) cancel the timer within itself. The cancel timer should be on the transition, and it might even be left out completely, since (afaik, but you should check) a timer on a node is cancelled when this node is left.

                      • 8. Re: Timers in jBPL
                        kukeltje

                        small correction: timers are only cancelled when they are on a task that is ended. So either use a cancel-timer in a transition or define the cancel-event attribute on the timer and set it e.g. to node-leave

                        • 9. Re: Timers in jBPL

                          This was THE hint - now it works as expected:

                          <state name="warte 1">
                           <timer name='reminder'
                           duedate='2 minutes'
                           transition='ex1'
                           cancel-event='node-left'>
                           <script>
                           System.out.println("Timer fired "+node);
                           </script>
                           </timer>
                           <transition to="Ende" name="ex1"></transition>
                           </state>
                          

                          But the docu is misleading, saying:
                          this attribute is only to be used in timers of tasks. it specifies the event on which the timer should be cancelled. by default, this is the task-end event, but it can be set to e.g. task-assign or task-start. ...


                          Thanks a lot!

                          • 10. Re: Timers in jBPL
                            kukeltje

                            ok... great that it works... can you file a jira issue for the 'misleading' docs? so it won't get lost

                            • 11. Re: Timers in jBPL
                              koen.aers

                              There is nothing wrong with the documentation except for maybe it being a little bit (too?) concise:

                              1. If you specify a timer on a node it gets translated to a create-timer and a cancel-timer action. The create-timer action is associated with the node-enter event and the cancel-timer action is associated with the node-leave event. The timer will thus be created and start running when you enter the node, like you would expect. Similarly, the timer will be automatically canceled when you leave the node. So if you leave the node when the timer fires (such as in the example above), the timer will be canceled as expected. There is no cancel-event attribute for timers on nodes. The parser does not parse it and if you add it, it will be ignored.

                              2. If you specify a timer on a task, it will again be translated to a create-timer action and a cancel-timer action. In this case the create-timer action will be associated with the task-create event. So the timer will be created and start running when the task is created. As for the cancel-timer there is a difference with nodes. You can specify one or more event types with which the cancel-timer can be associated with the cancel-event attribute. The cancel-timer attribute is a comma separated list of event types. It can amongst others include task-create, task-end, task-cancel, task-start, etc. The cancel-timer action gets associated with each of the comma separated values that is specified in the list. So if I would have "task-start, task-end" as the value of the attribute, the cancel-timer action would be executed when the task is started as well as when the task is ended. If no value is specified for the cancel-event, the default is to associate the cancel-timer action with the task-end event.

                              I hope this clarifies he confusion.

                              Cheers,
                              Koen

                              • 12. Re: Timers in jBPL
                                koen.aers

                                The relevant portion of the docs can be found here: http://docs.jboss.com/jbpm/v3.2/userguide/html_single/#tasktimers