10 Replies Latest reply on Sep 4, 2009 6:48 AM by kukeltje

    Is there any kind of variable in JBPM4 like 'transient varia

    lixiangrjxy

      In jbpm3, we can use transient variables to process biz data between two wait nodes, is there the same kind of variable in JBPM4? anyone who can advise?

        • 1. Re: Is there any kind of variable in JBPM4 like 'transient v
          frantisek.kocun

          I was searching for the same in vain. But I use PVM with own language so I coded that myself.

          If you find it please let us know!

          Thanks

          Fero

          • 3. Re: Is there any kind of variable in JBPM4 like 'transient v

            Hello

            I am not sure if I get the point here. I would like to forward a variable throughout some decisions but without persisting them (sensitive data that should not be in my DB)

            could this idea of "transient variable" be what I am looking for?

            but then I do not quite understand the thread shekharv is referring to : the variables set by ExecutionService are persisted, aren't they?

            • 4. Re: Is there any kind of variable in JBPM4 like 'transient v
              kukeltje

              afaik, jBPM4 has no notion of transient variables. otoh, if you do not use anything async, you could use 'thread local' stuff.

              • 5. Re: Is there any kind of variable in JBPM4 like 'transient v
                lixiangrjxy

                 

                "kukeltje" wrote:
                afaik, jBPM4 has no notion of transient variables. otoh, if you do not use anything async, you could use 'thread local' stuff.


                Actually I'm using a ThreadLocal now, thank you for your suggestion. Indeed I think transient variable is useful and necessary for jbpm, I just wonder if there's any similar sulotions controled by jbpm, not by programmer

                • 6. Re: Is there any kind of variable in JBPM4 like 'transient v
                  lixiangrjxy

                   

                  "npirard" wrote:
                  Hello

                  I am not sure if I get the point here. I would like to forward a variable throughout some decisions but without persisting them (sensitive data that should not be in my DB)

                  could this idea of "transient variable" be what I am looking for?

                  but then I do not quite understand the thread shekharv is referring to : the variables set by ExecutionService are persisted, aren't they?


                  I think we're looking for the same thing. and I think it shekharv's sulotion is not what we want.

                  An util class and a ThreadLocal variable can be work here as npirard suggested.

                  • 7. Re: Is there any kind of variable in JBPM4 like 'transient v

                    in fact I made a quick test workaround yesterday using a Custom

                    I try to pack the code and post it here this day, I'd be glad if anyone could point a flaw in it, if any, or validate my "secret" parameter is not recorded in some JBPM table ;-)

                    the ThreadLocale idea is nice too, thanks

                    • 8. Re: Is there any kind of variable in JBPM4 like 'transient v
                      kukeltje

                      I have to be honest, the ThreadLocal thing was not fully my idea. As far as I remember, it is the way jBPM3 did it to :-)

                      • 9. Re: Is there any kind of variable in JBPM4 like 'transient v

                        well, jBPM3 had a nice idea, IMO :-)

                        especially if the transient data has to be used at several parts of the process, so that it is overall better than mine.



                        here is what I did, I pass the data when signalling the Custom that uses them with method
                        ExecutionService.signalExecutionById(String, String, Map<String, ?>)



                        JPDL :

                        <?xml version="1.0" encoding="UTF-8"?>
                        
                        <process name="CustomParameters" xmlns="http://jbpm.org/4.0/jpdl">
                         <start g="161,71,48,48" name="start1">
                         <transition g="-30,-37" name="to input_some_info" to="input_some_info"/>
                         </start>
                         <state g="301,129,209,52" name="input_some_info">
                         <transition g="-68,-18" name="to exclusive1" to="exclusive1"/>
                         </state>
                         <decision g="381,222,48,48" name="exclusive1">
                         <handler class="org.jbpm.npi.Exclusive1Handler" />
                         <transition g="-58,-18" name="to custom1" to="custom1"/>
                         </decision>
                         <custom class="org.jbpm.npi.MyCustom" g="361,319,92,52" name="custom1">
                         <transition name="to exclusive2" to="exclusive2" g="-68,-18"/>
                         </custom>
                         <decision g="384,416,48,48" name="exclusive2">
                         <handler class="org.jbpm.npi.Exclusive2Handler" />
                         <transition name="to wait2" to="wait2" g="-44,-18"/>
                         </decision>
                         <end g="569,500,48,48" name="end1"/>
                         <state name="wait2" g="350,479,92,52">
                         <transition name="to end1" to="end1" g="-42,-18"/>
                         </state>
                        </process>
                        


                        two simple DecisionHandlers :
                        package org.jbpm.npi;
                        
                        import org.jbpm.api.jpdl.DecisionHandler;
                        import org.jbpm.api.model.OpenExecution;
                        
                        public class Exclusive1Handler implements DecisionHandler {
                        
                         @Override
                         public String decide(OpenExecution arg0) {
                         return "to custom1";
                         }
                        }
                        
                        package org.jbpm.npi;
                        
                        import org.jbpm.api.jpdl.DecisionHandler;
                        import org.jbpm.api.model.OpenExecution;
                        
                        public class Exclusive2Handler implements DecisionHandler {
                        
                         @Override
                         public String decide(OpenExecution arg0) {
                         return "to wait2";
                         }
                        }
                        
                        


                        my Custom :
                        package org.jbpm.npi;
                        
                        import java.util.Map;
                        
                        import org.jbpm.api.activity.ActivityExecution;
                        import org.jbpm.api.activity.ExternalActivityBehaviour;
                        
                        public class MyCustom implements ExternalActivityBehaviour {
                        
                         @Override
                         public void signal(ActivityExecution activityExecution, String signal, Map<String, ?> parameters) throws Exception {
                         System.out.println("signal() - ring the Kremlin !! " + parameters.get("putinPhoneNumber"));
                        
                         activityExecution.takeDefaultTransition();
                         }
                        
                         @Override
                         public void execute(ActivityExecution activityExecution) throws Exception {
                         System.out.println("MyCustom.execute()");
                         activityExecution.waitForSignal();
                         }
                        
                        }
                        


                        the test class
                        package org.jbpm.npi;
                        
                        import java.util.HashMap;
                        import java.util.Map;
                        
                        import org.jbpm.api.Execution;
                        import org.jbpm.api.ProcessInstance;
                        import org.jbpm.test.JbpmTestCase;
                        
                        /**
                         * test the possibility to inject parameters at some point of a process without
                         * persisting them
                         *
                         * @author npirard
                         */
                        public class CustomParametersTest extends JbpmTestCase {
                        
                         String deploymentId;
                        
                         @Override
                         protected void setUp() throws Exception {
                         super.setUp();
                        
                         deploymentId = repositoryService.createDeployment().addResourceFromClasspath("org/jbpm/npi/CustomParameters.jpdl.xml").deploy();
                         }
                        
                         @Override
                         protected void tearDown() throws Exception {
                         repositoryService.deleteDeploymentCascade(deploymentId);
                        
                         super.tearDown();
                         }
                        
                         public void testProcess(){
                         Map<String, Object> variables = new HashMap<String, Object>();
                        
                         //this is a variable that can be persisted without problem
                         variables.put("publicInfo", "this is not really secret");
                         ProcessInstance processInstance = executionService.startProcessInstanceByKey("CustomParameters", variables);
                        
                         Execution executionInA = processInstance.findActiveExecutionIn("input_some_info");
                         assertNotNull(executionInA);
                        
                         processInstance = executionService.signalExecutionById(executionInA.getId());
                        
                         Execution executionInCustom = processInstance.findActiveExecutionIn("custom1");
                         Map<String, String> parameters = new HashMap<String, String>();
                        
                         //this is really secret matter
                         parameters.put("putinPhoneNumber", "+7123456789");
                         processInstance = executionService.signalExecutionById(executionInCustom.getId(), "mySignal", parameters);
                        
                         Execution executionInWait2 = processInstance.findActiveExecutionIn("wait2");
                        
                         assertNotNull(executionInWait2);// breakpoint A
                        
                         processInstance = executionService.signalExecutionById(executionInWait2.getId());
                        
                         assertTrue(processInstance.isEnded());// breakpoint B
                         }
                        }
                        


                        I executed it in debug ; at breakpoint A I found "publicInfo" in table JBPM4_VARIABLE, but not "putinPhoneNumber"

                        at breakpoint B I do not find anything in JBPM4_VARIABLE. By the way, I would have expected "publicInfo" in JBPM4_HIST_VAR, but it is not. Maybe I have not understood the purpose of this latter table : it is not supposed to record the variables of past executions?



                        • 10. Re: Is there any kind of variable in JBPM4 like 'transient v
                          kukeltje

                          The history table is exactly what you think it is for. There are just some things not implemented yet, see the jira for history issues.