9 Replies Latest reply on Sep 13, 2005 10:14 PM by Tomasz Nazar

    practical application of cflow-stack

    Michael Haupt Newbie

      Hi,

      is there any application of the cflow-stack construct being used out there? I can imagine some, but would like to see that someone is already using this.

      Michael Haupt

        • 2. Re: practical application of cflow-stack
          Michael Haupt Newbie

          Tomasz,

          thank you, that's interesting, but I don't see where the specific ability of JBoss AOP to declaratively say "I want all of *these* methods on the stack in the given order" comes in.

          Maybe I didn't ask the question properly. I'm specifically interested in applications of cflow *stacks*, not single cflows that are combined with logical operators.

          Thanks though!

          Best regards,

          Michael

          • 3. Re: practical application of cflow-stack
            Tomasz Nazar Newbie


            Aaaahhh. Sorry :)
            I didn't notice "stack".

            So, start your own application and you'll be the first one :)

            Tomasz

            • 4. Re: practical application of cflow-stack
              Michael Haupt Newbie

              Tomasz,

              huh. So here's my heretic question. What is that feature good for, after all?

              Best,

              Michael

              • 5. Re: practical application of cflow-stack
                Kabir Khan Master

                Do you have any other suggestions for how cflows could be defined?

                A cflow used in a bind expression will always refer to a cflow stack, which specifies what things should be on the stack.
                Two examples:

                1) Say you have a method that calls itself recursively and you only want interceptiion to occur on the first invocation (or not the first, but all subsequent) - a cflow-stack can help you with that.

                2) Another example could be using AOP during testing. Say for example that you want to simulate a specifiic error condition using an advice (there is an example of simulating a SQL exception in the user guide). But you might only want this error to get triggered from some particular test cases and not from others. Again here cflow could help.

                • 6. Re: practical application of cflow-stack
                  Michael Haupt Newbie

                  Kabir,

                  thanks for your reply. I wasn't trying to offend anybody. ;-)

                  Of course a cflow stack is more generic than a single cflow statement, and more declarative than nested cflows when it comes to explicitly asking for things on the stack in a given order.

                  I was just looking for some large-scale application of the *stack* feature.

                  Your first example can be tackled entirely without cflow stacks (or nested cflows, which I boldly deem semantically equivalent).

                  Take this:

                  int fac(int k) {
                  if(k<=1) return 1;
                  else return k*fac(k-1);
                  }

                  If I want to match ONLY the first call, I can even do it statically:

                  call(fac) && !withincode(fac)

                  Or, to allow for mutual recursion (let's assume it's there):

                  call(fac) && !cflow(call(fac))

                  If I want to match ALL BUT the first, I can do it thus:

                  call(fac) && withincode(fac)

                  or

                  call(fac) && cflow(fac)

                  No nested cflows, no cflow stacks. I apologise for using pseudo-AspectJ syntax. ;-)

                  I shall take a look at your second example. But for now, it seems that a single cflow is enough there. It doesn't say that there is a need for matching a cflow *stack* (THIS method called from THAT method, which was in turn called from YONDER method, ...).

                  Thanks!

                  Michael

                  • 7. Re: practical application of cflow-stack
                    Kabir Khan Master

                    None taken :-)

                    I think the CFlow stack is more flexible than what you outline below, Note that you do not need to specify the whole stack, just things that need to be on the stack. So, you could have a stack with just one entry, giving you the behaviour you describe.

                    As for the withincode stuff, I don't remember exactly how it works in AspectJ, but in JBoss AOP at least, it will only match for that call.

                    Consider an example where the recursion is not so "dirext" (your example with some pointless changes ;-)
                    int fac(int k) {
                    if(k<=1) return 1;

                    if (k % 0 == 0) return x(k-1);
                    else return y(k-1);
                    k-1);
                    }

                    int y(int k){
                    return fac(k);
                    }

                    int x(int k){
                    return fac(k);
                    }


                    in this case
                    you would need to change the caller stuff to (I can't rememeber if we actually support negating withincode)

                    call(fac) AND !withincode(x) AND !withincode(y)

                    While if you had a cflow stack, that could remain the same.

                    • 8. Re: practical application of cflow-stack
                      Michael Haupt Newbie

                      Kabir,

                      thanks once more. I think I did not make my solutions clear enough. What you address with the doubled "!withincode()" is exactly what I meant with "mutual recursion": if a method calls itself recursively through another one. A calls B calls A calls B calls A ... and so forth.

                      For that, cflow is very convenient, which I would never dare to doubt.

                      But that was never my question. I am still looking for a practical example for a cflow stack with *more* than one entry, where you *need* to specify the order of methods on the stack.

                      Best,

                      Michael

                      • 9. Re: practical application of cflow-stack
                        Tomasz Nazar Newbie

                        I'm just loud thinking...nothing important below..

                        [..]
                        I don't get it. I just had to look back into reference to recollect..

                        (1)As I thought there is nothing about ordering of <not-called> constructs within <cflow-stack> element. Does it matter -- the order of elements? I suppose yes..

                        (2)And I always thought <cflow-stack> is just more concise way of expressing "cflows". Instead of mixing it with logical operators... A nice way of reuse.

                        (3)There is also not being said whether <cflow-stack> will match current stack when there are some other method calls between <called/not-called>.

                        e.g.
                        <cflow-stack><called: A()><called: B()> could/should? match method calls: A() calls A1() calls B()... or will only match method A() calling B() directly?

                        Tomasz