Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Lazy weaving vs eager weaving?

Is the static initializer for your aspect (XQServiceAspect) doing
something?  If it is touching types whose constructors will be
instrumented, that can lead to an issue.  Some affected type will be
advised.  When that type calls 'XQServiceAspect.aspectOf()' to get the
instance on which to call the advice, the static initializer for
XQServiceAspect will run, when that initializer runs, if it touches
another type whose constructor is also advised you get into a kind of
loop where things just can't work.  The constructors cannot call the
aspect because the aspect can't initialize until the constructors are
finished.

In that scenario maybe move any initialization logic from the static
initialization into an initialize method and then in advice have some
kind of 'ensureInitialized()' logic.

Of course, if your aspect static initializer isn't doing anything, I'm
talking nonense :)

Oh, I guess you could also try a cflow to get around it, something like:
after(): execution(*.new(..)) &&
!within(com.ncr.eai.esb.aop.XQServiceAspect) &&
!cflow(staticinitialization(XQServiceAspect)) {

which says 'I am interested in execution of constructors that aren't
XQServiceAspect constructors, and aren't called due to XQServiceAspect
static initialization.  This will mean you miss a few as the aspect
initializes, but you should catch them all after that.

Andy

On 25 March 2011 12:50, Grey, Lee <Lee.Grey@xxxxxxx> wrote:
> This:
>
>        after(): execution(*.new(..)) && !within(com.ncr.eai.esb.aop.XQServiceAspect) {
>                System.out.println("*---------* ctor: " + thisJoinPointStaticPart.getSignature());
>        }
>
> Is causing this:
>
> [11/03/25 15:42:07] (severe) Failed to load ID=dev_ESBCore, trace follows...
> org.aspectj.lang.NoAspectBoundException: Exception while initializing com_ncr_eai_esb_aop_XQServiceAspect: java.lang.ExceptionInInitializerError
>        at com.ncr.eai.esb.aop.XQServiceAspect.aspectOf(XQServiceAspect.aj:1)
>        at com.sonicsw.xqimpl.service.XQContainer.<init>(Unknown Source)
>        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
>        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
>        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
>        at java.lang.reflect.Constructor.newInstance(Unknown Source)
>        at java.lang.Class.newInstance0(Unknown Source)
>        at java.lang.Class.newInstance(Unknown Source)
>        at com.sonicsw.mf.framework.agent.ContainerImpl.internalLoadComponent(ContainerImpl.java:3272)
>        at com.sonicsw.mf.framework.agent.ContainerImpl.loadComponent(ContainerImpl.java:1246)
>        at com.sonicsw.mf.framework.agent.ContainerImpl.loadConfiguredComponent(ContainerImpl.java:465)
>        at com.sonicsw.mf.framework.agent.ContainerImpl.loadConfiguredComponents(ContainerImpl.java:3999)
>        at com.sonicsw.mf.framework.agent.ContainerImpl.loadAllConfiguredComponents(ContainerImpl.java:3835)
>        at com.sonicsw.mf.framework.agent.ContainerImpl.bootFramework(ContainerImpl.java:2305)
>        at com.sonicsw.mf.framework.agent.ContainerImpl.<init>(ContainerImpl.java:313)
>        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
>        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
>        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
>        at java.lang.reflect.Constructor.newInstance(Unknown Source)
>        at com.sonicsw.mf.framework.agent.ci.Agent.<init>(Agent.java:139)
>        at com.sonicsw.mf.framework.agent.ci.Agent.main(Agent.java:58)
> Caused by: java.lang.ExceptionInInitializerError
>        at com.ncr.eai.esb.aop.XQServiceAspect.<clinit>(XQServiceAspect.aj:26)
>        ... 20 more
> Caused by: org.aspectj.lang.NoAspectBoundException: com_ncr_eai_esb_aop_XQServiceAspect
>        at com.ncr.eai.esb.aop.XQServiceAspect.aspectOf(XQServiceAspect.aj:1)
>        at com.ncr.eai.esb.heartbeat.ServiceMetricsHandler.<init>(ServiceMetricsHandler.groovy:3)
>        at com.ncr.eai.esb.heartbeat.HeartBeatBean.<clinit>(HeartBeatBean.java:13)
>        ... 21 more
> Caused by...
> java.lang.ExceptionInInitializerError
>        at com.ncr.eai.esb.aop.XQServiceAspect.<clinit>(XQServiceAspect.aj:26)
>        at com.sonicsw.xqimpl.service.XQContainer.<init>(Unknown Source)
>        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
>        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
>        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
>        at java.lang.reflect.Constructor.newInstance(Unknown Source)
>        at java.lang.Class.newInstance0(Unknown Source)
>        at java.lang.Class.newInstance(Unknown Source)
>        at com.sonicsw.mf.framework.agent.ContainerImpl.internalLoadComponent(ContainerImpl.java:3272)
>        at com.sonicsw.mf.framework.agent.ContainerImpl.loadComponent(ContainerImpl.java:1246)
>        at com.sonicsw.mf.framework.agent.ContainerImpl.loadConfiguredComponent(ContainerImpl.java:465)
>        at com.sonicsw.mf.framework.agent.ContainerImpl.loadConfiguredComponents(ContainerImpl.java:3999)
>        at com.sonicsw.mf.framework.agent.ContainerImpl.loadAllConfiguredComponents(ContainerImpl.java:3835)
>        at com.sonicsw.mf.framework.agent.ContainerImpl.bootFramework(ContainerImpl.java:2305)
>        at com.sonicsw.mf.framework.agent.ContainerImpl.<init>(ContainerImpl.java:313)
>        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
>        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
>        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
>        at java.lang.reflect.Constructor.newInstance(Unknown Source)
>        at com.sonicsw.mf.framework.agent.ci.Agent.<init>(Agent.java:139)
>        at com.sonicsw.mf.framework.agent.ci.Agent.main(Agent.java:58)
> Caused by: org.aspectj.lang.NoAspectBoundException: com_ncr_eai_esb_aop_XQServiceAspect
>        at com.ncr.eai.esb.aop.XQServiceAspect.aspectOf(XQServiceAspect.aj:1)
>        at com.ncr.eai.esb.heartbeat.ServiceMetricsHandler.<init>(ServiceMetricsHandler.groovy:3)
>        at com.ncr.eai.esb.heartbeat.HeartBeatBean.<clinit>(HeartBeatBean.java:13)
>        ... 21 more
> Caused by...
> org.aspectj.lang.NoAspectBoundException: com_ncr_eai_esb_aop_XQServiceAspect
>        at com.ncr.eai.esb.aop.XQServiceAspect.aspectOf(XQServiceAspect.aj:1)
>        at com.ncr.eai.esb.heartbeat.ServiceMetricsHandler.<init>(ServiceMetricsHandler.groovy:3)
>        at com.ncr.eai.esb.heartbeat.HeartBeatBean.<clinit>(HeartBeatBean.java:13)
>        at com.ncr.eai.esb.aop.XQServiceAspect.<clinit>(XQServiceAspect.aj:26)
>        at com.sonicsw.xqimpl.service.XQContainer.<init>(Unknown Source)
>        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
>        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
>        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
>        at java.lang.reflect.Constructor.newInstance(Unknown Source)
>        at java.lang.Class.newInstance0(Unknown Source)
>        at java.lang.Class.newInstance(Unknown Source)
>        at com.sonicsw.mf.framework.agent.ContainerImpl.internalLoadComponent(ContainerImpl.java:3272)
>        at com.sonicsw.mf.framework.agent.ContainerImpl.loadComponent(ContainerImpl.java:1246)
>        at com.sonicsw.mf.framework.agent.ContainerImpl.loadConfiguredComponent(ContainerImpl.java:465)
>        at com.sonicsw.mf.framework.agent.ContainerImpl.loadConfiguredComponents(ContainerImpl.java:3999)
>        at com.sonicsw.mf.framework.agent.ContainerImpl.loadAllConfiguredComponents(ContainerImpl.java:3835)
>        at com.sonicsw.mf.framework.agent.ContainerImpl.bootFramework(ContainerImpl.java:2305)
>        at com.sonicsw.mf.framework.agent.ContainerImpl.<init>(ContainerImpl.java:313)
>        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
>        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
>        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
>        at java.lang.reflect.Constructor.newInstance(Unknown Source)
>        at com.sonicsw.mf.framework.agent.ci.Agent.<init>(Agent.java:139)
>        at com.sonicsw.mf.framework.agent.ci.Agent.main(Agent.java:58)
>
> I don't know why, but I have never had any success with the "within" keyword.  Can you tell what caused this?
>
> Thanks,
> Lee
>
> -----Original Message-----
> From: aspectj-users-bounces@xxxxxxxxxxx [mailto:aspectj-users-bounces@xxxxxxxxxxx] On Behalf Of Grey, Lee
> Sent: Friday, March 25, 2011 2:34 PM
> To: aspectj-users@xxxxxxxxxxx
> Subject: Re: [aspectj-users] Lazy weaving vs eager weaving?
>
> Andy,
>
> I took your advice (#2) below, and it's been working great in development for a month.  However, it turns out that there's something different in production (not sure what) that's preventing my harmless weaving from triggering, so my aspect is never instantiated.
>
> So, I'm trying to add something to the aspect to dump out all constructors, so I can choose something else as my eager-weaving trigger.  But, so far, I either get no output, or I get org.aspectj.lang.NoAspectBoundException.
>
> I don't know what class I want to trigger on, but I am 99% certain it's in a package somewhere beneath com.sonicsw.*.  Can you see what's wrong with this?
>
>        pointcut init(Object o):
>                this(o) &&
>                within(com.sonicsw..*) &&
>                initialization(*.new());
>
>        after(Object o) returning: init(o) {
>                System.out.println("*1* ctor: " + thisJoinPointStaticPart.getSignature());
>        }
>
>        after() returning(Object o): call(*.new(..)) {
>                System.out.println("*2* ctor: " + thisJoinPointStaticPart.getSignature());
>        }
>
> Thanks,
> Lee
>
>
> -----Original Message-----
> From: aspectj-users-bounces@xxxxxxxxxxx [mailto:aspectj-users-bounces@xxxxxxxxxxx] On Behalf Of Andy Clement
> Sent: Tuesday, February 22, 2011 12:22 PM
> To: aspectj-users@xxxxxxxxxxx
> Subject: Re: [aspectj-users] Lazy weaving vs eager weaving?
>
> Hi,
>
> There is no direct control for this.  You kind of have two options:
>
> (1) touch the aspect yourself much earlier, to cause it to be loaded up.  Just refer to something in it from one of your earlier loaded classes that will cause it to be loaded.
> (2) Use it to 'harmlessly' weave something that is loaded much earlier, which kind of causes (1) to happen.
>
> cheers
> Andy
>
> On 22 February 2011 08:57, Grey, Lee <Lee.Grey@xxxxxxx> wrote:
>> Is there any way to control when an aspect gets loaded and initialized?
>>
>> Thanks,
>> Lee
>> ________________________________
>> From: aspectj-users-bounces@xxxxxxxxxxx
>> [mailto:aspectj-users-bounces@xxxxxxxxxxx] On Behalf Of Grey, Lee
>> Sent: Monday, February 21, 2011 12:58 PM
>> To: aspectj-users@xxxxxxxxxxx
>> Subject: [aspectj-users] Lazy weaving vs eager weaving?
>>
>> I'm still working on the weaving of Sonic ESB container services, and
>> it's working perfectly with one exception.
>>
>> I'm instantiating a thread object in a static block of my aspect.
>> Unfortunately, the static block doesn't execute until the first time a
>> message is received, even though the container JVM had started long ago.
>> Aside from the fact that the thread doesn't start when it should,
>> there is also a very long hit for all the class loading and weaving on
>> receipt of that first message.
>>
>> Is there any way to have the weaving occur immediately, which I'm
>> assuming would be the way to have the static block execute prior to
>> receiving a message?
>>
>> Thanks,
>> Lee Grey
>>
>> _______________________________________________
>> aspectj-users mailing list
>> aspectj-users@xxxxxxxxxxx
>> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>>
>>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>


Back to the top