Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Method parameter creation...

What happens if you put a before advice which catch the condition L.isDebugEnabled and than a conditional pointcut and the around advice you wrote?
(I am a newbie so sorry if this sounds stupid)

[Have a nice day] / [10x]
---
Pope
---
<<There are only solutions...>>



Wes Isberg wrote:

Sorry, this would be great, but AspectJ doesn't work that way.
The short story is that the parameter evaluation happens before the call join point, before any advice could short-circuit. There's a longer discussion if you search
the mail archive for "parameter evaluation", e.g.,
http://dev.eclipse.org/mhonarc/lists/aspectj-users/msg01390.html
http://dev.eclipse.org/mhonarc/lists/aspectj-users/msg01408.html
Personally, I combine log API's with standard rendering; there aren't too
many variants:
log(String label)
   log(String label, Object item)
   log(String label, Object[] items)
Then my advice or a pluggable renderer can decide how/when to evaluate
the arguments.  But this doesn't help for existing code.
Wes
    ------------Original Message------------
    From: Parag Desai <talktoparag@xxxxxxxxx>
    To: aspectj-users@xxxxxxxxxxx
    Date: Sun, Jul-18-2004 10:04 PM
    Subject: [aspectj-users] Method parameter creation...

    Hi,

    I need a small clarification.

    In my project, there is a requirement to check for the log level
    before actually logging. Like this:

    *if ( logger.isDebugEnabled() )*

    *{*

    *            logger.debug(This is logged);*

    *}*

    We wanted to automate the level check using AspectJ. Hence, I
    wrote an aspect like

    *pointcut debug() : call(* *.debug(..));*

    * *

    *void around(): debug()*

    *{*

    *            if ( logger.isDebugEnabled() )*

    *                        proceed();*

    *}*

    The code that I wrote to test this is:

    *public static void testDebug()*

    *{*

    *debug( "This is logged );*

    *}*

    When I decompiled the class file generated, I found the following
    code:

    *public static void testDebug()*

    *{*

    *String s = "This is logged";*

    *debug_aroundBody1$advice(s, TestAspect.aspectOf(), null);*

    *} // where TestAspect was the name of my Aspect.*

    Now the intention of checking log level is to avoid the overhead
    of method parameter creation when the method is not going to be
    executed. The String This is logged is created irrespective of
    whether or not the conditional check in the advice is satisfied.
    Is this a drawback of AspectJ? Is there a workaround? Please tell
    me, as I am just a beginner in AspectJ and Im doing the first and
    only AspectJ-enabled project in my company.

    With warm regards

     -Parag

    (_talktoparag@yahoo.com_ <mailto:talktoparag@xxxxxxxxx>,
    _DParagp@blr.cognizant.com_ <mailto:DParagp@xxxxxxxxxxxxxxxxx>)

    ------------------------------------------------------------------------
    Do you Yahoo!?
    Vote for the stars of Yahoo!'s next ad campaign!
<http://advision.webevents.yahoo.com/yahoo/votelifeengine/>


Back to the top