Announcement Announcement Module
Collapse
No announcement yet.
how to turn on/off advice? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • how to turn on/off advice?

    Hi all!

    I'm trying to write a logging aspect. My problem is that i want to make it possible to turn off/on some of the advices on runtime (on some occasions during runtime, i don't want some of the intercepted method will be proxied for performance reasons).
    In Java:

    @Aspect
    public class AspectTest{
    public static final Log log = LogFactory.getLog(AspectTest.class.getName());
    @Pointcut(...)
    public pointcutA(){}
    @Pointcut(...)
    public pointcutB(){}

    @Before("pointcutA()")
    public adviceA(){// some logging}

    @Before("pointcutB()")
    public adviceB(){// some logging}
    }

    In configuration file:
    <aop:aspectj-autoproxy/>
    <bean id="aspectTest" class="com.emc.tov.test.aspects.AspectTest""/>

    let's say i want during runtime to apply only adviceA and disable adviceB, how can i do it?

    Thanks!
    Last edited by jimi81; Jul 24th, 2007, 06:29 AM.

  • #2
    Take a look at this class: DynamicMethodMatcherPointcut - and think about subclassing it and implement matches(Method method, Class cls) and matches(Method method, Class cls, Object[] args).
    I didn't implement an example myself, but for your issue, I would start investigating from this class.

    Comment


    • #3
      Thanks Andrei!

      I'll check about DynamicMethodMatcherPointcut. But after i gave a thought about the way Spring implements the AOP mechanism, it lead me to conclude that it's impossible to disable advices on runtime, in a mean that a call to the method should performed directly on the object and not through the proxy object, on intensive logging each call through the dynamic proxy seams to be very expansive (if using log4j, logging itself can be disable through log4j). Probably DynamicMethodMatcherPointcut give the opprotunity to filter pointcut, but it can't disable the proxy overhead.
      I think that using AspectJ directly is better for logging in my case, since it doesn't involve any runtime overhead which caused by the proxy. Does anybody know how common is to use AspectJ for logging? Do you know about big application that are using AspectJ?

      Thanks in advance.
      Last edited by jimi81; Jul 25th, 2007, 12:05 PM.

      Comment

      Working...
      X