3 Replies Latest reply on Aug 8, 2010 6:02 AM by HuiSheng Xu

    Some questions about the script execution code

    Michael Wohlfart Expert

      I am currently going through the source code of jBPM4 because I am having some problems with custom script execution in my process definitions. Unfortunately the code base is not very well documented for my taste, some source files contain nothing more than copyright and author comment, which leads me to ask here for the programmer's intention. Hopefully there is someone who knows what's going on, or at least we can have a discussion about how to handle things.

       

      • As far as I understand the ScriptManager is the central component in executing scripts but is also used for evaluating expressions, why is the method "evaluateScript()" never called? To me its seems like Scripts are evaluated as Expressions in the "evaluateExpression()" method thus the defaultScriptLanguage is never used, is this intentional or just a bug?
      • Why is the EnvironmentBindings not "storing" any variables in the put() method , isn't this necessary for some scripting languages, couldn't this easily be achieved by extending javax.script.SimpleBindings, or is this a wanted behavior for some reason I don't understand?
      • The Constructor for EnvironmentBindings has parameters for readContext and writeContext but they are not used, is this not yet implemented or is this deprecated?
      • I came across the TaskContext and basically what I try to do is having access to the TaskContext in my scripts, unfortunately the TaskContext is only used in the MailListener. Scripts seems to be executen within the ExecutionContext is there any reason for not having the TaskContext when executing Scripts?

       

      I am willing to do some work on this in the future because I think jbpm4 is a great framework but I need some input before hacking along...

        • 1. Re: Some questions about the script execution code
          HuiSheng Xu Master

          Hi Michael,

           

          I will try to answer your questions.  If I had any mistakes,  please correct me.

           

          1.ScriptManager is used to manage script like juel, bsh, groovy to integrate into pvm.  Before jBPM-4.4,  we used juel to be the default expression language.  But in jBPM-4.4,  Tom created a new package named org.jbpm.pvm.internal.el.  And all of expressions should be evaluated by this package.  We won't use ScriptManager to evaluate expression directly.

           

          So now,  The only place that used ScriptManager is in the org.jbpm.pvm.internal.el.Expression.  If we create a Expression which language is not UEL_VALUE or UEL_METHOD,  it will use ScriptManager to evaluate the script by specified language.

           

          And I find both evaluateExpression() and evaluateScript() are using evaluate() internal.  There is no different between them.  So we just using evaluateExpression() to do all of work about eval script.  Maybe sometimes it become much confused.

           

          2.EnvironmentBinding had not finished yet.  We just removed all of IllegalStateException in jBPM-4.4 in order to get more feeback from community.  I think we could finish it in the next version, like achieve the put() method to store data into process variable.

           

          3.Did we have to achieve the readContext and writeContext.  In which scenarios we should use them?  If they are not neccessary,  I want to deprecated them in the next version,  so we could delete them in the future.

           

          4.How should we refactor TaskContext and ExecutionContext.  A long times ago, Tom said he want to refacter the TaskContext and ExecutionContext,  But he didn't make it more clearly.  if we could make a good plan,  we could finish this work by ourselves.

           

          Any reply will be apprieciated.  Thank you very much.

          • 2. Re: Some questions about the script execution code
            Michael Wohlfart Expert

            Hi HuiSheng,

            thanks a lot for your reply,

            [..]

            And I find both evaluateExpression() and evaluateScript() are using evaluate() internal.  There is no different between them.  So we just using evaluateExpression() to do all of work about eval script.  Maybe sometimes it become much confused.

            the problem I see here is that a script might get executed with the default expression language instead with the default script language, this part of the source is indeed very confusing can't we just remove the evaluateExpression() and evaluateScript() and in general use the evaluate() method and throw an exception if the execution language is not specified, this would be more in line with the rest of the code in my opinion.

            [...]

            2.EnvironmentBinding had not finished yet.  We just removed all of IllegalStateException in jBPM-4.4 in order to get more feeback from community.  I think we could finish it in the next version, like achieve the put() method to store data into process variable.

            I didn't think of this, but it would be a cool feature to have a groovy script write to process variables

            [...]

            3.Did we have to achieve the readContext and writeContext.  In which scenarios we should use them?  If they are not neccessary,  I want to deprecated them in the next version,  so we could delete them in the future.

            I also don't see an urgent need for them, the read contexts are hard coded now as far as I understand?

            The write context would be where ever the variable is declared?

            [...]

            4.How should we refactor TaskContext and ExecutionContext.  A long times ago, Tom said he want to refacter the TaskContext and ExecutionContext,  But he didn't make it more clearly.  if we could make a good plan,  we could finish this work by ourselves.

            Could they be used to have access to task scoped and execution scoped variables, at least this would make sense to me :-/ right now the TaskContext just gives access to the task itself, so a script can do stuff like task.getVariable('varname')

            • 3. Re: Some questions about the script execution code
              HuiSheng Xu Master

              Hi Michael,

               

              I am agree with you about merge evaluateExpression() and evaluateScript() for ScriptManager.  The other questions we still need a more clearly plan.