| Author |
Recursion in implementation of Struts 2 workflow
|
Sonny Gill
Ranch Hand
Joined: Feb 02, 2002
Posts: 1211
|
|
Hi, In Struts 2, ActionInvocation and Interceptor(s) work together to implement the flow of serving an incoming request. ActionInvocation holds a list of interceptors applicable to the current request. Its invoke() method iterates through the list and calls intercept() method on each method one by one, while keeping track of which interceptors have been called. Interceptors, in intercept() method, do what they are supposed to do, and then they call invoke() back on ActionInvocation. This way all interceptors are called one by one until an Action is called, and then the control passes back through all interceptors in the reverse order. See - DefaultActionInvocation TimerInterceptor What I am trying to understand is why they implemented it this way? Same results could be achieved by ActionInvocation keeping control all the time. It could call a before() method on each interceptor, call the action, and then call an after() method on each interceptor in reverse order. What does the recursive approach get us that the iterative approach won't? Is the recursive approach considered more elegant? Cheers, Sonny
|
The future is here. It's just not evenly distributed yet. - William Gibson
Consultant @ Xebia. Sonny Gill Tweets
|
 |
 |
I agree. Here's the link: jrebel
|
|
subject: Recursion in implementation of Struts 2 workflow
|
|
|