Results 1 to 3 of 3

Thread: how to turn on/off advice?

  1. #1
    Join Date
    Jul 2007
    Posts
    2

    Default 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 at 05:29 AM.

  2. #2
    Join Date
    Mar 2007
    Posts
    515

    Default

    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.

  3. #3
    Join Date
    Jul 2007
    Posts
    2

    Default

    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 at 11:05 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •