4 Replies Latest reply on Jul 12, 2010 4:26 PM by jDev Dev

    jBPM timer not executing/firing

    jDev Dev Newbie

      I am using Eclipse v3 with jbpm 3.2.3

       

      I have a timer in my process definition that should send an email once it fires.

       

      It seems the timer never fires and I am not sure why.

       

      - I included all services in jbpm-context

      - my timers are being stored in the databse  ( Ican see the tables populating)

      - am I missing a class that schedules the timers to run (I thought that the scheduler service takes care of that)???

       

      If I remove the timer from the state and keep the mail statement (to send mail), it WORKS ... so it seems my timer is not firing

       

      ** I have tried using event (with <create-timer>), state (with <timer>), a simple system.out but to no avail

       

      Any insight would be appreciated

       

      HERE's all the files I am using for this simple java application

       

      PROCESS Definition code

      <?xml version="1.0" encoding="UTF-8"?>

       

      <process-definition  xmlns="urn:jbpm.org:jpdl-3.2"  name="TimerProcess/Tprocessdefinition.xml">

       

           <start-state name="start">

                <transition to="setTimer" name="trSetTimer"></transition>

           </start-state>

           

           <state name="setTimer">

           <timer name="notification" transition="trEnd" duedate="5 seconds">

                     <action name="emailNotify" class="org.jbpm.mail.Mail">

                     <subject>

                               notify timer

                     </subject>

                     <text>

                               testing jbpm timer

                     </text>

                     <to>

                     laura_carl@yahoo.com

                     </to>

                     </action>

                </timer>

                <transition name="trEnd" to="end"/>

           </state>

                

       

           <end-state name="end"></end-state>

       

      </process-definition>

       

      RunTimer class to drive the process Defintion

      package com.sample;

       

      import org.jbpm.JbpmConfiguration;

      import org.jbpm.JbpmContext;

      import org.jbpm.graph.def.ProcessDefinition;

      import org.jbpm.graph.exe.ProcessInstance;

       

      public class RunTimer {

           public static void main(String args[])throws Exception {

                new RunTimer().execute();

      }

       

      public void execute() throws Exception {

           

           JbpmContext jbpmContext= JbpmConfiguration.getInstance().createJbpmContext();

                

           try{

                ProcessInstance instance = processDefinition.createProcessInstance();

                jbpmContext.deployProcessDefinition(processDefinition);

                displayStatus(instance);

                instance.signal();

                displayStatus(instance);

                jbpmContext.save(instance);

           }finally{

                jbpmContext.close();

           }

       

      }

       

      private void displayStatus(ProcessInstance instance) {  

           String nodeName = instance.getRootToken().getNode().getName();  

           System.out.println("You are now in node: "+nodeName);  

       

      }  

       

      }

       

      and my jbpm cfg xml

      <jbpm-configuration>

       

        <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 resource files pointing to default configuration files in jbpm-{version}.jar -->

        <string name='resource.hibernate.cfg.xml' value='hibernate.cfg.xml' />

        <!-- <string name='resource.hibernate.properties' value='hibernate.properties' /> -->

        <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" />

        <string name="jbpm.mail.smtp.host" value="smt4.rogers.com"/>

       

        <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' />

        <bean name="jbpm.mail.address.resolver" class="org.jbpm.identity.mail.IdentityAddressResolver" singleton="true" />

        <bean name="jbpm.job.executor" class="org.jbpm.job.executor.JobExecutor" singleton="true"/>

       

       

       

      </jbpm-configuration>

        • 1. Re: jBPM timer not executing/firing
          Toshiya Kobayashi Newbie

          Hi,

           

          Do you know that you need to start Job Executor thread? -- Configuring it in jbpm.cfg.xml is not enough.

           

          http://docs.jboss.com/jbpm/v3.2/userguide/html_single/#d0e140

           

          The job executor component is packaged in the core jbpm-jpdl library, but it needs      to be deployed in one of the following ways: either register the JobExecutorLauncher servlet context listener in the web app deployment descriptor to start/stop the job     executor during creation/destruction of the servlet context, or start up a separate JVM     and start the job executor in there programatically.
          

           

          You can find jbpm-jpdl-3.2.3/deploy/jbpm-console.war as an example of job executor launcher servlet (see WEB-INF/web.xml).

           

          Toshiya

          • 2. Re: jBPM timer not executing/firing
            jDev Dev Newbie

            Thanks for the advise. It is making sense now.

            However, I am getting null for jobs to be executed

             

            I am placing this code after I signal for next transition>

             

            JobExecutor jobExecutor =  jbpmContext.getJbpmConfiguration().getJobExecutor();

            if  (jobExecutor==null) {
                      throw new JbpmException("no job executor configured in resource  ");
                      }
                      jobExecutor.start();

             

            I get in my console the following info

            [main] DEBUG JobExecutor : starting thread group 'null'...

             

            Is this the wrong way of extracting the jobs from the DB?

            • 3. Re: jBPM timer not executing/firing
              Toshiya Kobayashi Newbie
              [main] DEBUG JobExecutor : starting thread group 'null'...

               

              The message is not important. 'null' is just the name of JobExecutor.

               

              First, I think you don't have to configure your own jbpm.cfg.xml.
              jbpm-jpdl.jar:org/jbpm/default.jbpm.cfg.xml has properly configured JobExecutor and will be looked up if you don't have your own jbpm.cfg.xml.

               

              Second, your problem is that your java process ends before JobExecutor captures timer jobs. Try Thread.sleep(10000) at the end of your main method.
              This ad-hoc impl is ok if you just want to see how Timer works. But in real use case, you need to make sure the JobExecutorThread is alive. That's why the jbpm distribution contains job executor launcher servlet which run on an application server.

              • 4. Re: jBPM timer not executing/firing
                jDev Dev Newbie

                Thank you Toshiya ... It fixed the issue.

                 

                Currently, I am trying to integrate the jbpm timer taht I created with a web application (only using JSF) ... I keep getting an error. I will open another discussion for that