[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] How to exclude nested matching method executions?

I am repeating my first email without the <raw> tags:
#####################################################
I have this abstract logging aspect, which instruments before, after
returning and after throwing of certain methods. In addition, there are two
concrete derived aspects, each specifying the set of methods to be logged.
The methods affected by one aspect can be invoked from the methods affected
by the other aspect. Which is fine for before and after returning, but
problematic for after throwing, which should log the exception only for the
lowest method in the call stack.

Here is the abstract aspect declaration:
=============================================================
public abstract aspect LoggingAspect {
  declare parents: (@LogMe *) implements ILoggable;
  
  public Logger ILoggable.getLogger() {
    LoggerHolderAspect holder =
LoggerHolderAspect.aspectOf(this.getClass());
    return holder.getLogger();
  }

  abstract pointcut loggedMethods();
  
  before(ILoggable o): loggedMethods() && this(o) {
    logBefore(o.getLogger(), thisJoinPoint);
  }

  after(ILoggable o) returning (Object result): loggedMethods() && this(o) {
    logAfterReturning(o.getLogger(), thisJoinPoint, result);
  }
  
  after(ILoggable o) throwing (Exception e): loggedMethods() && this(o) {
    logAfterThrowing(o.getLogger(), thisJoinPoint, e);
  }

  protected void logBefore(Logger l, JoinPoint jp) { ... }
  protected void logAfterReturning(Logger l, JoinPoint jp, Object result) {
... }
  protected void logAfterThrowing(Logger l, JoinPoint jp, Exception e) { ...
}
}
=============================================================


Here is the first derived concrete aspect:
=============================================================
public aspect ResourceHandlerLoggingAspect extends LoggingAspect {
  declare @type : @Path * : @LogMe;
  
  pointcut loggedMethods() : within(@Path *) && execution(@(GET || PUT ||
POST || DELETE) public * *.*(..));
}
=============================================================


And here is the second derived concrete aspect:
=============================================================
public aspect ServiceLoggingAspect extends LoggingAspect {
  declare @type : com.shunra.poc..*Service : @LogMe;
  
  pointcut loggedMethods() : within(com.shunra.poc..*Service) &&
execution(public * *.*(..));
}
=============================================================


My question is how to make the after throwing advice ignored for a method A,
if it is invoked from a method B, which is also instrumented? The point of
all of this is to have a single exception dump in the log.

I must add that I have read the example in the Programming Guide
(http://www.eclipse.org/aspectj/doc/released/progguide/starting-production.html),
but I am failing to reproduce this behavior with my aspects.

Thank you very much. 



--
View this message in context: http://aspectj.2085585.n4.nabble.com/How-to-exclude-nested-matching-method-executions-tp4172075p4177192.html
Sent from the AspectJ - users mailing list archive at Nabble.com.