6 Replies Latest reply on Jun 3, 2014 4:35 AM by bl91

    jBPM 6 Session restore

    bl91

      Hi all, I'm quite new to the jBPM world. However I'm trying to develop a basic project to try some features of this engine.

       

      I'd like to know whether there is an automatic (or an already implemented) method to restore a jBPM session after a server restart/crash.

      I've already found some threads about this problem but they're about earlier versions of jBPM (5 I think - https://community.jboss.org/thread/203151) and I was wondering if there has been any improvement related to this issue in jBPM 6.

       

      Any help would be greatly appreciated, thanks in advance.

        • 1. Re: jBPM 6 Session restore
          buenavida

          Hallo!

          Have a look at this thread.

          Greetings

          Andi

          • 2. Re: jBPM 6 Session restore
            bl91

            Thanks Andreas, I've read that thread but it doesn't actually answer to my question.

            I currently use a singleton Runtime Manager (to keep it simple for now) and so I shouldn't worry about retrieving the session Id to restore it.

            I also use similar code to setup the engine and start the process, like the one you posted:

             

            RuntimeEnvironment environment = RuntimeEnvironmentBuilder.getDefault()

              .entityManagerFactory(Persistence.createEntityManagerFactory("org.jbpm.domain"))

              .userGroupCallback(userGroupCallback)

              .addAsset(ResourceFactory.newClassPathResource("processdef.bpmn"), ResourceType.BPMN2)

              .get();

             

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

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

            KieSession ksession = runtime.getKieSession();

             

            However I was wondering if there's any built-in mechanism which automatically restores that (singleton) session or I must explicitly use org.drools.persistence.jpa.JPAKnowledgeService.loadStatefulKnowledgeSession(...) API.

            In the latter case I would really appreciate some help figuring out what code I should write exactly and where to place it, because I'm really confused about it...

            • 3. Re: jBPM 6 Session restore
              buenavida

              You don't have to do anything, except configuring your jbpm engine. This is done by

               

              RuntimeEnvironment environment = RuntimeEnvironmentBuilder.getDefault()

                .entityManagerFactory(Persistence.createEntityManagerFactory("org.jbpm.domain"))

                .userGroupCallback(userGroupCallback)

                .addAsset(ResourceFactory.newClassPathResource("processdef.bpmn"), ResourceType.BPMN2)

                .get();

               

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

              RuntimeEngine runtimeEngine = runtimeManager.getRuntimeEngine(null);

               

              Then

              TaskService taskService = engine.getTaskService();

              is restoring your session automatically. You do not have to do anything else.

               

              So when starting your application you should configure the jbpm engine by this code and your sessions are restored automatically.

              • 4. Re: jBPM 6 Session restore
                bl91

                I'm still confused.

                Suppose I start a process with its instanceId, inside the process there's only a task binded to an AsynWorkItemHandler. That task takes 30 seconds to complete.

                Now I stop the AS while it is executing  and then I restart the AS. There are still process and workitem entries in the DB.

                So, the question is: how do I resume the execution of the process and of the task ?

                 

                You suggested to use the TaskService but I still don't understand how to resume the process. Which method of that I should use ? I need the instanceId, taskId, something else ?

                • 5. Re: jBPM 6 Session restore
                  swiderski.maciej

                  if you use AsyncWorkItemHandler (with jbpm executor) depending on the retry count of the given job your process instance should be retried as soon as server is back online and can process requests. jbpm executor polls for available jobs to be executed so the previous one was not completed and thus should be picked up again for execution. If that is not happening you should file a jira for that.

                   

                  HTH

                  1 of 1 people found this helpful
                  • 6. Re: jBPM 6 Session restore
                    bl91

                    Thanks Maciej,

                    I do use jbpm-executor and the AsyncWIH, I tried to find some trace of the Executor loading the pending WorkItem but I couldn't find it in the log (even in DEBUG level).

                    So, if it should leave some log of that poll, then I might have made some mistakes in the configuration.

                     

                    How am I supposed to initialize the Executor/ExecutorService ? Currently, I'm using CDI to obtain an ExecutorService from a WorkItemHandlerProducer at startup, but I don't do anything to start it.

                    Also, I forgot to say I'm not using the jbpm-console, but I'm embedding jBPM in a custom project...