Skip to main content

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

> 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.

Aspects don't know what other aspects are in effect.  This means any
coordination would have to be done by you.  Given that the same
exception will have the same hashcode you can build something in that
tracks what has or hasn't been reported already.  If the same aspect
is reporting an exception multiple times, it is possible to use
cflow/cflowbelow to report it just once.

You might want to look at
http://www.ibm.com/developerworks/rational/library/06/0711_hawkins_january/
as an article on logging/exception handling with AJ.

cheers
Andy

On 9 December 2011 08:15, Mark <mark.kharitonov@xxxxxxxxx> wrote:
> I am repeating my first email without the &lt;raw&gt; 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.
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users


Back to the top