Skip to content

SR – Chapter 4,5

April 21, 2010

Aspectj Basics:
Categorization of aop is joinpoint: method, cr, fields etc.
Specific point to hit is : pointcut
Method to be called, appended is : advice
Aspect = combination of advice at a given pointcut
weaving – process of adding aspects to a class. target: class modified. introduction : new methods/fields added to class through aop.
Method Call –> Proxy –> Spring AOP. The proxy is responsible for intercepting calls to all methods and passing them as necessary to the AOP framework for the advice to be applied.
Proxy acts as a intermediary role player that recv’s the call and then does some modifications before calling the target object. It has 4 parts to it – incoming, outgoing call function, expose itself to the container, and modify the returned object when this operator is used.
CGLIB proxy is better than JDK in terms of performance since – JDK proxy invoke method is called for every method that is called – even those that are not advised. In CGLIB this does not happen and a one time check is done. This improves performance. Also optimization when fixed advice is used is done by cglib library – and it also supports interface/+/concrete handling. In Jdk proxy only classes with interfaces are supported for proxying.

Static proxying: Single proxy for every class. Dynamic proxy is a generic proxy for all classes (JDK Proxy : requires implementation of InvocationHandler and method invoke()).

InterfaceOfClassToBeProxied intfc = Proxy.createNewInstance(classloader, classImpl, new JDKProxyImplementation(objClassToBePRoxied));

Classic spring AOP (Matches ALL)

1. Create one class for interceptor/advice
2. Configurations in beans.xml for implementation to be proxied, advising class and interfaces (if need be)

For pointcut definitions – only configurations required:

<bean id="mypoint"
                    <property name="mappedName" value="add" />

<bean id="pointcutAdvisor"
                      <property name="pointcut" ref="mypoint" />
                      <property name="advice" ref="myadvice" />

There are other kind of pointcut advisors existing like RegexpMethodPointcutAdvisor, or AspectJExpressionPointcutAdvisor.

Insane mistake committed today: instead of using ref=’rr’ I was using value=’rr’ with property name=’o’ . Completely insane – wasted 1 hr on this!!

Type of weaving and another to the Joinpoint definition.Spring-AOP : Runtime weaving through proxy using concept of dynamic proxy if interface exists or cglib library if direct implementation provided.

AspectJ: Compile time weaving through AspectJ Java Tools(ajc compiler) if source available or post compilation weaving (using compiled files).Also, load time weaving with Spring can be enabled – it needs the aspectj definition file and offers flexibility. Compile time weaving can offer benefits of performance (in some cases) and also the joinpoint definition in Spring -aop is restricted to method definition only which is not the case for AspectJ.

LOG4J reference
### direct log messages to stdout ###
%d{yyyy-MM-dd HH:mm:ss} %5p %c{1}:%L – %m%n
### set root logger level ###
log4j.rootLogger=error, stdout
### set application logger level ###
Log4J supports six logging levels: fatal, error, warn, info, debug, and trace.

Example of Dynamic JDK proxy:

Prefixes in Spring: tx, util, aop, jee

No comments yet

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: