Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [aspectj-users] Overriding pointcuts

Mathew,
Thanks for your response. That's a bummer. Lets look at the problem from a different  vantage point.
 What Iam trying to accomplish here is turn off the flight recorder logging with some configuration, without recompiling. I can do this by turning it off in the flight recorder, but then I will be taking the hit of AspectJ framework ( creating JoinPoints etc), which I dont want.
 
Rephrasing the question, Is it possible to turnoff AspectJ framework in the code without recompiling, by an off/on switch?
 
Thanks,
Savita


From: aspectj-users-bounces@xxxxxxxxxxx [mailto:aspectj-users-bounces@xxxxxxxxxxx] On Behalf Of Matthew Webster
Sent: Wednesday, September 06, 2006 3:18 AM
To: aspectj-users@xxxxxxxxxxx
Subject: Re: [aspectj-users] Overriding pointcuts


Savita,

Unfortunately this won't work because you can only extend abstract aspects so you cannot override the behaviour of an existing woven concrete aspect. You can override a pointcut but only in a sub-aspect:

public abstract aspect AbstractPrimitiveFlightRecorder {

        protected pointcut myMethod() :
                PrimitiveFlightRecorderPointcutLibrary.recordedMethod();

}

public aspect PrimitiveFlightRecorderAspect extends AbstractPrimitiveFlightRecorder
{
        protected pointcut myMethod()
        :   execution(!@PrimitiveDataLoggerAnnotation public * *.Method*(..));  

        before (): myMethod() {
                System.out.println("> PrimitiveFlightRecorderAspect.before() " + thisJoinPoint);
        }
       
        after (): myMethod() {
                System.out.println("< PrimitiveFlightRecorderAspect.before() " + thisJoinPoint);
        }
}

However one solution is to use a separate pointcut library which is used to weave at compile-time:

public aspect PrimitiveFlightRecorderPointcutLibrary {

        protected pointcut recordedMethod() :
                execution(@PrimitiveDataLoggerAnnotation public * *.Method*(..));

}

public aspect PrimitiveFlightRecorderAspect
{
        protected pointcut myMethod() :
                PrimitiveFlightRecorderPointcutLibrary.recordedMethod();

        before (): myMethod() {
                System.out.println("> PrimitiveFlightRecorderAspect.before() " + thisJoinPoint);
        }
       
        after (): myMethod() {
                System.out.println("< PrimitiveFlightRecorderAspect.before() " + thisJoinPoint);
        }
}

Then for LTW substitute an alternative implementation of the library. Because _all_ aspects must be woven, including those woven previously, you will pick up the new pointcut definition. Unfortunately you cannot define pointcut libraries using XML.

Matthew Webster
AOSD Project
Java Technology Centre, MP146
IBM Hursley Park, Winchester,  SO21 2JN, England
Telephone: +44 196 2816139 (external) 246139 (internal)
Email: Matthew Webster/UK/IBM @ IBMGB, matthew_webster@xxxxxxxxxx
http://w3.hursley.ibm.com/~websterm/



"Chandan, Savita" <Savita.Chandan@xxxxxxxxxxxxxx>
Sent by: aspectj-users-bounces@xxxxxxxxxxx

06/09/2006 02:43

Please respond to
aspectj-users@xxxxxxxxxxx

To
<aspectj-users@xxxxxxxxxxx>
cc
Subject
[aspectj-users] Overriding pointcuts





Hi,

I want to override pointcuts inserted in the aspect code during compile, at run time. What would I do to achieve this? If I created a pointcut in aop.xml that contradicts the pointcut inserted in the code, what would happen?

For ex.

In my aspect class
public aspect PrimitiveFlightRecorderAspect

{

       
pointcut myMethod():  execution(@ PrimitiveDataLoggerAnnotation public * *.Method*(..)) );

        before (): myMethod() {
       
}

        after (): myMethod() {}
}

Now if in the aop.xml if I were to do this. (pardon me for any mistakes in the aop.xml, this is the first time I creating one)  what would happen?

<aspectj>
       
<aspects>
               
<aspect name="PrimitiveFlightRecorderAspect"/>
               
 pointcut myMethod():  execution(! @ PrimitiveDataLoggerAnnotation public * *.Method*(..)) );

        </aspects>
</aspectj>

Thanks,

Savita
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users


Back to the top