5 Replies Latest reply on Jan 4, 2013 10:56 AM by dward

    Mapping global variables in Switchyard Rules Service

    avadhut.sardeshmukh

      Hello All

      First of all, I am a complete newbie to the Java world in general, Jboss and Switchyard in particular. So please excuse for an inappropriate question and point me to a proper place to look for an answer.

       

      I am trying to expose a Drools rule file as a Switchyard service, and want to return some key-value pairs from the rule file.

      Earlier (before using Switchyard), I had done this by setting an object as a global variable (using "setGlobal" method of "StatefulKnowledgeSession" class) and then inserting key-value pairs into this object inside the rule file. Now I want to do the same thing using Switchyard.

       

      There is a "globals=" attribute inside the @Rules annotation, but it is not doing what I had expected. I used it as follows :

                                    globals={@Mapping(expression="message.content", variable="output")}

      What it is doing is, it is mapping the object passed as input to the .drl file (using the SendInOnly method), to the variable declared as global (i.e. output). What I expect instead is, these two (input and output) to be two different objects (of different classes). Probably there's a way to use it according to my intended way, but I am not able to get it.

      Please let me know which additional info I can provide to help you better understand my question.


      Will you please help me solve this issue?

       

      Thanks and regards,

      Avadhut Sardeshmukh

        • 1. Re: Mapping global variables in Switchyard Rules Service
          dward

          Hi Avadhut,

           

          Before rules execution, the mapping expression is evaluated and the result is mapped into the rules session as a global. After rules execution, however, the global is not taken back out of the rules session and set back into the mapping expression. (The expression is only used in one direction - not both - and was intentional.)  That's why naming a global mapping something like "output" doesn't really make sense.

           

          There is a way, however, to do what you want.  The "message" variable (representing org.switchyard.Message) is a global that will always be available to you in your DRL, and the content on it can be changed in your DRL itself, via get/setContent. If you modify the content via setContent, AND your rule service has a message ExchangePattern of IN_OUT, then the content you set in your DRL will be used as the outgoing content.

           

          Hope this helps,

          David

          1 of 1 people found this helpful
          • 2. Re: Mapping global variables in Switchyard Rules Service
            avadhut.sardeshmukh

            Hello David

            Thank you very much for the prompt reply, and I am sorry for this delayed response. Your answer was insightful indeed. I tried the setContent approach and it worked.

             

            But, due to some design considerations at our end, what we finally ended up doing is to have a seperate data structure (i.e. a class) for each rule service, with its (i.e. service's) inputs/outputs defined as attributes of the class data structure. Thus, we used this single object for input as well as output (by setting message-exchange-pattern to IN_OUT).

            Nevertheless, from your reply I got insights into the usage of message, exchange context etc with switchyard. Thank you very much.

             

            -Avadhut.

            • 3. Re: Mapping global variables in Switchyard Rules Service
              dward

              Avadhut,

               

              I'm happy you found a solution. Having a single object to hold input/output is indeed a common solution; glad it works within your design.

               

              David

              • 4. Re: Mapping global variables in Switchyard Rules Service
                magick93

                Hi David

                 

                Would you be so kind as to do a quick example of this? Im really struggling with how to get values out of a rule service.

                 

                That would be so appreciated!

                 

                Thanks and regards,

                Anton

                • 5. Re: Mapping global variables in Switchyard Rules Service
                  dward

                  Anton, I've responded over here.  Let's keep the conversation in one place, please?