-
1. Re: Are names supposed to be unique in JBoss AOP?
flavia.rainone Apr 9, 2008 3:59 PM (in response to danamin)Hi!
It is expected that JBoss AOP would create four instances of aspects instead of two.
This is true because an interceptor tag declares a new interceptor to JBoss AOP. Whether you have more than one interceptor declaration with the same class is not relevant. Look at the example below:<bind pointcut="execution(static * POJO->*(..))"> <interceptor class="MethodInterceptor name="interceptor1"/> </bind> <bind pointcut="execution(* POJO$Bar->*(..))"> <interceptor class="MethodInterceptor" name="interceptor2"/> </bind>
In the xml tags above two different interceptors, with the same class, are declared. Their names are "interceptor1" and "interceptor2". If their names are not defined, JBoss AOP creates a name for those interceptors.
So, if you want to use a single interceptor, i.e., to have only one aspect definition generated to represent your interceptor, you should do something like this:<interceptor class="MethodInterceptor name="interceptor1"/> <bind pointcut="execution(static * POJO->*(..))"> <interceptor-ref name="interceptor1"/> </bind> <bind pointcut="execution(* POJO$Bar->*(..))"> <interceptor-ref name="interceptor1"/> </bind>
However, it looks like JBoss AOP does create two interceptors with the same name when the name attributes are not defined. I will do some investigation before answering this part of your question. -
2. Re: Are names supposed to be unique in JBoss AOP?
flavia.rainone Apr 9, 2008 4:07 PM (in response to danamin)Hi again,
I have taken a deeper look at the code, and now I see that JBoss AOP does not generate another aspect class to represent the same interceptor. When the attribute name is ommitted, JBoss AOP names the AspectDefinition object after the class of the interceptor. I.e., the declaration below:<bind pointcut="execution(* POJO$Bar->*(..))"> <interceptor class="MethodInterceptor"/> </bind>
Will generate an AspectDefinition named "MethodInterceptor". When another binding with the same interceptor tag is found (and with the name attribute ommitted again), JBoss AOP looks for an AspectDefinition named "MethodInterceptor" instead of creating another AspectDefinition.
So, in the example you gave, JBoss AOP creates an AspectDefinition to represent SimpleInterceptor when it finds the first binding. When it finds the second one, it creates an AspectDefinition named MethodInterceptor. In the next bindings, it realizes it already has an AspectDefinition named MethodInterceptor and reuses this definition instead of creating extra AspectDefinitions. -
3. Re: Are names supposed to be unique in JBoss AOP?
danamin Apr 9, 2008 5:20 PM (in response to danamin)Ah yes, correct,
It is indeed
1 SimpleInterceptor with an invoke advice and
1 MethodInterceptor with 3 invoke advices
So the issue with interceptors remains
Wouter -
4. Re: Are names supposed to be unique in JBoss AOP?
flavia.rainone Apr 14, 2008 10:52 AM (in response to danamin)Wouter
You are right. I have created a Jira ssue to fix this bug:
http://jira.jboss.com/jira/browse/JBAOP-554
Thanks for pointing this out.