9 Replies Latest reply on Jul 28, 2011 12:48 PM by jlgranda81

    Iterate over all existing sessions at startup

    bwallis42

      Is there a supported way that I can find all existing persisted workflow sessions when jBPM is restarted?

       

      I need a way to reconfigure a bunch of JMS subscriptions that are dynamically created when the stateful sessions are created for each workflow instance. We are running with a statefull session per workflow rather than lots of workflows within one session since the set of facts used for one workflow instance is most likely not used in any other workflow instance.

       

      thanks.

        • 1. Iterate over all existing sessions at startup
          salaboy21

          Hi Brian, you will have a row for each processinstance that you have running inside the ProcessInstanceInfo table. Did you check that?

          Notice that there is a Status, or Completed field that indicates if the process has ended or not.

          Greetings.

          • 2. Iterate over all existing sessions at startup
            odelyaholiday

            Hi Mauricio

             

            Are ProcessInstanceInfo rows in the table are deleted everytime that the session /server stops?

            • 3. Iterate over all existing sessions at startup
              salaboy21

              Nope, the Database is used to keep the processes safe. You need to understand that the processes will be stored each time that they reach a wait state (async task, like human tasks). If it's an in memory (all synchronous tasks) process it will not be persisted.

              Cheers

              • 4. Iterate over all existing sessions at startup
                odelyaholiday

                Mauricio Salatino wrote:

                 

                If it's an in memory (all synchronous tasks) process

                do you mean h2 database?

                 

                what could make a process in memory?

                • 5. Iterate over all existing sessions at startup
                  salaboy21

                  In memory process are the one that doesn't have a wait state/safe point in them. When that happens (when no async task is included) the process will only run in memory without persisting their state. That's because they can run from the beginning to the end without waiting for an external actor or system to interact with them.

                  When you use H2 (in memory database), the processes will be persisted as if you were using a common DB.

                  Greetings.

                  • 6. Iterate over all existing sessions at startup
                    odelyaholiday

                    You actually mean a process that doesn't have human tasks for instance?

                    • 7. Iterate over all existing sessions at startup
                      salaboy21

                      Human tasks are async, but you can also have external systems interactions that works asynchronously. You need to think that if your process can start and end only in memory, without waiting any external interaction (Systems or Humans) your process will never be persisted.

                      • 8. Iterate over all existing sessions at startup
                        bwallis42

                        Mauricio Salatino wrote:

                         

                        Hi Brian, you will have a row for each processinstance that you have running inside the ProcessInstanceInfo table. Did you check that?

                        Notice that there is a Status, or Completed field that indicates if the process has ended or not.

                        Greetings.

                        I see that in the code in ProcessInstanceInfo which would let me get the ProcessInstance. But I cannot see any way to find the session from there.

                         

                        I believe that I need to recreate all the old sessions on restart which is exactly what I need since I can then assert new facts into these sessions which will cause the workflow processes to continue processing (remember, I have a session per process).

                         

                        I found a mention of this in an old post by Kris (from Aug 22, 2009):

                         

                        So whenever the application needs to be restarted, you must restore the

                        session (either creating a new one or reloading it using the unique

                        session id).  Execution will then continue as before.  For example, if a

                        user then completes a task that was requested by a specific process

                        instance, the engine will automatically know that that user task was

                        related to that specific process instance and reload its previous state

                        from the database.

                         

                        So, as long as you make sure that the session is restarted, all process

                        instances will continue from the state they were at before without you

                        having to do anything.

                         

                         

                        but I am still not sure how I do this or whether or not I need to persist the unique session IDs when I create them in the first place

                         

                        thanks.

                        • 9. Re: Iterate over all existing sessions at startup
                          jlgranda81

                          Mauricio, is possible overwrite  JPAProcessInstanceManager or create a subclass for overwrite removeProcessInstance method?