The Artima Developer Community
Sponsored Link

Java Buzz Forum
AspectJ, "dynamic" pointcuts, and Spring. A great combination

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
dion

Posts: 5028
Nickname: dion
Registered: Feb, 2003

Dion Almaer is the Editor-in-Chief for TheServerSide.com, and is an enterprise Java evangelist
AspectJ, "dynamic" pointcuts, and Spring. A great combination Posted: May 12, 2004 11:20 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by dion.
Original Post: AspectJ, "dynamic" pointcuts, and Spring. A great combination
Feed Title: techno.blog(Dion)
Feed URL: http://feeds.feedburner.com/dion
Feed Description: blogging about life the universe and everything tech
Latest Java Buzz Posts
Latest Java Buzz Posts by dion
Latest Posts From techno.blog(Dion)

Advertisement
Adrian Colyer, lead of the AspectJ team, was obviously a busy man on his flight back from Las Vegas to London. He posted a message to the aspectj mailling list, which talks about a JoinPointMatcher. This class is built to handle dynamically working with join points a la: JoinPointMatcher jpm = new JoinPointMatcher("within(patterntesting..*)"); He says more: At any join point, you can ask JoinPointMatcher whether or not it matches: if( jpm.matches(thisJoinPoint)) ... Here's an aspect that allows runtime configuration using this mechanism: aspect DynamicPointcutConstructionExample { private static JoinPointMatcher jpm; public void setPointcutExpression(String pointcutExpr) { jpm = new JoinPointMatcher(pointcutExpr); } // this pointcut is used to narrow down as far as possible at compile time the set of places // at which a dynamic pointcut could match (for efficiency) pointcut scope() : within(org.xyz.foo); before() : scope() && if(jpm.matches(thisJoinPoint)) { System.out.println("I matched!!"); } } The consequence you pay for using dynamic pointcuts (I'm using the word dynamic in analogy to the use of "dynamic" in DII, it may not be the best term) is that the pointcut matching is (very much) less efficient since the jpm.match code is driven for every join point in the scope (whereas the same pointcut specified at compile time would cause the advice to execute exactly where it needs to with no additional overhead or redundancy). If a dynamic pointcut proved to be too slow, you could always switch back to a traditional statically specified pc. If you're using Spring with the above example, you can configure the aspect with e.g. "http://www.springframework.org/dtd/spring-beans.dtd"> I hope we end up with something very close to this in Spring --> class="DynamicPointcutConstructionExample" factoryMethod="aspectOf"> execution(* *(..)) && this(Foo) Spring will set the value of the pointcutExpression attribute when the aspect is constructed. Many thanks are due to Rod Johnson for the inspiration to look into this. This is *very* cool stuff. I know that Vincent Massol has a need for this type of dynamic pointcut, and many others will be found. Of course, you want to NOT do things in this manner when possible for performance reasons etc.... but having the power to drop down to this when needed is fantastic. Now all we need is to have the ability to write reusable aspect libraries and I will be a very happy man.

Read: AspectJ, "dynamic" pointcuts, and Spring. A great combination

Topic: Google IPO Humour Previous Topic   Next Topic Topic: RSS over P2P: one of those aha moments

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use