1 2 Previous Next 21 Replies Latest reply on Nov 8, 2011 10:09 PM by Donald Walters

    MapBasedPersistenceTest issue

    Donald Walters Newbie

      I am tring to use the MapPersistence instead of a database underlying the JPAKnowledgeService but I keep getting an exception. I have done the setup according to the MapBasedPersistenceTest

       

      What could I be doing wrong here?

       

      StatefulKnowledgeSession ksession = newStatefulKnowledgeSession();

      WorkflowProcessInstance processInstance = (WorkflowProcessInstance) ksession.startProcess("ServiceProcess", params); //<==exception

       

      public static StatefulKnowledgeSession newStatefulKnowledgeSession() {

       

              KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();

              kbuilder.add(ResourceFactory.newClassPathResource("workflowtest/MyProcess.xml"), ResourceType.BPMN2);

       

              KnowledgeBase kbase = kbuilder.newKnowledgeBase();

       

              EnvironmentBuilder envBuilder = new KnowledgeSessionStorageEnvironmentBuilder(storage);

              Environment env = KnowledgeBaseFactory.newEnvironment();

              env.set(EnvironmentName.TRANSACTION_MANAGER, envBuilder.getTransactionManager());

              env.set(EnvironmentName.PERSISTENCE_CONTEXT_MANAGER, envBuilder.getPersistenceContextManager());

       

              return JPAKnowledgeService.newStatefulKnowledgeSession(kbase, null, env);

      }

       

      ===================================================

      java.lang.ClassCastException: org.drools.persistence.map.MapPersistenceContextManager cannot be cast to org.jbpm.persistence.ProcessPersistenceContextManager

                at org.jbpm.persistence.processinstance.JPAProcessInstanceManager.addProcessInstance(JPAProcessInstanceManager.java:32)

                at org.jbpm.process.instance.AbstractProcessInstanceFactory.createProcessInstance(AbstractProcessInstanceFactory.java:36)

                at org.jbpm.process.instance.ProcessRuntimeImpl.startProcess(ProcessRuntimeImpl.java:168)

                at org.jbpm.process.instance.ProcessRuntimeImpl.createProcessInstance(ProcessRuntimeImpl.java:140)

                at org.jbpm.process.instance.ProcessRuntimeImpl.startProcess(ProcessRuntimeImpl.java:121)

                at org.drools.common.AbstractWorkingMemory.startProcess(AbstractWorkingMemory.java:1095)

                at org.drools.impl.StatefulKnowledgeSessionImpl.startProcess(StatefulKnowledgeSessionImpl.java:306)

                at org.drools.command.runtime.process.StartProcessCommand.execute(StartProcessCommand.java:119)

                at org.drools.command.runtime.process.StartProcessCommand.execute(StartProcessCommand.java:38)

                at org.drools.persistence.SingleSessionCommandService.execute(SingleSessionCommandService.java:292)

                at org.drools.command.impl.CommandBasedStatefulKnowledgeSession.startProcess(CommandBasedStatefulKnowledgeSession.java:222)

        • 1. Re: MapBasedPersistenceTest issue
          Donald Walters Newbie

          I found the issue. I was using the drools MapPersistenceContext instead of the sample from

          https://github.com/krisv/jbpm/blob/master/jbpm-persistence-jpa/src/test/java/org/jbpm/persistence/map/impl/MapBasedPersistenceTest.java

           

          But now I am getting the following error below sometimes. What could have caused this?

           

          java.lang.NullPointerException

                    at org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl.setState(WorkflowProcessInstanceImpl.java:251)

                    at org.jbpm.marshalling.impl.AbstractProcessInstanceMarshaller.readProcessInstance(AbstractProcessInstanceMarshaller.java:382)

                    at org.jbpm.persistence.processinstance.ProcessInstanceInfo.getProcessInstance(ProcessInstanceInfo.java:133)

                    at org.jbpm.persistence.processinstance.JPAProcessInstanceManager.getProcessInstance(JPAProcessInstanceManager.java:64)

                    at org.jbpm.process.instance.ProcessRuntimeImpl.getProcessInstance(ProcessRuntimeImpl.java:190)

                    at org.drools.common.AbstractWorkingMemory.getProcessInstance(AbstractWorkingMemory.java:1113)

                    at org.drools.impl.StatefulKnowledgeSessionImpl.getProcessInstance(StatefulKnowledgeSessionImpl.java:283)

                    at org.jbpm.persistence.processinstance.JPASignalManager.signalEvent(JPASignalManager.java:24)

                    at org.jbpm.process.instance.ProcessRuntimeImpl.signalEvent(ProcessRuntimeImpl.java:355)

                    at org.drools.impl.StatefulKnowledgeSessionImpl.signalEvent(StatefulKnowledgeSessionImpl.java:321)

                    at org.drools.command.runtime.process.SignalEventCommand.execute(SignalEventCommand.java:91)

                    at org.drools.persistence.SingleSessionCommandService.execute(SingleSessionCommandService.java:292)

                    at org.drools.command.impl.CommandBasedStatefulKnowledgeSession.signalEvent(CommandBasedStatefulKnowledgeSession.java:200)

          • 2. Re: MapBasedPersistenceTest issue
            Donald Walters Newbie

            Just to give a bit of background on what I am trying to achieve. I am trying to use the framework in a high performance application. eg more than 200 transactions per second. In order to achieve this I need to eliminate the need for a database in the backend of the framework and use a in memory solution. I do not want to use a database but a cache or the map solution is more acceptable. I used the map implementation above and it work for a few transactions but then after a little while for some signalEvents i start getting that error. I am not sure what it means but it seems like an issue setting a state (do know which state). I really need help on this.

            • 3. Re: MapBasedPersistenceTest issue
              Mauricio Salatino Master

              Hi Donalds, before going deep with the analysis.. are you sure that you need persistence? If you want process 200 tx per second you will probably don't want to spend time persisting the state and just run the activities.

              Can you explain a little bit the process structure and the task that you want to execute.

              Cheers

              • 4. Re: MapBasedPersistenceTest issue
                Donald Walters Newbie

                Hi Mauricio,

                 

                Basically, there is main flow that the user can access, which leads to a interruptcatchevent, like below. Once it reaches this point then it will wait for the users input from which i would retrieve the sessionid from an external cache then trigger the signalevent. I was under the impression that in order to signal the event I would have to use some storage to persist the state of the workitem, processinstance and session. Take in consideration that the event can be signal at some other time (whenever). Also, I see that the time is not fired even though no response is received. So, basically, I want to achieve; wait on an input or expiry if none receive in a specified time.

                 

                <sequenceFlow id="case-wait4_pg" sourceRef="wait4" targetRef="wait4_pg"/>

                <parallelGateway id="wait4_pg" name="wait4_pg" gatewayDirection="Diverging"/>

                <sequenceFlow id="case-wait4_signal" sourceRef="wait4_pg" targetRef="wait4_signal"/>

                <sequenceFlow id="case-wait4_timer" sourceRef="wait4_pg" targetRef="wait4_timer"/>

                <intermediateCatchEvent id="wait4_signal" name="wait4_signal">

                <dataOutput id="wait4_event_Output" name="event"/>

                <dataOutputAssociation>

                <sourceRef>wait4_event_Output</sourceRef>

                <targetRef>processItem</targetRef>

                </dataOutputAssociation>

                <outputSet>

                <dataOutputRefs>wait4_event_Output</dataOutputRefs>

                </outputSet>

                <signalEventDefinition signalRef="wait4_signal_event"/>

                </intermediateCatchEvent>

                <intermediateCatchEvent id="wait4_timer" name="wait4_timer">

                <timerEventDefinition>

                <timeDuration>3m</timeDuration>

                </timerEventDefinition>

                </intermediateCatchEvent>

                <sequenceFlow id="case-wait4_cleanup" sourceRef="wait4_timer" targetRef="wait4_end"/>

                <endEvent id="wait4_end" name="wait4_end">

                <terminateEventDefinition/>

                </endEvent>

                • 5. Re: MapBasedPersistenceTest issue
                  Maciej Swiderski Master

                  Donald, thanks for giving some background and your requirements.

                   

                  Mauricio has a point here. In your case persistance is not really needed and as far as I know you do not need to have persistance to work with events, just make sure you utilize the same session instances for all interactions for a particular process instance.

                   

                  HTH

                  • 6. Re: MapBasedPersistenceTest issue
                    Donald Walters Newbie

                    thanks guys. I have removed the persistence and done the following.

                     

                     

                     

                    private static final ConcurrentHashMap<Integer, StatefulKnowledgeSession> ksessions = new ConcurrentHashMap<Integer, StatefulKnowledgeSession>();

                     

                    .....

                    StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();//CacheKnowledgeService.newStatefulKnowledgeSession(kbase);

                    ksession.getWorkItemManager().registerWorkItemHandler(

                                    "Service Task", new ProcessExecutionHandler(helper));

                    ksessions.put(ksession.getId(), ksession);

                     

                    .......

                    StatefulKnowledgeSession ksession = ksessions.get(sessionId);

                    ksession.getWorkItemManager().registerWorkItemHandler(

                                    "Service Task", new ProcessExecutionHandler(helper));

                     

                    that seems to work but will the session still be in the map after total completion? I would have to have a mechanism to remove it, I assume?

                    Also, I am still have the issue where the timer is not triggered.

                    • 7. Re: MapBasedPersistenceTest issue
                      Maciej Swiderski Master

                      Yes, you should dispose the session once you're done with all the processing.

                       

                      Regardig timer, I think you need to call fireAllRules method on the session to trigger timer.

                       

                      HTH

                      • 8. Re: MapBasedPersistenceTest issue
                        Donald Walters Newbie

                        but if the user never sends a response then how will i know to fireAllRules for session? How will I know if it is expired?

                        Also, when I was using the persistence this was not the case. The events fired without my intervention.

                        • 9. Re: MapBasedPersistenceTest issue
                          Maciej Swiderski Master

                          I meant that as soon as timer node is entered fireAllRules should be invoked so the timer will be activated. This is what I observed when working with timers.

                          • 10. Re: MapBasedPersistenceTest issue
                            Mauricio Salatino Master

                            Yes.. you can use the fire until halt method in a separate thread for each session and they will become reactive, so each time that a rules gets activated it will be fired.

                            Cheers

                            • 11. Re: MapBasedPersistenceTest issue
                              Donald Walters Newbie

                              The timer still doesn't fire even after doing the following.

                               

                              StatefulKnowledgeSession session = ExecutionController.getSession(sessionId);

                              if (session != null) {

                                       session.fireUntilHalt();

                              }

                              • 12. Re: MapBasedPersistenceTest issue
                                Mauricio Salatino Master

                                you need to put the fireUntilHalt in another thread

                                • 13. Re: MapBasedPersistenceTest issue
                                  Donald Walters Newbie

                                  I have the following thread running but still nothing.

                                   

                                        private static class SessionExpirator extends Thread{

                                          @Override

                                          public void run() {

                                              while(RunningStatus.isRunning()){

                                                  Enumeration<Integer> keys = ksessions.keys();

                                                  while(keys.hasMoreElements()){

                                                      StatefulKnowledgeSession sess = getSession(keys.nextElement());

                                                      sess.fireUntilHalt();

                                                  }

                                              }

                                             

                                              try{

                                                  Thread.sleep(1000 * 60);

                                              }catch(Exception e){}

                                          }

                                   

                                  In addition, I get the following when completing the task before the timer event.

                                   

                                  java.util.concurrent.RejectedExecutionException

                                            at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(Unknown Source)

                                            at java.util.concurrent.ThreadPoolExecutor.reject(Unknown Source)

                                            at java.util.concurrent.ScheduledThreadPoolExecutor.delayedExecute(Unknown Source)

                                            at java.util.concurrent.ScheduledThreadPoolExecutor.schedule(Unknown Source)

                                            at org.drools.time.impl.JDKTimerService.schedule(JDKTimerService.java:115)

                                            at org.drools.time.impl.JDKTimerService.scheduleJob(JDKTimerService.java:80)

                                            at org.jbpm.process.instance.timer.TimerManager.registerTimer(TimerManager.java:61)

                                            at org.jbpm.workflow.instance.node.TimerNodeInstance.internalTrigger(TimerNodeInstance.java:67)

                                            at org.jbpm.workflow.instance.impl.NodeInstanceImpl.trigger(NodeInstanceImpl.java:122)

                                            at org.jbpm.workflow.instance.impl.NodeInstanceImpl.triggerConnection(NodeInstanceImpl.java:185)

                                            at org.jbpm.workflow.instance.impl.NodeInstanceImpl.triggerCompleted(NodeInstanceImpl.java:150)

                                            at org.jbpm.workflow.instance.node.SplitInstance.internalTrigger(SplitInstance.java:61)

                                            at org.jbpm.workflow.instance.impl.NodeInstanceImpl.trigger(NodeInstanceImpl.java:122)

                                            at org.jbpm.workflow.instance.impl.NodeInstanceImpl.triggerConnection(NodeInstanceImpl.java:185)

                                            at org.jbpm.workflow.instance.impl.NodeInstanceImpl.triggerCompleted(NodeInstanceImpl.java:150)

                                            at org.jbpm.workflow.instance.impl.ExtendedNodeInstanceImpl.triggerCompleted(ExtendedNodeInstanceImpl.java:47)

                                            at org.jbpm.workflow.instance.node.StateBasedNodeInstance.triggerCompleted(StateBasedNodeInstance.java:162)

                                            at org.jbpm.workflow.instance.node.StateBasedNodeInstance.triggerCompleted(StateBasedNodeInstance.java:143)

                                            at org.jbpm.workflow.instance.node.WorkItemNodeInstance.triggerCompleted(WorkItemNodeInstance.java:239)

                                            at org.jbpm.workflow.instance.node.WorkItemNodeInstance.workItemCompleted(WorkItemNodeInstance.java:301)

                                            at org.jbpm.workflow.instance.node.WorkItemNodeInstance.signalEvent(WorkItemNodeInstance.java:277)

                                            at org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl.signalEvent(WorkflowProcessInstanceImpl.java:333)

                                            at org.drools.process.instance.impl.DefaultWorkItemManager.completeWorkItem(DefaultWorkItemManager.java:116)

                                  • 14. Re: MapBasedPersistenceTest issue
                                    Donald Walters Newbie

                                    Hi guys,

                                     

                                    so far the issue of the persistence in memory has been resolved but I am still having the error above and the timers not being triggered.

                                    Any help on this?

                                     

                                    Regards

                                    1 2 Previous Next