Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] LTW + Annotations + Intertype + Declare Parents = problems


Brian,

I have adapted your testcase slighty (below) and added an implementation of CallbackDispatcher. The code runs OK under AJDT version 1.4.1.20060728033634 using the "Load-Time Weaving Application" launcher. I will also try it with 1.5.2a.

[WeavingURLClassLoader] info AspectJ Weaver Version DEVELOPMENT built on Wednesday Jul 26, 2006 at 09:22:19 GMT
[WeavingURLClassLoader] info register classloader org.aspectj.weaver.loadtime.WeavingURLClassLoader
[WeavingURLClassLoader] info using configuration /C:/workspaces/org.aspectj/zzz/bin/META-INF/aop.xml
[WeavingURLClassLoader] info register aspect ServiceDispatchAspect
[WeavingURLClassLoader] info weaving 'Test'
[WeavingURLClassLoader] info weaving 'MyCallbackImpl'
[WeavingURLClassLoader] info processing reweavable type MyCallbackImpl: MyCallbackImpl.java
[WeavingURLClassLoader] info successfully verified type ServiceDispatchAspect exists.  Originates from C:\workspaces\org.aspectj\zzz\brian_a_yoffe\ServiceDispatchAspect.aj
[WeavingURLClassLoader] weaveinfo Extending interface set for type 'MyCallbackImpl' (MyCallbackImpl.java) to include 'ServiceDispatchAspect$CallbackDispatchable' (ServiceDispatchAspect.aj)
[WeavingURLClassLoader] weaveinfo Type 'MyCallbackImpl' (MyCallbackImpl.java) has intertyped field from 'ServiceDispatchAspect' (ServiceDispatchAspect.aj:'CallbackDispatcher ServiceDispatchAspect$CallbackDispatchable.callbackDispatcher')
[WeavingURLClassLoader] weaveinfo Join point 'constructor-execution(void MyCallbackImpl.<init>())' in Type 'MyCallbackImpl' (MyCallbackImpl.java:2) advised by after advice from 'ServiceDispatchAspect' (ServiceDispatchAspect.aj:15)
[WeavingURLClassLoader] weaveinfo Join point 'method-execution(void MyCallbackImpl.doWork())' in Type 'MyCallbackImpl' (MyCallbackImpl.java:4) advised by around advice from 'ServiceDispatchAspect' (ServiceDispatchAspect.aj:27)
[WeavingURLClassLoader] info generating class 'MyCallbackImpl$AjcClosure1'
[WeavingURLClassLoader] info weaving 'MyCallback'
[WeavingURLClassLoader] info weaving 'ServiceDispatchAspect$CallbackDispatchable'
[WeavingURLClassLoader] info processing reweavable type ServiceDispatchAspect$CallbackDispatchable: ServiceDispatchAspect.aj
[WeavingURLClassLoader] info successfully verified type ServiceDispatchAspect exists.  Originates from C:\workspaces\org.aspectj\zzz\brian_a_yoffe\ServiceDispatchAspect.aj
[WeavingURLClassLoader] weaveinfo Type 'ServiceDispatchAspect$CallbackDispatchable' (ServiceDispatchAspect.aj) has intertyped field from 'ServiceDispatchAspect' (ServiceDispatchAspect.aj:'CallbackDispatcher ServiceDispatchAspect$CallbackDispatchable.callbackDispatcher')
[WeavingURLClassLoader] info weaving 'ServiceDispatchAspect'
[WeavingURLClassLoader] info processing reweavable type ServiceDispatchAspect: ServiceDispatchAspect.aj
[WeavingURLClassLoader] info weaving 'CallbackDispatcher'
CallbackDispatcher.dispatch()

public aspect ServiceDispatchAspect {
       
    public interface CallbackDispatchable {
    }

    private CallbackDispatcher CallbackDispatchable.callbackDispatcher;

    declare parents : (@ServiceCallback *) extends CallbackDispatchable;

    protected pointcut callbackConstruction(CallbackDispatchable callback) :
                execution(CallbackDispatchable+.new(..))
                && this(callback);

     // this works in compile time weaving - nothing in load time weaving
    after(final CallbackDispatchable callback) :
            callbackConstruction(callback) {
//                callback.callbackDispatcher = createDispatcher(XYZ);
            callback.callbackDispatcher = new CallbackDispatcher();
    }

    protected pointcut serviceVoidCallbackMethodExecution(CallbackDispatchable callback) :
        execution(public void (@ServiceCallback *).*(..)) &&
        !execution(* Object.*(..)) &&
        this(callback);
   
    // this throws an AbstractMethodError at first access of callback.callbackDispatcher
    void around(final CallbackDispatchable callback) :
            serviceVoidCallbackMethodExecution(callback) {
            callback.callbackDispatcher.dispatch();
       
    }
}

public class CallbackDispatcher {

       
        public void dispatch () {
                System.out.println("CallbackDispatcher.dispatch()");
        }
}

