8 Replies Latest reply on Feb 4, 2015 2:10 AM by Maciej Swiderski

    How to persist session data

    Melissa Ferenal Newbie

      Hi,

       

      I have a variable that I want to share between processes. I've registered it as a global variable into the session.

      However, the global variable is reset after I've restarted the server.

       

      Example:

      Process 1: Get Order

      Process 2: Procure

      Both processes needs to access the same Order object in the session.


      How do I persist session data so that it will still be available even if the server is restarted?

        • 1. Re: How to persist session data
          Maciej Swiderski Master

          globals are not persistable as they are seen as sort of services that usually are stateless. Instead you can insert a fact into ksession which will be stored in db as part of ksession state and then you can use it in all process instances.

           

          HTH

          • 2. Re: How to persist session data
            SANJAY GAUTAM Expert

            Maciej Swiderski wrote:

             

            globals are not persistable as they are seen as sort of services that usually are stateless. Instead you can insert a fact into ksession which will be stored in db as part of ksession state and then you can use it in all process instances.

             

            HTH

            HI Maciej

            Will ksession of statefull  type will not persist variables inside the ksession at that point of time and when the server comes back it creates the ksession with that state . I think I might have to experiment with it . ? is there more details around ksession and how it recovers back in the restart scenerios ?

             

            Thanks

            Sanjay Gautam

            • 3. Re: How to persist session data
              Melissa Ferenal Newbie

              Hi Maciej,

               

              Thanks for the help. I was able to share data using facts and the data was also available even after restarting.

              I used kcontext.getKnowledgeRuntime().insert(order);

               

              However, the session is reset when I deploy a new version of the project and the data is lost.

               

              Where are the fact variables stored? Or how can I keep the session data even after redeploying?

               

              Thanks

              • 4. Re: How to persist session data
                Dan Cimpoesu Newbie

                Hi Maciej

                 

                Are there other options?

                 

                Are facts searchable?

                 

                For example we have an order procurement object we need to share between several concurrent and cooperating processes. It is like a case where we need to store information needed to progress several processes. Ideally we would like to also store some relevant documents in this case. Please note that every order procurement is different and we need to assemble the data and start the relevant processes to achieve the procurement outcome.

                 

                What are your recommendations?

                • 5. Re: How to persist session data
                  Maciej Swiderski Master

                  facts are stored as part of ksession so as long as you will use same ksession you will have access to them. Though each redeploy means undeploy and deploy where undeploy will remove session identifier from file system - when using singleton strategy - which essentially means that new ksession will used after deploy.

                   

                  You could overcome this with saving the *jbpmSessionId.ser file for given deployment that is stored in JBOSS_HOME/standalone/data before you redeploy. After redeploy you would need to shutdown server and restore the old .ser file for that deployment it will then use same ksession.

                   

                  HTH

                  • 6. Re: How to persist session data
                    Maciej Swiderski Master

                    for that scenario I would go for pluggable variable strategies as described here. That way you could store your data anywhere and then processes will have access to them by identifiers.

                     

                    HTH

                    • 7. Re: How to persist session data
                      Dan Cimpoesu Newbie

                      Thank you Maciej, the article is clear and it all makes sense.

                       

                      If I use the workbench how can I add to RuntimeEnvironment the JPAPlaceholderResolverStrategy or my custom Resolver Strategy? Is there a declarative way or I need to modify the jbpm code base?

                       

                      Thanks

                      Dan

                      • 8. Re: How to persist session data
                        Maciej Swiderski Master

                        you can do that using deployment descriptor, take a look at the document support example that uses custom marshaling strategy that can be found here.

                         

                        HTH