7 Replies Latest reply on Dec 4, 2013 3:10 AM by swiderski.maciej

    JBPM6 - RuntimeManager @PerProcessInstance and KSession

    fgiannetti

      Hi!

      I have an RuntimeManager annotated with @PerProcessInstance in CDI:

       

      @Inject
      @PerProcessInstance
      private RuntimeManager manager;
      
      
      @Inject
      private TaskService taskService;
      

       

      I create a new process like this:

       

      RuntimeEngine engine= manager.getRuntimeEngine(ProcessInstanceIdContext.get());
      KieSession session=engine.getKieSession();
      session.setGlobal("foo", new Foo());
      session.startProcess("jbom.myProcess",paramMap);
      
      

       

      Thats works OK.

      When the process is created, inside the first task the global "foo" is correct and working.

      But when I try to acces the "foo" global in a separate request (for example when the task is completed)  this is null.

       

      If I use a @Singleton RuntimeManager the global is alive at all the tasks, but with PerProcessInstance its resets to null

       

      Is any way to keep the global alive during the process lifecycle?

       

      Thanks!

        • 1. Re: JBPM6 - RuntimeManager @PerProcessInstance and KSession
          salaboy21

          Hi,

          first of all if you are using the runtimeManager you should get the Task Service from it.

          About the global, that's normal, when you try to load the session again for continue working (because you have one session per process instance) the foo variable is not initialized again.

           

          I would recommend you using a process variable instead of a global and that will be stored in the context of the process so you know that it will be always there.

           

          HTH

          • 2. Re: JBPM6 - RuntimeManager @PerProcessInstance and KSession
            fgiannetti

            Thanks for you reply!

             

            I use the process variable solution temporarily until I have some more information about it. If cant have more, i keep it as final solution

             

            Regards!

            • 3. Re: JBPM6 - RuntimeManager @PerProcessInstance and KSession
              salaboy21

              Can I ask what kind of globals are you trying to set/use? Gloabls are usually external services.. so if that's the case a Global should be the answer. For that you can use globals but you need to make sure that every time before using the ksession you set the global.

              • 4. Re: JBPM6 - RuntimeManager @PerProcessInstance and KSession
                fgiannetti

                The global is a service that contains some methods to make some business logic.

                 

                How can I get the ksession when I use the TaskService? I have the TaskService with the @Inject, so cant see where set the global variables.

                 

                Anyway, if the solution is set the global any time I use the session (not just once while creating it) I gess that the process variable solution is the best of both

                 

                Tanks!!!

                • 5. Re: JBPM6 - RuntimeManager @PerProcessInstance and KSession
                  salaboy21

                  Don't inject the task service use this:

                   

                  1. RuntimeEngine engine= manager.getRuntimeEngine(ProcessInstanceIdContext.get()); 
                  2. KieSession session=engine.getKieSession(); 
                  3. TaskService taskService = engine.getTaskService();


                  Every time that you want to use the global you will need to do:

                  1. session=engine.getKieSession(); 
                  2. session.setGlobal("name", value );
                  • 6. Re: JBPM6 - RuntimeManager @PerProcessInstance and KSession
                    salaboy21

                    Don't inject the task service use this:

                     

                    1. RuntimeEngine engine= manager.getRuntimeEngine(ProcessInstanceIdContext.get());
                    2. KieSession session=engine.getKieSession();
                    3. TaskService taskService = engine.getTaskService();

                    Every time that you want to use the global you will need to do:

                    1. session=engine.getKieSession();
                    2. session.setGlobal("name", value );
                    • 7. Re: JBPM6 - RuntimeManager @PerProcessInstance and KSession
                      swiderski.maciej

                      guys, this is indeed missing feature in RuntimeManager that should allow to define what globals shall be injected in ksession on it's creation or load. Could you please file a jira issue for this?

                       

                      In meantime, instead of using process variable for global service you could (ab)use RegisterableItemsFactory implementation to put your globals into ksession when its called to register work item handlers, listeners. Most likely globals will be part of RegisterableItemsFactory anyway so it will be a matter of mowing that code into dedicated method in that class.

                       

                      HTH