6 Replies Latest reply on Jan 8, 2015 1:56 AM by Maciej Swiderski

    Restore processes instances from database.

    Jakub Piotrowski Newbie

      Hello, i succesfully connected jbpm to my database (PostgreSQL) and i store logs into it. I made it by:

      KieServices ks = KieServices.Factory.get();
      KieContainer kContainer = ks.getKieClasspathContainer();
      KieSession kSession = kContainer.newKieSession("WorkflowSession");
      EntityManagerFactory emf = new EnvironmentProducer().getEntityManagerFactory();
      AbstractAuditLogger auditLogger = AuditLoggerFactory.newJPAInstance(emf);


      I would like to restore all active processes after server falling. For example:

      1. Start scenario (start process)

      2. Server fall down (the process is in database register as active)

      3. After turn on server again have this process loaded to my new KieSession


      Please help me with this problem.



        • 1. Re: Restore processes instances from database.
          Maciej Swiderski Master

          there is no need to restore process instances after server shutdown/restart. Whenever you need to work on given process instance (signal, complete task etc) session will load the process instance on demand.


          I would recommend to use runtime manager whenever working with processes, see docs.



          • 2. Re: Restore processes instances from database.
            Jakub Piotrowski Newbie

            Thank you for answer.


            I still have some questions:

            When i create RuntimeEnvironment i have to put as parametr: ResourceFactory.newClassPathResource("BPMN2-ScriptTask.bpmn2").

                 I don't know what should be exactly in newClassPathResource().


            I would like to restore all processes after server restart and it i thought that Per Process Strategy will be good, but i still don't know how to use it.


            Best regards

            • 3. Re: Restore processes instances from database.
              Maciej Swiderski Master

              you put all the assets (process and rules) into the environment that you want to use later on when executing your processes.


              Again, there is no need to manually restore process instances as they are fetched on demand when work is to be performed on them - like signal, complete task, get process instance.



              • 4. Re: Re: Restore processes instances from database.
                Jakub Piotrowski Newbie
                public class WorkflowKnowlageBase
                  private static RuntimeManager manager;
                  RuntimeEnvironmentBuilder builder = new RuntimeEnvironmentBuilder();
                  RuntimeEnvironment env = builder.get();
                  manager = RuntimeManagerFactory.Factory.get()
                  public void createProcessInstance(String procName,
                  Map<String, Object> params, String scenarioName)
                  RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());
                  KieSession kSession = runtime.getKieSession();
                  ProcessInstance pi = kSession.createProcessInstance(procName, params);


                Here is my class to make sessions and start processes and it doesn't work, what is wrong?

                I've checked and i can't put processes into environment.


                Best regards

                • 5. Re: Restore processes instances from database.
                  chiaan Hung Novice

                  In my application, human task can be restore automatically after server restart. However, there will have error saying that workitemhandler are missing. I can only fix this error by start the same process again than I can have the missing workitemhandler back. Do you have other solution? THX!     

                  • 6. Re: Re: Re: Restore processes instances from database.
                    Maciej Swiderski Master

                    Here is the code that would be needed to create RuntimeManager properly:

                    EntityManagerFactory emf = Persistence.createEntityManagerFactory("org.jbpm.persistence.jpa");
                    RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get()
                    .addAsset(ResourceFactory.newClassPathResource("BPMN2-ScriptTask.bpmn2"), ResourceType.BPMN2)
                    .addAsset(ResourceFactory.newClassPathResource("BPMN2-UserTask.bpmn2"), ResourceType.BPMN2)
                    manager = RuntimeManagerFactory.Factory.get().newPerProcessInstanceRuntimeManager(environment); 

                    with that you provide entity manager factory and processes that should be there. Without these two there is no way for the engine to know what to do.