7 Replies Latest reply on Aug 11, 2005 7:27 PM by marcus.junk

    invoking scheduler service in jbpm 3.0?

    rmunjuluri

      Hi,

      I am trying to get the scheduler service in jbpm 3.0 to work. I have written my own SchedulerServiceMBean in JBoss 4.02 and instantiated the Scheduler Object and started the jBpm Scheduler Object in the startService(). I can see the debug logs that the scheduler is running every minute but seems to refer to JBPM_TIMER table where as my deployed process definition never created an entry in this table.

      I created a simple task that prints a log message to run every minute, starting with a duedate of 3 minutes. here is the sample process def.

      <start-state name="Bpm_State_Start_Run_Scheduled_Job">
       <transition name="BPM_TRANSITION_TO_RUN_SCHEDULED_JOB" to="Bpm_State_Run_Scheduled_Job"></transition>
       </start-state>
      
       <state to="Bpm_State_Run_Scheduled_Job">
       <timer name='WfScheduledTimer'
       duedate='3 business minutes'
       repeat='1 business minute'
       transition='Bpm_State_End_Run_Scheduled_Job' >
       <action class='SchedulerHandlers.ScheduledActionHandler' />
       </timer>
       </state>
      
       <end-state name="Bpm_State_End_Run_Scheduled_Job"></end-state>


      I dont see that the ScheduledActionHandler is ever invoked... Does the schduler service work in JBbpm3.0 or am I missing something here?

      thanx
      -ram

        • 1. Re: invoking scheduler service in jbpm 3.0?
          marcus.junk

          Hi,

          I am having problems getting my SchedulerThread running from within an MBeanService in JBoss.
          How do you go about this?
          I seem to have successfully deployed the MBeanService and started the SchedulerThread but do not see any indication that the SchedulerThread is running.

          The only thing I can think of it is its my logging configuration within JBoss that means I can not see the same messages you see for the thread running every minute.

          below is my ServiceMBean.

          If you could steer me in the right direction it would be much appreciated.

          Thx, Marcus.

          import java.util.Date;
          
          import org.jboss.system.ServiceMBeanSupport;
          import org.jbpm.scheduler.exe.Timer;
          import org.jbpm.scheduler.impl.Scheduler;
          import org.jbpm.scheduler.impl.SchedulerListener;
          import org.jbpm.scheduler.impl.SchedulerThread;
          
          public class JbpmSchedulerService extends ServiceMBeanSupport implements JbpmSchedulerServiceMBean {
          
           private int schedulePeriod;
          
           private Scheduler scheduler;
          
           protected void startService() throws Exception {
           scheduler = new Scheduler();
          
           System.out.println("schedulePeriod :" + schedulePeriod);
           scheduler.setInterval(schedulePeriod); // assume in milliseconds
          
           int historyMaxSize = 50;
           scheduler.setHistoryMaxSize(historyMaxSize);
          
           // register the console listener
           scheduler.start();
           SchedulerThread schedulerThread = scheduler.getSchedulerThread();
          
           schedulerThread.addListener(new SchedulerListener() {
           public void timerExecuted(Date date, Timer timer) {
           // TODO Auto-generated method stub
           System.out.println("date : " + date + ", timer : " + timer);
           }
           });
           }
          
           protected void stopService() throws Exception {
           scheduler.stop();
           }
          
           public void setSchedulePeriod(int seconds) {
           this.schedulePeriod = seconds;
           }
          
           public int getSchedulePeriod() {
           return schedulePeriod;
           }
          
          }
          


          • 2. Re: invoking scheduler service in jbpm 3.0?
            rmunjuluri

            Hi,

            I tried something like this.

            public class SchedulerService extends ServiceMBeanSupport implements ....{

            private Scheduler scheduler = null;

            public SchedulerService () {
            super();
            scheduler = new Scheduler();
            }

            public void startService() throws Exception {
            log.info("--> Starting up Scheduler Service");
            scheduler.start();
            }

            public void stopService() {
            log.info("--> Shutting down Scheduler Service");
            scheduler.stop();
            }

            public String getInterval() {
            return (new Double(scheduler.getInterval())).toString();
            }
            public void setInterval(String interval) {
            scheduler.setInterval((new Double(interval)).intValue());
            }

            public String getHistoryMaxSize() {
            return (new Double(scheduler.getHistoryMaxSize())).toString();
            }
            public void setHistoryMaxSize(String historyMaxSize) {
            scheduler.setHistoryMaxSize((new Double(historyMaxSize)).intValue());
            }
            }


            and I set the interval to 60000 millis and the historymaxsize as attributes of the service in the deployment descriptor. this makes the schedulerthread within the Scheduler object execute every min. the logs are in DEBUG mode (using log.debug()) within the scheduler/schedulerThread. so they appear in the server.log.

            the scheduler thread wakes up every min and checks for any set timers in the JBPM_TIMER table for execution.

            let me know

            -ram

            • 3. Re: invoking scheduler service in jbpm 3.0?
              marcus.junk

              yep thats similiar to what I did in the end, ta.

              Have an issue around now having to embed this ServiceMBean in the same class loader as my EAR that is doing all the jbpm stuff, else the SchedulerThread when it fires cannot find the correct ActionHandler implementation.

              I did get my ActionHandler to fire on a task timeout thou, the biggest problem I had was in the way I'm doing transaction management and thus the underlying scheduler was having issues trying to start a transaction. I fixed and resolved all my issues by remote debugging jboss when the executeTimers method was invoked.

              M.

              • 4. Re: invoking scheduler service in jbpm 3.0?
                rmunjuluri

                Cool. what did you have to do to make the actionhandler to fire? Did you have something different in the process definition that updates the JBPM_TIMER, for the MBean Service to pick up the timer settings and fire the action handler?

                thanx
                -ram

                • 5. Re: invoking scheduler service in jbpm 3.0?
                  marcus.junk

                  The action handler class configured in the jpdl timer definition simply needed to be in the path of the class loader that was running the SchedulerThread. It simply fired the action event on timer expiry and the class was invoked.
                  I found out this problem by remote debugging the executeTimers method and seeing why and what was happening when the executeTimers method was invoked.

                  M.

                  • 6. Re: invoking scheduler service in jbpm 3.0?
                    rmunjuluri

                    Do you see any rows created in the JBPM_TIMER table when you deployed the process def? if you did, can you give an example of the process def you used? cause I dont see any rows created in my JBPM_TIMER table and I can see that the SchedulerThread loops and checks for rows in the JBPM_TIMER table that do not have an exception.

                    I really appreciate your help

                    thanx
                    -ram

                    • 7. Re: invoking scheduler service in jbpm 3.0?
                      marcus.junk

                      Yeah I definetly see rows added for the duration of the timer in the jbpm_timer table.

                      Here is my processdefintion.xml

                      <?xml version="1.0" encoding="UTF-8"?>
                      
                      <process-definition
                       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                       name="JBossSimpleTaskTimerTest">
                       <start-state name="start">
                       <transition name="tr1" to="task1"></transition>
                       </start-state>
                       <end-state name="end"></end-state>
                       <task-node name="task1">
                       <task name="task1">
                       <timer name='reminder' duedate='20 seconds'>
                       <action class='com.sample.action.TaskTimeoutMessageHandler' />
                       </timer>
                       </task>
                       <transition name="tr1" to="end"></transition>
                       </task-node>
                      </process-definition>
                      


                      And the ActionHandler class
                      package com.sample.action;
                      
                      import org.jbpm.graph.def.ActionHandler;
                      import org.jbpm.graph.exe.ExecutionContext;
                      
                      public class TaskTimeoutMessageHandler implements ActionHandler {
                      
                       private static final long serialVersionUID = 1L;
                      
                       public void execute(ExecutionContext executionContext) throws Exception {
                       // TODO Auto-generated method stub
                       System.out.println("***************");
                       System.out.println("TaskTimeoutMessageHandler FIRED");
                       System.out.println("***************");
                       }
                      }
                      



                      And the code that invokes my business process.

                       /**
                      
                       * Marcus test method to test business process task timer functionality within the JBoss container
                      
                       *
                      
                       * @return true if suceeds else false
                      
                       * @throws Exception
                      
                       *
                      
                       * @ejb.interface-method
                      
                       * @ejb.transaction
                      
                       * type="Required"
                      
                       */
                      
                       public boolean testBusinessProcessTaskTimer() throws Exception {
                      
                      
                      
                       String bpName = "JBossSimpleTaskTimerTest";
                      
                      
                      
                       // open & start a business process
                      
                       startBusinessProcess(bpName);
                      
                      
                      
                       return true;
                      
                       }
                      
                      
                      
                      
                      
                       private void startBusinessProcess(String bpName){
                      
                      
                      
                       // need to hook into current singleton jbpmSessionFactory using JNDI
                      
                       JbpmSessionFactory jbpmSessionFactory =
                      
                       (JbpmSessionFactory) new JndiContext().lookup("java:/jbpm/JbpmSessionFactory", JbpmSessionFactory.class);
                      
                      
                      
                      
                      
                       LOG.debug("opening jbpm session");
                      
                       JbpmSession jbpmSession = jbpmSessionFactory.openJbpmSession();
                      
                      
                      
                       try {
                      
                      
                      
                       LOG.debug("retrieve jbpm process definition : " + bpName);
                      
                       ProcessDefinition processDefinition =
                      jbpmSession.getGraphSession().findLatestProcessDefinition(bpName);
                      
                      
                      
                       // for interest sake check to see if there are any existing BPS that have not completed.
                      
                       jbpmSession.getGraphSession().findProcessInstances(processDefinition.getId());
                      
                      
                      
                      
                      
                       LOG.debug("creating process instance : " + bpName);
                      
                       ProcessInstance processInstance = new ProcessInstance(processDefinition);
                      
                      
                      
                       // start bp instance
                      
                       LOG.debug("starting process instance, name : " + bpName + ", process id : " + processInstance.getId());
                      
                       processInstance.signal();
                      
                      
                      
                       LOG.debug("instance.isTerminatedImplicitly=<" + processInstance.isTerminatedImplicitly() + ">");
                      
                      
                      
                       LOG.debug("Instance is in state=<" + processInstance.getRootToken().getNode().getName() + ">");
                      
                       LOG.debug("processInstance.hasEnded()=<" + processInstance.hasEnded() + ">");
                      
                       LOG.debug("processInstance.getStart()=<" + processInstance.getStart() + ">");
                      
                       LOG.debug("processInstance.getEnd()=<" + processInstance.getEnd() + ">");
                      
                      
                      
                       LOG.debug("save process instance : " + processInstance);
                      
                       jbpmSession.getGraphSession().saveProcessInstance(processInstance);
                      
                      
                      
                       jbpmSession.getSession().flush();
                      
                       } finally {
                      
                       LOG.debug("close jbpm session txn");
                      
                       jbpmSession.close();
                      
                       }
                      
                       }
                      


                      sorry bout the weird excessive white space in the code above, something dodgy happened after I pasted into the forum and then hit preview.

                      And finally my jboss logs of the business process being invoked and then the timer firing.

                      I don't really want to post the complete jboss log in here as its verbose, how do I attach a file in this forum?

                      Here is a snippet of the timer firing and the hibernate code querying the jbpm_timer table. I have replaced any commercially sensitive data with ***.


                      2005-08-12 10:58:46,248 551780 INFO [STDOUT] (jbpm scheduler:) Hibernate: select timer0_.ID_ as col_0_0_ from JBPM_TIMER timer0_ where timer0_.EXCEPTION_ is null order by timer0_.DUEDATE_ asc
                      2005-08-12 10:58:50,938 556470 INFO [*********.framework.enterprise.jndi.spi.JndiContextImpl] (RMI TCP Connection(2)-127.0.0.1:) Looking up jndi object 'java:/jbpm/JbpmSessionFactory' as a 'org.jbpm.db.JbpmSessionFactory'.
                      2005-08-12 10:58:50,939 556471 INFO [*********.framework.enterprise.jndi.spi.JndiContextImpl] (RMI TCP Connection(2)-127.0.0.1:) Jndi object 'java:/jbpm/JbpmSessionFactory' found successfully.
                      2005-08-12 10:58:50,939 556471 DEBUG [**.**.**.bpm.prototypes.BPMTestBean] (RMI TCP Connection(2)-127.0.0.1:) opening jbpm session
                      2005-08-12 10:58:50,940 556472 DEBUG [**.**.**.bpm.prototypes.BPMTestBean] (RMI TCP Connection(2)-127.0.0.1:) retrieve jbpm process definition : JBossSimpleTaskTimerTest
                      ....
                      2005-08-12 10:58:51,476 557008 DEBUG [**.**.**.bpm.prototypes.BPMTestBean] (RMI TCP Connection(2)-127.0.0.1:) creating process instance : JBossSimpleTaskTimerTest
                      2005-08-12 10:58:51,993 557525 DEBUG [**.**.**.bpm.prototypes.BPMTestBean] (RMI TCP Connection(2)-127.0.0.1:) instance.isTerminatedImplicitly=<false>
                      2005-08-12 10:58:51,994 557526 DEBUG [**.**.**.bpm.prototypes.BPMTestBean] (RMI TCP Connection(2)-127.0.0.1:) Instance is in state=<task1>
                      2005-08-12 10:58:51,994 557526 DEBUG [**.**.**.bpm.prototypes.BPMTestBean] (RMI TCP Connection(2)-127.0.0.1:) processInstance.hasEnded()=<false>
                      2005-08-12 10:58:51,994 557526 DEBUG [**.**.**.bpm.prototypes.BPMTestBean] (RMI TCP Connection(2)-127.0.0.1:) processInstance.getStart()=<Fri Aug 12 10:58:51 NZST 2005>
                      2005-08-12 10:58:51,994 557526 DEBUG [**.**.**.bpm.prototypes.BPMTestBean] (RMI TCP Connection(2)-127.0.0.1:) processInstance.getEnd()=<null>
                      2005-08-12 10:58:51,994 557526 DEBUG [**.**.**.bpm.prototypes.BPMTestBean] (RMI TCP Connection(2)-127.0.0.1:) save process instance : org.jbpm.graph.exe.ProcessInstance@efae3b
                      2005-08-12 10:58:51,995 557527 INFO [STDOUT] (RMI TCP Connection(2)-127.0.0.1:) Hibernate: insert into JBPM_LOG (INDEX_, DATE_, TOKEN_, PARENT_, CLASS_) values (?, ?, ?, ?, 'I')
                      2005-08-12 10:58:52,011 557543 INFO [STDOUT] (RMI TCP Connection(2)-127.0.0.1:) Hibernate: insert into JBPM_LOG (INDEX_, DATE_, TOKEN_, PARENT_, TRANSITION_, CLASS_) values (?, ?, ?, ?, ?, 'S')
                      2005-08-12 10:58:52,012 557544 INFO [STDOUT] (RMI TCP Connection(2)-127.0.0.1:) Hibernate: insert into JBPM_LOG (INDEX_, DATE_, TOKEN_, PARENT_, TRANSITION_, SOURCENODE_, DESTINATIONNODE_, CLASS_) values (?, ?, ?, ?, ?, ?, ?, 'T')
                      2005-08-12 10:58:52,020 557552 INFO [STDOUT] (RMI TCP Connection(2)-127.0.0.1:) Hibernate: insert into JBPM_LOG (INDEX_, DATE_, TOKEN_, PARENT_, EXCEPTION_, ACTION_, CLASS_) values (?, ?, ?, ?, ?, ?, 'A')
                      2005-08-12 10:58:52,025 557557 INFO [STDOUT] (RMI TCP Connection(2)-127.0.0.1:) Hibernate: insert into JBPM_LOG (INDEX_, DATE_, TOKEN_, PARENT_, TASKINSTANCE_, TASKACTORID_, CLASS_) values (?, ?, ?, ?, ?, ?, '1')
                      2005-08-12 10:58:52,032 557564 INFO [STDOUT] (RMI TCP Connection(2)-127.0.0.1:) Hibernate: insert into JBPM_TIMER (NAME_, DUEDATE_, REPEAT_, TRANSITIONNAME_, EXCEPTION_, ACTION_, TOKEN_, PROCESSINSTANCE_, TASKINSTANCE_, GRAPHELEMENTTYPE_, GRAPHELEMENT_) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
                      2005-08-12 10:58:52,058 557590 INFO [STDOUT] (RMI TCP Connection(2)-127.0.0.1:) Hibernate: update JBPM_TOKEN set NAME_=?, START_=?, END_=?, NODEENTER_=?, NEXTLOGINDEX_=?, ISABLETOREACTIVATEPARENT_=?, ISTERMINATIONIMPLICIT_=?, NODE_=?, PROCESSINSTANCE_=?, PARENT_=? where ID_=?
                      2005-08-12 10:58:52,072 557604 INFO [STDOUT] (RMI TCP Connection(2)-127.0.0.1:) Hibernate: update JBPM_TASKINSTANCE set NAME_=?, DESCRIPTION_=?, ACTORID_=?, CREATE_=?, START_=?, END_=?, DUEDATE_=?, PRIORITY_=?, ISCANCELLED_=?, ISSIGNALLING_=?, ISBLOCKING_=?, TASK_=?, TOKEN_=?, SWIMLANINSTANCE_=?, TASKMGMTINSTANCE_=? where ID_=?
                      2005-08-12 10:58:52,080 557612 INFO [STDOUT] (RMI TCP Connection(2)-127.0.0.1:) Hibernate: update JBPM_MODULEINSTANCE set PROCESSINSTANCE_=?, NAME_=? where ID_=?
                      2005-08-12 10:58:52,091 557623 INFO [STDOUT] (RMI TCP Connection(2)-127.0.0.1:) Hibernate: update JBPM_MODULEINSTANCE set PROCESSINSTANCE_=?, NAME_=? where ID_=?
                      2005-08-12 10:58:52,100 557632 DEBUG [**.**.**.bpm.prototypes.BPMTestBean] (RMI TCP Connection(2)-127.0.0.1:) close jbpm session txn
                      2005-08-12 10:58:56,486 562018 INFO [STDOUT] (jbpm scheduler:) Hibernate: select timer0_.ID_ as col_0_0_ from JBPM_TIMER timer0_ where timer0_.EXCEPTION_ is null order by timer0_.DUEDATE_ asc
                      2005-08-12 10:58:56,522 562054 INFO [STDOUT] (jbpm scheduler:) Hibernate: select timer0_.ID_ as ID1_42_, timer0_.NAME_ as NAME2_26_42_, timer0_.DUEDATE_ as DUEDATE3_26_42_, timer0_.REPEAT_ as REPEAT4_26_42_, timer0_.TRANSITIONNAME_ as TRANSITI5_26_42_, timer0_.EXCEPTION_ as EXCEPTION6_26_42_, timer0_.ACTION_ as ACTION7_26_42_, timer0_.TOKEN_ as TOKEN8_26_42_, timer0_.PROCESSINSTANCE_ as PROCESSI9_26_42_, timer0_.TASKINSTANCE_ as TASKINS10_26_42_, timer0_.GRAPHELEMENTTYPE_ as GRAPHEL11_26_42_, timer0_.GRAPHELEMENT_ as GRAPHEL12_26_42_, action1_.ID_ as ID1_0_, action1_.NAME_ as NAME3_4_0_, action1_.ISPROPAGATIONALLOWED_ as ISPROPAG4_4_0_, action1_.REFERENCEDACTION_ as REFERENC5_4_0_, action1_.ACTIONDELEGATION_ as ACTIONDE6_4_0_, action1_.EVENT_ as EVENT7_4_0_, action1_.PROCESSDEFINI
                      2005-08-12 10:59:12,015 577547 INFO [STDOUT] (jbpm scheduler:) Hibernate: select timer0_.ID_ as col_0_0_ from JBPM_TIMER timer0_ where timer0_.EXCEPTION_ is null order by timer0_.DUEDATE_ asc
                      ---- MASSIVE verbose hibernate query.
                      2005-08-12 10:59:12,030 577562 INFO [STDOUT] (jbpm scheduler:) Hibernate: select timer0_.ID_ as ID1_42_, timer0_.NAME_ as NAME2_26_42_, timer0_.DUEDATE_ as DUEDATE3_26_42_, timer0_.REPEAT_ as REPEAT4_26_42_, timer0_.TRANSITIONNAME_ as TRANSITI5_26_42_, timer0_.EXCEPTION_ as EXCEPTION6_26_42_, timer0_.ACTION_ as ACTION7_26_42_, timer0_.TOKEN_ as TOKEN8_26_42_, timer0_.PROCESSINSTANCE_ as PROCESSI9_26_42_, timer0_.
                      ---- MASSIVE verbose hibernate query.
                      2005-08-12 10:59:12,365 577897 INFO [STDOUT] (jbpm scheduler:) ***************
                      2005-08-12 10:59:12,365 577897 INFO [STDOUT] (jbpm scheduler:) TaskTimeoutMessageHandler FIRED
                      2005-08-12 10:59:12,366 577898 INFO [STDOUT] (jbpm scheduler:) ***************
                      2005-08-12 10:59:12,380 577912 INFO [STDOUT] (jbpm scheduler:) date : Fri Aug 12 10:59:12 NZST 2005, timer : timer(reminder,com.sample.action.TaskTimeoutMessageHandler,10:59:11,957)
                      2005-08-12 10:59:12,407 577939 INFO [STDOUT] (jbpm scheduler:) Hibernate: delete from JBPM_TIMER where ID_=?
                      2005-08-12 10:59:17,429 582961 INFO [STDOUT] (jbpm scheduler:) Hibernate: select timer0_.ID_ as col_0_0_ from JBPM_TIMER timer0_ where timer0_.EXCEPTION_ is null order by timer0_.DUEDATE_ asc
                      2005-08-12 10:59:22,449 587981 INFO [STDOUT] (jbpm scheduler:) Hibernate: select timer0_.ID_ as col_0_0_ from JBPM_TIMER timer0_ where timer0_.EXCEPTION_ is null order by timer0_.DUEDATE_ asc




                      Hope this helps and I can post the full jboss log via email or some attach mechanism if pos.

                      M.