Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

multiple interceptor execution order

 
Himai Minh
Ranch Hand
Posts: 1361
7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From my understanding of Interceptor 1.1 spec from Oracle p.6

Multiple method interceptor methods are executed in this order:
1.default interceptor
2. interceptor class defined in @Interceptor() may have superclass. The interceptor methods in the super classes
are invoked.

3. the interceptors defined in @Interceptors().
4. class interceptor methods defined in the target class itself.

5. @AroundInvoke methods in target class's super classes
6. method level interceptors in target class
7. @AroundInvoke methods of the target class


Frits' notes:
1. interceptor's superclass.
2. Default interceptor
3. target class's superclass's @AroundInvoke methods
4. class interceptor bound by @Interceptor
5. method level interceptors bounded by @Interceptor
6. @AroundInvoke method on the target class.

From Frit's notes, the order is a little bit different.
Difference 1 : In the Oracle specification, the default interceptor is invoked first before the super classes of the interceptor defined in @Interceptor.

Difference 2: In the Oracle spec, step 3-5, it seems the interceptor defined in @Interceptor on the target class is invoked before the interceptor defined in the target class's super class.
But in step 3-4 of Frit's notes, it seems that the interceptor in the target's super class is invoked before the interceptor bound by @Interceptor on the target class itself.


Please advice.

 
Himai Minh
Ranch Hand
Posts: 1361
7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think I am able to answer my own question. I thought those steps are the orders of interceptor execution. But they are not the orders. That makes sense now.
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2536
113
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Himai,

It makes sense to follow the ordering of the Interceptor 1.1 spec. I will change my notes in the coming days.

Thanks for pointing that out!

Regards,
Frits
 
Himai Minh
Ranch Hand
Posts: 1361
7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Frits,
On p. 6 of Interceptor 1.1 specification, it says
"If multiple method interceptor methods are defined for a target class, the following rules governing their invocation order apply. The deployment descriptor may be used to override the interceptor invocation order specified in annotations.
. default interceptor, if any, are invoked first...
. ... interceptor classes associated with the target class using the Interceptors annotation, the interceptor methods defied by those interceptor classes are invoked before any interceptor method defined on the target class.
. The around-invoke method defined on those interceptor classes are invoked in the same order as the specification of the interceptor classes in the Interceptors annotation....
and etc


From this quote, it does not say the order of interceptor method invocation must be default interceptor first , @Interceptor is the next, @AroundInvoke defined in those @Interceptor (....) is next and so on.
So, I think your notes is fine.

But this has to be in order:

After the interceptor methods defined on interceptor classes have been invoked, then in order:
. any method-level interceptor for the target class
. around invoke methods of target class's super class
. around invoke method of the target class.



 
Himai Minh
Ranch Hand
Posts: 1361
7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By the way, I found this web site http://what-when-how.com/enterprise-javabeans-3/aop-in-the-ejb-world-interceptors/ about AOP in EJB.

It presents a nice diagram in figure 5.4 saying default interceptors are invoked first, then class level interceptors and last method level interceptor although it is counter intuitive.
Also table 5.3 shows the differences between business method interceptors and lifecycle callback interceptors.

It is a good reference for everyone.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic