The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

JohnJPS (6) [Avatar] Offline
#1
I saw your talk at EclipseWorld and was very impressed; I now have the book, well-written, and am looking at using some for a performance logging aspect... since we don't want to just have it on or off for everything, I'd like to deliver a solution wherein developers can designate a method using a dummy annotation, e.g. in the application:

@LogPerformance
public void someMethod(args) { ... }

then my aspect will pick things up from there:

package com.blah.logging.aspects;
public abstract aspect PerformanceLoggingAspect {
pointcut performanceLoggedObjects : execution(????);
public abstract Logger getLogger();
Object around() : performanceLoggedObjects() {
getLogger().perf(thisJoinPointStaticPart.toLongString() + ": PerformanceLog-entrance");
Object ret = proceed();
getLogger().perf(thisJoinPointStaticPart.toLongString() + ": PerformanceLog-exit");
return ret;
}
}

I think the overall idea is pretty straightforward but I don't know how to properly define the pointcut so that it targets just methods that are so annotated. Comments/tips/hints appreciated. Thanks.
JohnJPS (6) [Avatar] Offline
#2
Re: Using annotations in target for a pointcut
To answer my own question:

public pointcut perfLoggedOps() : execution(@LogPerformance * * (..));

(although eclipse still gives me an error on that line under the final semicolon:
"Syntax error on token ";", Type expected after this token") I suspect I'll figure that one out soon enough.

I should reference your article here, since that's where I found a ton of good info on just this kind of stuff:
http://www-128.ibm.com/developerworks/java/library/j-aopwork3/

Thanks!
ramnivas (171) [Avatar] Offline
#3
Re: Using annotations in target for a pointcut
John,

Thanks for attending my EclipseWorld talk.

I just tried your pointcut; it seems to work just fine. Let me know if you are still facing that problem.

-Ramnivas
JohnJPS (6) [Avatar] Offline
#4
Re: Using annotations in target for a pointcut
The warning had to do with some code following the pointcut statement that needed a return type specification. I found a bug report for ajc for just this issue, to make it warn about the following function rather than the pointcut; but based on the bug report details I was able to figure it out.
Thanks,
John