3 Replies Latest reply on Nov 28, 2014 1:32 AM by Maciej Swiderski

    Using Timer task (of Intermediate catch event section) is throwing an exception

    Santhosh Bhat Newbie

      My workflow is something like this  [start --> workItemTask --> Timer --> scriptTask --> anotherWorkItemTask --> continued... ] . I am using Timer to basically invoke scriptTask for sometime, every 1 second, until some value changes (I am trying to simulate a while loop here).

       

      The timer task has 2 sections

       

      1. Time Duration  - for which i have given a value of 0d0h0m1s0ms

      2. Time Cycle - for which I have given a value of 0d0h0m1s0ms

       

      Now I expect the script task to be invoked, after a delay of 1 second, for every 1 second. This is not happening. Instead, when this point reaches, JBPM is throwing below exception

       

      java.lang.IllegalStateException: java.lang.reflect.InvocationTargetException

        at org.drools.persistence.jpa.KnowledgeStoreServiceImpl.buildCommandService(KnowledgeStoreServiceImpl.java:164)

        at org.drools.persistence.jpa.KnowledgeStoreServiceImpl.newKieSession(KnowledgeStoreServiceImpl.java:70)

        at org.drools.persistence.jpa.KnowledgeStoreServiceImpl.newKieSession(KnowledgeStoreServiceImpl.java:39)

        at org.kie.internal.persistence.jpa.JPAKnowledgeService.newStatefulKnowledgeSession(JPAKnowledgeService.java:121)

        at org.jbpm.runtime.manager.impl.factory.JPASessionFactory.newKieSession(JPASessionFactory.java:42)

        at org.jbpm.runtime.manager.impl.PerRequestRuntimeManager.getRuntimeEngine(PerRequestRuntimeManager.java:66)

        at org.jbpm.process.core.timer.impl.GlobalTimerService.getCommandService(GlobalTimerService.java:208)

        at org.jbpm.process.core.timer.impl.GlobalTimerService.getCommandService(GlobalTimerService.java:192)

        at org.jbpm.persistence.timer.GlobalJpaTimerJobInstance.call(GlobalJpaTimerJobInstance.java:67)

        at org.jbpm.persistence.timer.GlobalJpaTimerJobInstance.call(GlobalJpaTimerJobInstance.java:46)

        at java.util.concurrent.FutureTask.run(FutureTask.java:262)

        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:178)

        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:292)

        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)

        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)

        at java.lang.Thread.run(Thread.java:745)

      Caused by: java.lang.reflect.InvocationTargetException

        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)

        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

        at java.lang.reflect.Constructor.newInstance(Constructor.java:526)

        at org.drools.persistence.jpa.KnowledgeStoreServiceImpl.buildCommandService(KnowledgeStoreServiceImpl.java:150)

        ... 15 more

      Caused by: java.lang.IllegalArgumentException: Timer service 'new org.jbpm.process.core.timer.impl.RegisteredTimerServiceDelegate("default-per-request-timerServiceId")' not found

        at org.drools.core.SessionConfiguration.newTimerService(SessionConfiguration.java:495)

        at org.drools.core.time.TimerServiceFactory.getTimerService(TimerServiceFactory.java:27)

        at org.drools.core.impl.StatefulKnowledgeSessionImpl.<init>(StatefulKnowledgeSessionImpl.java:366)

        at org.drools.core.impl.StatefulKnowledgeSessionImpl.<init>(StatefulKnowledgeSessionImpl.java:278)

        at org.drools.core.common.PhreakWorkingMemoryFactory.createWorkingMemory(PhreakWorkingMemoryFactory.java:21)

        at org.drools.core.impl.KnowledgeBaseImpl.newStatefulSession(KnowledgeBaseImpl.java:1304)

        at org.drools.core.impl.KnowledgeBaseImpl.newStatefulSession(KnowledgeBaseImpl.java:1289)

        at org.drools.core.impl.KnowledgeBaseImpl.newStatefulKnowledgeSession(KnowledgeBaseImpl.java:292)

        at org.drools.core.impl.KnowledgeBaseImpl.newKieSession(KnowledgeBaseImpl.java:378)

        at org.drools.persistence.SingleSessionCommandService.initNewKnowledgeSession(SingleSessionCommandService.java:125)

        at org.drools.persistence.SingleSessionCommandService.<init>(SingleSessionCommandService.java:92)

        ... 20 more

      Caused by: [Error: could not instantiate class: null]

      [Near : {... new org.jbpm.process.core.timer.im ....}]

                       ^

      [Line: 1, Column: 5]

        at org.mvel2.ast.NewObjectNode.getReducedValue(NewObjectNode.java:307)

        at org.mvel2.MVELInterpretedRuntime.parseAndExecuteInterpreted(MVELInterpretedRuntime.java:106)

        at org.mvel2.MVELInterpretedRuntime.parse(MVELInterpretedRuntime.java:49)

        at org.mvel2.MVEL.eval(MVEL.java:92)

        at org.drools.core.util.MVELSafeHelper$RawMVELEvaluator.eval(MVELSafeHelper.java:406)

        at org.drools.core.SessionConfiguration.newTimerService(SessionConfiguration.java:493)

        ... 30 more

      Caused by: java.lang.reflect.InvocationTargetException

        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)

        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

        at java.lang.reflect.Constructor.newInstance(Constructor.java:526)

        at org.mvel2.ast.NewObjectNode.getReducedValue(NewObjectNode.java:278)

        ... 35 more

      Caused by: java.lang.IllegalStateException: TimerService with key default-per-request-timerServiceId was not found in the registry

        at org.jbpm.process.core.timer.impl.RegisteredTimerServiceDelegate.<init>(RegisteredTimerServiceDelegate.java:59)

        ... 40 more

       

      Googling did not help. So i am posting this here. Doesn't timer task comes by default with JBPM runtime? Do we need to add something through the API ? Here's how I am creating the runtime

       

         EntityManagerFactory emf = Persistence.createEntityManagerFactory("org.jbpm.services.task");

         RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().entityManagerFactory(emf)

         .userGroupCallback(new JBossUserGroupCallbackImpl(getUserGroupProperties()))

         .addAsset(ResourceFactory.newUrlResource(workflowFile), ResourceType.BPMN2)

         .get();

             // "workflowFile" refers to the absolute URL to the .bpmn2 file in the system. Eg: file:///c:/test.bpmn2

       

         RuntimeManager runtimeManager = RuntimeManagerFactory.Factory.get().newPerRequestRuntimeManager(environment);

         RuntimeEngine runtime = runtimeManager.getRuntimeEngine(EmptyContext.get());

         KieSession ksession = runtime.getKieSession();

              ksession.startProcess(...);

        • 1. Re: Using Timer task (of Intermediate catch event section) is throwing an exception
          Maciej Swiderski Master

          this error:

          TimerService with key default-per-request-timerServiceId was not found in the registry

          means there is no runtime manager available called 'default-per-request' as when it is created it will register it's timer service. So please double check runtime manager was not closed after process was started.

           

          Not sure what version you use but might be worth checking with latest final (6.1.0) or release candidate (CR2) of 6.2.0

           

          HTH

          • 2. Re: Re: Using Timer task (of Intermediate catch event section) is throwing an exception
            Santhosh Bhat Newbie

            Thanks for your answer.. I have now changed the runtime manager to be singleton, and timer is not throwing the exception.

             

            RuntimeManager runtimeManager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);


            Regarding second part of my question (while loop using timer)

             

            I have created a timerTask with following definition.

             

            <bpmn2:timerEventDefinition id="TimerEventDefinition_1">

                    <bpmn2:timeCycle xsi:type="bpmn2:tFormalExpression" id="FormalExpression_158" language="http://www.java.com/java">1s###1s</bpmn2:timeCycle>

              </bpmn2:timerEventDefinition>

             

            this means that, The timer will have a delay of 1s before moving the execution to the next task, and it will repeatedly execute the next task, for 1second each. Am I correct?

             

            This is not happening. In my case, the timer gets fired after a delay of 1s, but continues to execute the susequent tasks, without repeating the cycle (loop). Can you please help me with this?

            • 3. Re: Using Timer task (of Intermediate catch event section) is throwing an exception
              Maciej Swiderski Master

              timer cycle will trigger subsequent nodes every 1 second, meaning all activities that follow the timer will be triggered multiple times. Depending what is after timer it might be the case that process instance reaches the end event that terminates the process instance and that's why timer is not firing anymore.

              But without seeing the actual process I cannot tell for sure

               

              HTH