Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Why would one ever want to use Load Time Weaving?

I don't normally run with LTW in eclipse, but you can. (so I am a bit
rusty on it).

Basically you need to be running things using the weaver javaagent.
You can do this by modifying an existing launch configuration (to
include -javaagent) or use the 'AspectJ Load-Time Weaving Application'
launch configuration (So Run>RunAs> and under the aspectj entry, New
and define it appropriately - setting an aspect path that contains
your aspect).

> I am trying to understand, how to replace this compile-time aspect, which
> replaces Response.toString() invocations issued from my own code to an
> equivalent load-time aspect, which would instrument the method itself,
> rather than calls to it.

That's exactly right, one benefit of LTW is that we don't have to
instrument all the call sites, we can just instrument the target once.
 This basically means moving from a 'call' pointcut to an 'execution'
pointcut.  From:

> @Pointcut("!within(com.shunra.poc.ResponseToStringAspect) &&
> !within(com.shunra.poc.logging.LoggerAspect) &&"
>      + " call(public String toString()) && target(o)")
>  void toString(Response o) {
>  }

to

@Pointcut("execution(public String toString()) && target(o)");
void toString(Response o) {}

or possibly:

@Pointcut("execution(public String Response.toString()) && target(o)");
void toString(Response o) {}

(including the declaring type can help with matching speed and runtime
impact sometimes)

cheers
Andy

On 14 December 2011 03:45, Mark <mark.kharitonov@xxxxxxxxx> wrote:
> I know I must be testing your patience here. I have this simple aspect, which
> purpose is to customize the toString() output of a type belong to a third
> party library:
> ===========================
> package com.shunra.poc;
>
> import javax.ws.rs.core.Response;
>
> import org.aspectj.lang.annotation.Around;
> import org.aspectj.lang.annotation.Aspect;
> import org.aspectj.lang.annotation.Pointcut;
>
> @Aspect
> public class ResponseToStringAspect {
>  @Pointcut("!within(com.shunra.poc.ResponseToStringAspect) &&
> !within(com.shunra.poc.logging.LoggerAspect) &&"
>      + " call(public String toString()) && target(o)")
>  void toString(Response o) {
>  }
>
>  @Around("toString(o)")
>  public String responseToString(Response o) {
>    Object entity = o.getEntity();
>    return entity == null ? "null" : entity.toString();
>  }
> }
> ===========================
>
> I am trying to understand, how to replace this compile-time aspect, which
> replaces Response.toString() invocations issued from my own code to an
> equivalent load-time aspect, which would instrument the method itself,
> rather than calls to it.
>
> Specifically, what are the steps to do it in Eclipse?
>
> Thank you very much.
>
> --
> View this message in context: http://aspectj.2085585.n4.nabble.com/Why-would-one-ever-want-to-use-Load-Time-Weaving-tp4181328p4194579.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