Savita you can significantly reduce the
overhead by dynamically enabling and disabling your aspects. This can be as
simple as using the if pointcut like so
public aspect FlightRecorder {
private static boolean enabled;
// can be controlled through JMX, for example
public pointcut flightMethod():
execution(!@PrimitiveDataLoggerAnnotation
public * *.Method*(..));
private pointcut recordedMethod():
if(enabled) && flightMethod();
before() : recordedMethod() { …
}
after() : recordedMethod() { …
}
}
AspectJ constructs join points lazily when
they are guarded like this, so you should see the runtime overhead as simply
the time for a single (inlined) if test. This is often desirable, especially if
you would like to be able to enable and disable recording at runtime. You can
also allow more dynamic scoping e.g., by package and class like with logging
frameworks, possibly also with a global enabled switch. AspectJ been tuned
significantly over the years to support efficiently running when aspects like
this are disabled, but certainly you should benchmark the overhead in your
case.
Ron
From: aspectj-users-bounces@xxxxxxxxxxx
[mailto:aspectj-users-bounces@xxxxxxxxxxx] On
Behalf Of Chandan, Savita
Sent: Wednesday, September 06,
2006 10:22 AM
To: aspectj-users@xxxxxxxxxxx
Subject: 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/[1]
"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