PDA

View Full Version : AOP implementation


don_benedo
Aug 14th, 2004, 02:48 PM
Hi,

Thank you Spring team for the great work. I am really diggin your code. I am relatively new to AOP. I follow your implementation in aop package up to the point of getting all the bean, advices and interceptors in bean container like ProxyBeanFactory. However, I do not see how the interceptors and advise get applied. And how the MethodInvocation is linked to PointCut. Can anyone clarify the flow how things are tied up together? And Rod, would you be writing a book about AOP implementation? I will be among the first to buy. Thanks.


Don B.

Rod Johnson
Aug 15th, 2004, 07:47 AM
Don

The interceptor chain is applied by either JdkDynamicAopProxy (for J2SE dynamic proxies) or Cglib2AopProxy, both in the org.springframework.aop.framework package. This proxy is configured by the AdvisedSupport object it refers to, which supplies the advice chain etc. (ProxyFactory and ProxyFactoryBean extend AdvisedSupport).

A MethodInvocation object flows through the interceptor chain, with the pointcut being evaluated for each piece of advice. An Advisor contains both pointcut and advice. (An advice is an object that can execute if the pointcut fires. An Interceptor is an example of an advice.)

There's some optimization in that pointcuts can often be evaluated just once, when the proxy is created, but this is the basic concept.

There's a fairly detailed chapter about AOP in "J2EE without EJB". I'm also writing a very detailed AOP chapter for the forthcoming "Professional Spring Development".

Rgds
Rod

don_benedo
Aug 15th, 2004, 10:28 AM
Thank you for your reply, Rod. I will take a closer look at the code and follow your explanation. I have your first book and the J2EE without EJB is on its way. Really great work. I would like to thank you as many times as you can take. No joke. :D

vickyk
Aug 24th, 2004, 11:56 PM
Hi Rod,
Don

The interceptor chain is applied by either JdkDynamicAopProxy (for J2SE dynamic proxies) or Cglib2AopProxy, both in the org.springframework.aop.framework package. This proxy is configured by the AdvisedSupport object it refers to, which supplies the advice chain etc. (ProxyFactory and ProxyFactoryBean extend AdvisedSupport).

A MethodInvocation object flows through the interceptor chain, with the pointcut being evaluated for each piece of advice. An Advisor contains both pointcut and advice. (An advice is an object that can execute if the pointcut fires.

As per your statement then the Advisor in Spring should have the PointCut also , but your design have a seperate Pointcut Advisor and Introduction Advisor ? Why is this like that ?

Regards
Vicky

vickyk
Aug 31st, 2004, 01:35 AM
As per your statement then the Advisor in Spring should have the PointCut also , but your design have a seperate Pointcut Advisor and Introduction Advisor ? Why is this like that ?

Rod ,
Can I get some of your time on this . :wink:
Regards
Vicky

Rod Johnson
Sep 7th, 2004, 08:36 AM
As per your statement then the Advisor in Spring should have the PointCut also , but your design have a seperate Pointcut Advisor and Introduction Advisor ? Why is this like that?
There are two types of Advisor: those for applying an advice to methods (the commonest case), and those for making introductions to advised objects. The first type is PointcutAdvisor: a Pointcut is required to identify which methods to advice. The second type is IntroductionAdvisor: the MethodMatcher part of the Pointcut interface is irrelevant in this case, hence we only use the ClassFilter part rather than a whole Pointcut.