7 Replies Latest reply on Jan 12, 2007 3:45 AM by Ronald van Kuijk

    How to create a Timer on a task-node?

    Sri Harsha D A Newbie

      I have a task node in which i would like execute the handler for every 10 seconds.
      My Process deifinition is

       <start-state name="start">
       <task>
       </task>
       <transition name="" to="Initiate Transcode"></transition>
       </start-state>
       <node name="Initiate Transcode">
       <action name="transcodeContent" class="VideoTranscodeHandler">
       </action>
       <transition name="monitorTranscode" to="Monitor Transcodnig"></transition>
       </node>
       <task-node name="Monitor Transcodnig" async="true">
      <task>
       <timer duedate="20 seconds" name="TranscodeMonitorTimer" repeat="10 seconds">
       <action class="VideoTranscodeMonitorHandler">
       </action>
       </timer>
      </task>
       <transition name="requestForApproval" to="Submit for Approval"></transition>
       </task-node>
      


      When i signal, it is executing the first node but the handler in the timer is not getting executed.
      Here is the handler code
      public class VideoTranscodeMonitorHandler implements ActionHandler {
      
       private static final long serialVersionUID = 1L;
       private static final Logger logger = CommonLogger.getInstance("com.ge.nbc.content.process.video.handler.VideoTranscodeMonitorHandler");
      
       public void execute(ExecutionContext executionContext) throws Exception {
       logger.info("###############################################");
       logger.info("### this is VideoTranscodeMonitorHandler for the content ");
       logger.info("###############################################");
      
      


      Is there anything that iam missing? Should we explicitly create a timer and invoke before/after the signal to fire a timer event?

      Regards
      Harsha

        • 1. Re: How to create a Timer on a task-node?
          Ansgar Thobe Newbie

          Is the timer created in the database?
          If so, make sure that the scheduler is running.

          • 2. Re: How to create a Timer on a task-node?
            Sri Harsha D A Newbie

            Yes the timer is getting created in JBPM_TIMER table. But the handler is not getting executed. Iam throwing back the exception that is caught in the handler. So i see the following exception in the JBPM_TIMER table.

            java.lang.Exception: Exception in the VideoTranscodeMonitorHandler org.jbpm.bytes.ByteArray$$EnhancerByCGLIB$$afee7672
             at com.ge.nbc.content.process.video.handler.VideoTranscodeMonitorHandler.execute(VideoTranscodeMonitorHandler.java:55)
             at org.jbpm.graph.def.Action.execute(Action.java:123)
             at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
             at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
             at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
             at java.lang.reflect.Method.invoke(Method.java:585)
             at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.invoke(CGLIBLazyInitializer.java:185)
             at org.jbpm.graph.def.Action$$EnhancerByCGLIB$$9c43d20f.execute(<generated>)
             at org.jbpm.scheduler.exe.Timer.execute(Timer.java:84)
             at org.jbpm.scheduler.impl.SchedulerThread.executeTimers(SchedulerThread.java:118)
             at org.jbpm.scheduler.impl.SchedulerThread.run(SchedulerThread.java:70)
            


            How do i make sure that the Scheduler is running. Looking at the error trace i think its running.

            Is there anything that iam missing.

            Regards
            Harsha

            • 3. Re: How to create a Timer on a task-node?
              Ansgar Thobe Newbie

              If the scheduler start you should see something like this:

              21:22:44,375 DEBUG [Scheduler] starting the scheduler


              And after that, the scheduler should check the database for timer every 5 seconds ( i think 5 seconds is the default value, but i am not sure...) and you can see this:
              21:24:12,328 DEBUG [SchedulerThread] checking for timers


              Otherwise, you must start the scheduler.
              You could do this in the web.xml. there you must config the scheduler simular to this ( i don t use the scheduler servlet, so i don t know, if this is exactly right).
              <servlet>
               <servlet-name>JbpmThreadsServlet</servlet-name>
               <servlet-class>org.jbpm.web.JbpmThreadsServlet</servlet-class>
               <load-on-startup>1</load-on-startup>
               </servlet>
               <servlet-mapping>
               <servlet-name>JbpmThreadsServlet</servlet-name>
               <url-pattern>/threads</url-pattern>
               </servlet-mapping>

              Alternative you could start the main method of the org.jbpm.scheduler.impl.SchedulerThread.
              I do this with java reflection in a java class, but i have no big java experience, so this is may not the best way, but it works... :-)
              String[] nargs = {"4000", "40" ,"dd/MM/yyyy HH:mm:ss"};
               Class sched = Class.forName( "org.jbpm.scheduler.impl.SchedulerMain");
               Method[] methods = sched.getMethods();
               logger.info("Die methoden: " +methods.toString());
               Method methode = sched.getMethod(
               "main" , nargs.getClass());
               logger.info("Die methode: " + methode.toString());
               methode.invoke( null, new Object[]{nargs} );
              


              Regards
              asmo


              • 4. Re: How to create a Timer on a task-node?
                Ronald van Kuijk Master

                is it me or??????

                according to the stacktrace the scheduler IS running (just like mentioned) AND the handler is called since it THROWS AN EXCEPTION (just like mentioned)....

                So the problem is not that the handler is not getting called, but that it throws an exception...

                Correct me if I'm wrong, otherwise pay better attention in the future... oh... and better formulate the subject

                • 5. Re: How to create a Timer on a task-node?
                  Ansgar Thobe Newbie

                  you are right.
                  i try to pay better attention next time....

                  • 6. Re: How to create a Timer on a task-node?
                    Sri Harsha D A Newbie

                    The scheduler thread is running and the exception is because of an older version of the Handler that was deployed. So i cleaned up the JBPM tables and deployed the handlers again.
                    It worked.

                    Thanks for all the help.

                    Regards
                    Harsha

                    • 7. Re: How to create a Timer on a task-node?
                      Ronald van Kuijk Master

                      I did not want to offend anyone, jsut save us all from spending to much time on issues that aren't realy there.