Sunday, August 18, 2013

PerfSpy 5 -- AOP.xml

AOP.xml defines to the Aspect engine what aspects to use in load-time, and weave options:

<aspectj>
        <aspects>
                <aspect name="com.yourcompany.zoo.PerfSpyDemoAsepct"/>
        </aspects>
        <weaver options="-verbose -showWeaveInfo -debug">
                <include within="com.yourcompany.zoo.animal..*"/>
                <include within="com.yourcompany.zoo.people..*"/>      
               <dump beforeandafter="true" within="com.yourcompany.zoo.animal..*"/>
               <dump beforeandafter="true" within="com.yourcompany.zoo.people..*"/>       
        </weaver>
</aspectj>

“weave” is a vivid word to describe the process that injects your actions (the “what” part of the aspect) into the defined places (the “where” part of the aspect) of the binary classes. Check the loggings:

1) [AppClassLoader@203ba002] debug not weaving 'com.yourcompany.zoo.Show'         
2) [AppClassLoader@203ba002] debug weaving 'com.yourcompany.zoo.animal.Animal'    
3) [AppClassLoader@203ba002] weaveinfo Join point 'method-execution(java.lang.String com.yourcompany.zoo.animal.Animal.getName())' in Type 'com.yourcompany.zoo.animal.Animal' (Animal.java:16) advised by around advice from 'com.yourcompany.zoo.PerfSpyDemoAsepct' (AbstractPerfSpyAspect.java) [with runtime test]                                                          
4) [AppClassLoader@203ba002] weaveinfo Join point 'method-execution(com.yourcompany.zoo.people.Trainer com.yourcompany.zoo.animal.Animal.getTrainer())' in Type 'com.yourcompany.zoo.animal.Animal' (Animal.java:20) advised by around advice from 'com.yourcompany.zoo.PerfSpyDemoAsepct' (AbstractPerfSpyAspect.java) [with runtime test]
5) [AppClassLoader@203ba002] debug generating class 'com.yourcompany.zoo.animal.Animal$AjcClosure1'
6) [AppClassLoader@203ba002] debug generating class 'com.yourcompany.zoo.animal.Animal$AjcClosure3'
1)2):'com.yourcompany.zoo.Show' is not woven while 'com.yourcompany.zoo.animal.Animal' is, because that is how it is defined in aop.xml:
      <include within="com.yourcompany.zoo.animal..*"/>
                <include within="com.yourcompany.zoo.people..*"/>        
3)4):all Animal methods are woven, obeying this PointCut:
      @Pointcut("execution(* com.yourcompany.zoo..*.*(..) )")
        public void withinCflowOps()
Notice, the constructor method of Animal is not woven, because constructor PointCut has to be defined using another syntax.

5)6):The product of the weaving process. AspectJ agent creates these binary parts which replace the original Animal class. You can view these generated classes by adding this into aop.xml weave option:
       <dump beforeandafter="true" within="com.yourcompany.zoo.animal..*"/>
<dump beforeandafter="true" within="com.yourcompany.zoo.people..*"/> 

No comments:

Post a Comment