Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-dev] A little help with perthis/pertarget ...

I actually went down that route but, the advice quit kicking in at run time. It was still being weaved in through. In did notice under the "Per-object aspects" section here (http://www.websearchking.com/?q=aspectj&c=15) that is states "The advice defined in A will run only at a join point where the currently executing object has been associated with an instance of A.". Is there something special that I need to do the the actual pointcut to "associate" the execution thread with the aspect? I did try adding "&& this(o)" but, I am not exactly sure what I'm doing.

On Thu, Jul 10, 2008 at 11:20 AM, Eric Bodden <eric.bodden@xxxxxxxxxxxxxx> wrote:
aspect ProfileAspect perthis(execution(* *Service.* (..))) {...

does not work for you?

Eric

2008/7/10 Dan Bush <dan.bush@xxxxxxxxx>:
> Can anyone help me refactor this aspect so that it's not a singleton? I have
> attempted to use both perthis and pertarget but when I do, the advice no
> longer kicks in. The aspect is actually picking out all the methods on my
> EJB tier so there are multiple threads in flight here. I want an instance of
> the aspect per each thread. I was and want to simply have a "private long
> start;" instead of a "private Hashtable ht = new Hashtable();" but, I had to
> introduce the Hashtable so my singleton aspect would work properly. Here is
> my aspect as it currently exists. Again it works as expected but, I want to
> utilize perthis or pertarget as opposed to incurring the overhead with the
> Hashmap approach.
>
>
> package com.xxx.aspect;
>
> import org.slf4j.*;
> import javax.ejb.*;
> import com.xxx.ejb.stateless.*;
> import java.util.*;
>
> /**
> * Profiles
> */
> aspect ProfileAspect {
>
>     private Hashtable ht = new Hashtable();
>
>     private static final Logger LOG = LoggerFactory
>     .getLogger("com.ing.uds.
> aspect.ProfileAspect");
>
>         pointcut services(): (execution(* *Service.* (..)));
>
>     before(): services() {
>         ht.put(thisJoinPoint.getThis(), new
> Long(System.currentTimeMillis()));
>     }
>
>     after(): services() {
>         LOG.debug("{}|{}", thisJoinPoint,
> Long.toString(System.currentTimeMillis()-((Long)ht.get(thisJoinPoint.getThis())).longValue()));
>       }
>
> }
> _______________________________________________
> aspectj-dev mailing list
> aspectj-dev@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-dev
>
>



--
Eric Bodden
Sable Research Group
McGill University, Montréal, Canada
_______________________________________________
aspectj-dev mailing list
aspectj-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-dev


Back to the top