Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [aspectj-users] Excluding Particular Joinpoints

Just to add to Gregor’s point, which is a natural and simple way to handle
this in a concrete aspect. You can extend the approach to allow configuring
concrete reusable aspects without extending them by using a strategy
pattern. The Glassbox Inspector project
(https://glassbox-inspector.dev.java.net//) uses a FailureDetectionStrategy
for this purpose, which allows you to configure which exceptions should be
tracked as errors. This is the core of the code:

public interface FailureDetectionStrategy {
    boolean isFailure(Throwable t, StaticPart staticPart);
}

Then in a reusable base aspect it has advice like this
...
    after(RequestContext requestContext) throwing (Throwable t) :
requestExecution(requestContext) {
        PerfStats stats = requestContext.getStats();
        if (stats != null) {
            if (failureDetectionStrategy.isFailure(t,
thisJoinPointStaticPart)) {
                requestContext.recordFailure(t);
...

Again, the reason for having a strategy pattern is to allow configuration of
what failures the concrete subaspects should track. This is also discussed
in more depth in the my article Performance monitoring with AspectJ, Part 2
(see http://www-128.ibm.com/developerworks/java/library/j-aopwork12/#N102A0
for the relevant section) 

________________________________________
From: aspectj-users-bounces@xxxxxxxxxxx
[mailto:aspectj-users-bounces@xxxxxxxxxxx] On Behalf Of Gregor Kiczales
Sent: Wednesday, November 30, 2005 1:26 PM
To: aspectj-users@xxxxxxxxxxx
Subject: RE: [aspectj-users] Excluding Particular Joinpoints

________________________________________
From: aspectj-users-bounces@xxxxxxxxxxx
[mailto:aspectj-users-bounces@xxxxxxxxxxx] On Behalf Of Tobias Dunn-Krahn

I am using AspectJ in a project to log all handled exceptions.  In general
this is what I want, but in a small number of cases such exceptions are
“expected” and I do not wish to log them. 
 
aspect FooBarExceptionLoggingStrategy {
  
  before(Throwable t): handler(Throwable) && args(t) {
    if( shouldLog(t) )
       log(t);
  }
 
  private boolean shouldLog(Throwable t) {
    <<test whatever needs testing here>>
  }
 
  private void log(Throwable t) {
    ...
  }
}
 
The point being that you can test the exception in any way you want before
logging it. 
You could also pass thisJoinPoint or thisJoinPointStaticPart. If you want,
you could
move shouldLog into the actual pointcut, using if(shouldLog(t)).

  

________________________________________
From: aspectj-users-bounces@xxxxxxxxxxx
[mailto:aspectj-users-bounces@xxxxxxxxxxx] On Behalf Of Tobias Dunn-Krahn
Sent: Wednesday, November 30, 2005 11:42 AM
To: aspectj-users@xxxxxxxxxxx
Subject: [aspectj-users] Excluding Particular Joinpoints
Hello All,

I am using AspectJ in a project to log all handled exceptions.  In general
this is what I want, but in a small number of cases such exceptions are
“expected” and I do not wish to log them.  My pointcut definition is
currently very simple; it matches all exception handlers except those that
handle SocketTimeoutExceptions:

  pointcut exceptionHandlers(Throwable t) : handler(Throwable+) && (args(t)
      && !args(java.net.SocketTimeoutException));

However, now I need to exclude matching of particular exception handlers
that are not distinguishable by type.  I tried creating a custom annotation
with target type LOCAL_VARIABLE and using this annotation to decorate the
exception, but unfortunately annotations of this type are not retained for
runtime (and are therefore inaccessible).  Does anyone have any suggestions?

Thanks in advance,
Tobias




Back to the top