4 Replies Latest reply on Aug 1, 2005 4:06 AM by koder1

    JBPM executor example

    koder1

      Hi,

      where can i find working example of the JBPM engine executor that persists jbpms state in the db, executes timers and so on?

      pawel

        • 1. Re: JBPM executor example
          kukeltje

          If you mean using the low level api, look at the testcases.

          Ronald

          • 2. Re: JBPM executor example
            koder1

            hi again,

            in this simple testcase (made after a db test from jbpm.tests), the timer is execute and deleted only the first time processinstance is executed (see log at the end).
            How should this for loop look like, to make the timers be executed properly?

            ---

            public class TimerTest extends AbstractDbTestCase {



            public void testTimerExecutionRepeat() throws InterruptedException {
            ProcessDefinition processDefinition = ProcessDefinition
            .parseXmlString("<process-definition>"
            + " "
            + " System.out.println(\"this script is entering node\"+node);"
            + " "

            + " <start-state>"
            + " "
            + " </start-state>"

            + " <task-node name='callBack'>"
            + " <timer name='reminder'"
            + " duedate='3 seconds'"
            + " transition='toCallBack'/>"

            + " "
            + " "

            + " "
            + " "
            + " </task-node>"

            + " <end-state name='end'/>"
            + "</process-definition>");


            processDefinition = saveAndReload(processDefinition);
            ProcessInstance processInstance = new ProcessInstance(processDefinition);

            processInstance.signal();
            jbpmSession.getGraphSession().saveProcessInstance(processInstance);
            newTransaction();
            commitAndCloseSession();

            for(int x = 0; x< 20; x++){

            new SchedulerThread().executeTimers();
            System.out.println("CurrentNode= " + processInstance.getRootToken().getNode().getName());
            Thread.sleep(1000);
            }
            }
            }


            ---

            09:51:57,875 DEBUG GraphElement : event 'process-start' on 'ProcessDefinition(19fe451)' for 'Token(/)'
            09:51:57,890 DEBUG GraphElement : event 'before-signal' on 'StartState(147917a)' for 'Token(/)'
            09:51:57,906 DEBUG GraphElement : event 'node-leave' on 'StartState(147917a)' for 'Token(/)'
            09:51:57,906 DEBUG GraphElement : event 'transition' on 'Transition(102b2b6)' for 'Token(/)'
            09:51:57,906 DEBUG GraphElement : event 'node-enter' on 'TaskNode(callBack)' for 'Token(/)'
            09:51:57,921 DEBUG GraphElement : executing action 'CreateTimerAction(111ded2)'
            09:51:57,937 DEBUG GraphElement : executing action 'Script(19f03d7)'
            09:51:57,937 DEBUG Script : script input: {taskInstance=null, node=TaskNode(callBack), token=Token(/), task=null, executionContext=ExecutionContext[Token(/)]}
            this script is entering nodeTaskNode(callBack)
            09:51:58,062 DEBUG Script : script output: {}
            09:51:58,078 DEBUG GraphElement : event 'task-create' on 'Task(calling back)' for 'Token(/)'
            09:51:58,078 DEBUG GraphElement : event 'after-signal' on 'StartState(147917a)' for 'Token(/)'
            09:51:58,093 DEBUG SchedulerSession : saving timer timer(reminder,09:52:00,921)
            09:51:58,093 DEBUG JbpmSessionFactory : building singleton JbpmSessionFactory
            09:51:58,093 DEBUG JbpmSessionFactory : using the default hibernate configuration file: hibernate.cfg.xml
            09:51:59,046 DEBUG JbpmSessionFactory : building hibernate session factory
            09:51:59,765 DEBUG SchedulerThread : checking for timers
            09:52:00,015 DEBUG SchedulerThread : found timer timer(reminder,09:52:00,921)
            CurrentNode= callBack
            09:52:01,015 DEBUG SchedulerThread : checking for timers
            09:52:01,046 DEBUG SchedulerThread : found timer timer(reminder,09:52:00,921)
            09:52:01,046 DEBUG SchedulerThread : executing timer 'timer(reminder,09:52:00,921)'
            09:52:01,093 DEBUG GraphElement : event 'before-signal' on 'TaskNode(callBack)' for 'Token(/)'
            09:52:01,125 DEBUG GraphElement : event 'node-leave' on 'TaskNode(callBack)' for 'Token(/)'
            09:52:01,125 DEBUG GraphElement : executing action 'CancelTimerAction(11a0d35)'
            09:52:01,125 DEBUG GraphElement : event 'transition' on 'Transition(toCallBack)' for 'Token(/)'
            09:52:01,140 DEBUG GraphElement : event 'node-enter' on 'TaskNode(callBack)' for 'Token(/)'
            09:52:01,140 DEBUG GraphElement : executing action 'CreateTimerAction(bafdff)'
            09:52:01,140 DEBUG GraphElement : executing action 'Script(1a9f87c)'
            09:52:01,156 DEBUG Script : script input: {taskInstance=null, node=TaskNode(callBack), token=Token(/), task=null, executionContext=ExecutionContext[Token(/)]}
            this script is entering nodeTaskNode(callBack)
            09:52:01,171 DEBUG Script : script output: {}
            09:52:01,187 DEBUG GraphElement : event 'task-create' on 'Task(calling back)' for 'Token(/)'
            09:52:01,187 DEBUG GraphElement : event 'after-signal' on 'TaskNode(callBack)' for 'Token(/)'
            09:52:01,187 DEBUG SchedulerThread : deleting timer 'timer(reminder,09:52:00,921)'
            CurrentNode= callBack
            09:52:02,203 DEBUG SchedulerThread : checking for timers
            CurrentNode= callBack
            09:52:03,203 DEBUG SchedulerThread : checking for timers
            CurrentNode= callBack
            09:52:04,203 DEBUG SchedulerThread : checking for timers
            CurrentNode= callBack
            09:52:05,203 DEBUG SchedulerThread : checking for timers
            CurrentNode= callBack
            09:52:06,203 DEBUG SchedulerThread : checking for timers
            CurrentNode= callBack

            • 3. Re: JBPM executor example
              koder1

              hi again,

              in this simple testcase (made after a db test from jbpm.tests), the timer is execute and deleted only the first time processinstance is executed (see log at the end).
              How should this for loop look like, to make the timers be executed properly?

              ---

              public class TimerTest extends AbstractDbTestCase {



              public void testTimerExecutionRepeat() throws InterruptedException {
              ProcessDefinition processDefinition = ProcessDefinition
              .parseXmlString("<process-definition>"
              + " "
              + " System.out.println(\"this script is entering node\"+node);"
              + " "

              + " <start-state>"
              + " "
              + " </start-state>"

              + " <task-node name='callBack'>"
              + " <timer name='reminder'"
              + " duedate='3 seconds'"
              + " transition='toCallBack'/>"

              + " "
              + " "

              + " "
              + " "
              + " </task-node>"

              + " <end-state name='end'/>"
              + "</process-definition>");


              processDefinition = saveAndReload(processDefinition);
              ProcessInstance processInstance = new ProcessInstance(processDefinition);

              processInstance.signal();
              jbpmSession.getGraphSession().saveProcessInstance(processInstance);
              newTransaction();
              commitAndCloseSession();

              for(int x = 0; x< 20; x++){

              new SchedulerThread().executeTimers();
              System.out.println("CurrentNode= " + processInstance.getRootToken().getNode().getName());
              Thread.sleep(1000);
              }
              }
              }


              ---

              09:51:57,875 DEBUG GraphElement : event 'process-start' on 'ProcessDefinition(19fe451)' for 'Token(/)'
              09:51:57,890 DEBUG GraphElement : event 'before-signal' on 'StartState(147917a)' for 'Token(/)'
              09:51:57,906 DEBUG GraphElement : event 'node-leave' on 'StartState(147917a)' for 'Token(/)'
              09:51:57,906 DEBUG GraphElement : event 'transition' on 'Transition(102b2b6)' for 'Token(/)'
              09:51:57,906 DEBUG GraphElement : event 'node-enter' on 'TaskNode(callBack)' for 'Token(/)'
              09:51:57,921 DEBUG GraphElement : executing action 'CreateTimerAction(111ded2)'
              09:51:57,937 DEBUG GraphElement : executing action 'Script(19f03d7)'
              09:51:57,937 DEBUG Script : script input: {taskInstance=null, node=TaskNode(callBack), token=Token(/), task=null, executionContext=ExecutionContext[Token(/)]}
              this script is entering nodeTaskNode(callBack)
              09:51:58,062 DEBUG Script : script output: {}
              09:51:58,078 DEBUG GraphElement : event 'task-create' on 'Task(calling back)' for 'Token(/)'
              09:51:58,078 DEBUG GraphElement : event 'after-signal' on 'StartState(147917a)' for 'Token(/)'
              09:51:58,093 DEBUG SchedulerSession : saving timer timer(reminder,09:52:00,921)
              09:51:58,093 DEBUG JbpmSessionFactory : building singleton JbpmSessionFactory
              09:51:58,093 DEBUG JbpmSessionFactory : using the default hibernate configuration file: hibernate.cfg.xml
              09:51:59,046 DEBUG JbpmSessionFactory : building hibernate session factory
              09:51:59,765 DEBUG SchedulerThread : checking for timers
              09:52:00,015 DEBUG SchedulerThread : found timer timer(reminder,09:52:00,921)
              CurrentNode= callBack
              09:52:01,015 DEBUG SchedulerThread : checking for timers
              09:52:01,046 DEBUG SchedulerThread : found timer timer(reminder,09:52:00,921)
              09:52:01,046 DEBUG SchedulerThread : executing timer 'timer(reminder,09:52:00,921)'
              09:52:01,093 DEBUG GraphElement : event 'before-signal' on 'TaskNode(callBack)' for 'Token(/)'
              09:52:01,125 DEBUG GraphElement : event 'node-leave' on 'TaskNode(callBack)' for 'Token(/)'
              09:52:01,125 DEBUG GraphElement : executing action 'CancelTimerAction(11a0d35)'
              09:52:01,125 DEBUG GraphElement : event 'transition' on 'Transition(toCallBack)' for 'Token(/)'
              09:52:01,140 DEBUG GraphElement : event 'node-enter' on 'TaskNode(callBack)' for 'Token(/)'
              09:52:01,140 DEBUG GraphElement : executing action 'CreateTimerAction(bafdff)'
              09:52:01,140 DEBUG GraphElement : executing action 'Script(1a9f87c)'
              09:52:01,156 DEBUG Script : script input: {taskInstance=null, node=TaskNode(callBack), token=Token(/), task=null, executionContext=ExecutionContext[Token(/)]}
              this script is entering nodeTaskNode(callBack)
              09:52:01,171 DEBUG Script : script output: {}
              09:52:01,187 DEBUG GraphElement : event 'task-create' on 'Task(calling back)' for 'Token(/)'
              09:52:01,187 DEBUG GraphElement : event 'after-signal' on 'TaskNode(callBack)' for 'Token(/)'
              09:52:01,187 DEBUG SchedulerThread : deleting timer 'timer(reminder,09:52:00,921)'
              CurrentNode= callBack
              09:52:02,203 DEBUG SchedulerThread : checking for timers
              CurrentNode= callBack
              09:52:03,203 DEBUG SchedulerThread : checking for timers
              CurrentNode= callBack
              09:52:04,203 DEBUG SchedulerThread : checking for timers
              CurrentNode= callBack
              09:52:05,203 DEBUG SchedulerThread : checking for timers
              CurrentNode= callBack
              09:52:06,203 DEBUG SchedulerThread : checking for timers
              CurrentNode= callBack

              • 4. Re: JBPM executor example
                koder1

                sorry for spam, i try again,

                in this simple testcase (made after a db test from jbpm.tests), the timer is execute and deleted only the first time processinstance is executed (see log at the end).
                How should this for loop look like, to make the timers be executed properly?

                ---

                public class TimerTest extends AbstractDbTestCase {
                
                
                
                public void testTimerExecutionRepeat() throws InterruptedException {
                 ProcessDefinition processDefinition = ProcessDefinition
                 .parseXmlString("<process-definition>"
                 + " <event type='node-enter'>"
                 + " <script>System.out.println(\"this script is entering node\"+node);</script>"
                 + " </event>"
                
                 + " <start-state>"
                 + " <transition to='callBack' />"
                 + " </start-state>"
                
                 + " <task-node name='callBack'>"
                 + " <timer name='reminder'"
                 + " duedate='3 seconds'"
                 + " transition='toCallBack'/>"
                
                 + " <transition name='toEnd' to='end'/>"
                 + " <transition name='toCallBack' to='callBack'/>"
                
                 + " <task name='calling back'>"
                 + " </task>"
                 + " </task-node>"
                
                 + " <end-state name='end'/>"
                 + "</process-definition>");
                
                
                 processDefinition = saveAndReload(processDefinition);
                 ProcessInstance processInstance = new ProcessInstance(processDefinition);
                
                 processInstance.signal();
                jbpmSession.getGraphSession().saveProcessInstance(processInstance);
                 newTransaction();
                 commitAndCloseSession();
                
                 for(int x = 0; x< 20; x++){
                
                 new SchedulerThread().executeTimers();
                 System.out.println("CurrentNode= " + processInstance.getRootToken().getNode().getName());
                 Thread.sleep(1000);
                 }
                 }
                }
                


                ---

                09:51:57,875 DEBUG GraphElement : event 'process-start' on 'ProcessDefinition(19fe451)' for 'Token(/)'
                09:51:57,890 DEBUG GraphElement : event 'before-signal' on 'StartState(147917a)' for 'Token(/)'
                09:51:57,906 DEBUG GraphElement : event 'node-leave' on 'StartState(147917a)' for 'Token(/)'
                09:51:57,906 DEBUG GraphElement : event 'transition' on 'Transition(102b2b6)' for 'Token(/)'
                09:51:57,906 DEBUG GraphElement : event 'node-enter' on 'TaskNode(callBack)' for 'Token(/)'
                09:51:57,921 DEBUG GraphElement : executing action 'CreateTimerAction(111ded2)'
                09:51:57,937 DEBUG GraphElement : executing action 'Script(19f03d7)'
                09:51:57,937 DEBUG Script : script input: {taskInstance=null, node=TaskNode(callBack), token=Token(/), task=null, executionContext=ExecutionContext[Token(/)]}
                this script is entering nodeTaskNode(callBack)
                09:51:58,062 DEBUG Script : script output: {}
                09:51:58,078 DEBUG GraphElement : event 'task-create' on 'Task(calling back)' for 'Token(/)'
                09:51:58,078 DEBUG GraphElement : event 'after-signal' on 'StartState(147917a)' for 'Token(/)'
                09:51:58,093 DEBUG SchedulerSession : saving timer timer(reminder,09:52:00,921)
                09:51:58,093 DEBUG JbpmSessionFactory : building singleton JbpmSessionFactory
                09:51:58,093 DEBUG JbpmSessionFactory : using the default hibernate configuration file: hibernate.cfg.xml
                09:51:59,046 DEBUG JbpmSessionFactory : building hibernate session factory
                09:51:59,765 DEBUG SchedulerThread : checking for timers
                09:52:00,015 DEBUG SchedulerThread : found timer timer(reminder,09:52:00,921)
                CurrentNode= callBack
                09:52:01,015 DEBUG SchedulerThread : checking for timers
                09:52:01,046 DEBUG SchedulerThread : found timer timer(reminder,09:52:00,921)
                09:52:01,046 DEBUG SchedulerThread : executing timer 'timer(reminder,09:52:00,921)'
                09:52:01,093 DEBUG GraphElement : event 'before-signal' on 'TaskNode(callBack)' for 'Token(/)'
                09:52:01,125 DEBUG GraphElement : event 'node-leave' on 'TaskNode(callBack)' for 'Token(/)'
                09:52:01,125 DEBUG GraphElement : executing action 'CancelTimerAction(11a0d35)'
                09:52:01,125 DEBUG GraphElement : event 'transition' on 'Transition(toCallBack)' for 'Token(/)'
                09:52:01,140 DEBUG GraphElement : event 'node-enter' on 'TaskNode(callBack)' for 'Token(/)'
                09:52:01,140 DEBUG GraphElement : executing action 'CreateTimerAction(bafdff)'
                09:52:01,140 DEBUG GraphElement : executing action 'Script(1a9f87c)'
                09:52:01,156 DEBUG Script : script input: {taskInstance=null, node=TaskNode(callBack), token=Token(/), task=null, executionContext=ExecutionContext[Token(/)]}
                this script is entering nodeTaskNode(callBack)
                09:52:01,171 DEBUG Script : script output: {}
                09:52:01,187 DEBUG GraphElement : event 'task-create' on 'Task(calling back)' for 'Token(/)'
                09:52:01,187 DEBUG GraphElement : event 'after-signal' on 'TaskNode(callBack)' for 'Token(/)'
                09:52:01,187 DEBUG SchedulerThread : deleting timer 'timer(reminder,09:52:00,921)'
                CurrentNode= callBack
                09:52:02,203 DEBUG SchedulerThread : checking for timers
                CurrentNode= callBack
                09:52:03,203 DEBUG SchedulerThread : checking for timers
                CurrentNode= callBack
                09:52:04,203 DEBUG SchedulerThread : checking for timers
                CurrentNode= callBack
                09:52:05,203 DEBUG SchedulerThread : checking for timers
                CurrentNode= callBack
                09:52:06,203 DEBUG SchedulerThread : checking for timers
                CurrentNode= callBack