[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[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.