Matthew Webster
AOSD Project
Java Technology Centre, MP146
IBM Hursley Park, Winchester,  SO21 2JN, England
Telephone: +44 196 2816139 (external) 246139 (internal)
Email: Matthew Webster/UK/IBM @ IBMGB, matthew_webster@xxxxxxxxxx
http://w3.hursley.ibm.com/~websterm/



brian.a.yoffe@xxxxxxxxxxxx
Sent by: aspectj-users-bounces@xxxxxxxxxxx

22/08/2006 19:15

Please respond to
aspectj-users@xxxxxxxxxxx

To
aspectj-users@xxxxxxxxxxx
cc
Subject
[aspectj-users] LTW + Annotations + Intertype + Declare Parents =        problems






Okay, I'll do my best to distill this problem (or series of problems) into simpler test cases, but for now, I have two distinct problems.   I am using aspectj 1.5.2a.   I have verified that my aspect performs as expected when using comple time weaving, and fails when using LTW.


The first problem is that a constructor pointcut is not properly being matched to a constructor joinpoint that it should.   Specifically, I've created a callback annotation called ServiceCallback.   The intent is mark callback interfaces so that at runtime, we can intercept calls to any method declared on a CallabckService interface and dispatch it appropriately.   So, I've decided that I'd like to create the appropriate kind of callback dispatcher when any class that implements an interface marked with @ServiceCallback is created.


Because I want to create the callback dispatcher 1 time per @ServiceCallback object, I want to store the callback dispatcher on the @ServiceCallback object directly.   Thus, I've created a CallbackDispatchable interface within this aspect, and introduced a field callbackDispatcher on the interface to store the dispatcher.


For example:


public @interface ServiceCallback;


@ServiceCallback

public interface MyCallback {

  void doWork();

}


public MyCallbackImpl implements MyCallback {

  void doWork();

}


Therefore, given the advice below, MyCallback should CallbackDispatchable because of the declare parents clause.   Since MyCallbackImpl implements MyCallback, which extends CallbackDispatchable, when I create a new instance of MyCallbackImpl, the callbackConstruction pointcut should match.   In fact, it does with ctw, but not ltw.


The next problem I'm having has to do with accessing the introduced field, callbackDispatcher.    Advice on the serviceVoidCallbackMethodExecution pointcut should allow me to access the callbackDispatcher without an issue.   In fact, it does in ctw, but in ltw, the following error occurs:


java.lang.AbstractMethodError: ...CallbackImpl.ajc$interFieldGet$

aspectj_ServiceDispatchAspect$

aspectj_ServiceDispatchAspect$CallbackDispatchable$callbackDispatcher()L.../CallbackDispatcher;




Thanks in advance
Brian Yoffe





Code for the aspect follows:


public aspect ServiceDispatchAspect {

       
   public interface CallbackDispatchable {

   }


   private CallbackDispatcher CallbackDispatchable.callbackDispatcher;


   declare parents : (@ServiceCallback *) extends CallbackDispatchable;


   protected pointcut callbackConstruction(CallbackDispatchable callback) :

               execution(CallbackDispatchable+.new(..))
               && this(callback);


    // this works in compile time weaving - nothing in load time weaving

   after(final CallbackDispatchable callback) :
           callbackConstruction(callback) {

               callback.callbackDispatcher = createDispatcher(XYZ);

       }


   protected pointcut serviceVoidCallbackMethodExecution(CallbackDispatchable callback) :

       execution(public void (@ServiceCallback *).*(..)) &&

       !execution(* Object.*(..)) &&

       this(callback);

   
   // this throws an AbstractMethodError at first access of callback.callbackDispatcher

   void around(final CallbackDispatchable callback) :
           serviceVoidCallbackMethodExecution(callback) {


     
 
   }




LTW summary:


weaveinfo Extending interface set for type 'MyCallback' (MarketDataCallback.java) to include 'ServiceDispatchAspect$CallbackDispatchable' (ServiceDispatchAspect.aj)


weaveinfo Join point 'method-execution(void MyServiceImpl.doWork())' in Type 'MyServiceImpl' (MyServiceImpl.java:0) advised by around advice from 'ServiceDispatchAspect' (ServiceDispatchAspect.aj:0) [with runtime test]



This communication is for informational purposes only. It is not intended as an offer or solicitation for the purchase or sale of any financial instrument or as an official confirmation of any transaction. All market prices, data and other information are not warranted as to completeness or accuracy and are subject to change without notice. Any comments or statements made herein do not necessarily reflect those of JPMorgan Chase & Co., its subsidiaries and affiliates.

This transmission may contain information that is privileged, confidential, legally privileged, and/or exempt from disclosure under applicable law. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution, or use of the information contained herein (including any reliance thereon) is STRICTLY PROHIBITED. Although this transmission and any attachments are believed to be free of any virus or other defect that might affect any computer system into which it is received and opened, it is the responsibility of the recipient to ensure that it is virus free and no responsibility is accepted by JPMorgan Chase & Co., its subsidiaries and affiliates, as applicable, for any loss or damage arising in any way from its use. If you received this transmission in error, please immediately contact the sender and destroy the material in its entirety, whether in electronic or hard copy format. Thank you.
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users


Back to the top