wood burning stoves 2.0*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Business method interceptor methods (AroundInvoke methods) invocation order Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Business method interceptor methods (AroundInvoke methods) invocation order" Watch "Business method interceptor methods (AroundInvoke methods) invocation order" New topic
Author

Business method interceptor methods (AroundInvoke methods) invocation order

Xavi Sanchez
Greenhorn

Joined: Mar 11, 2008
Posts: 15
Hi.

Regarding Business method interceptor methods (AroundInvoke methods) invocation order, is this correct?

* Invocation rules:
  - If a method is overridden it will not be invoked.
  - Default order is as specified on annotation or DD element.
  - For a given level, annotated interceptors precede DD interceptors.
  - For a given class, invocation is hierarchical from most general superclass.

* Invocation order:
  - Default interceptors.
  - Class-level interceptors.
  - Method-level interceptors.
  - Bean interceptor method.

* Full order with rules applied (always non overridden AroundInvoke methods):
  - Default interceptors as specified in the DD. For each, invocation is hierarchical from most general superclass.
  - Annotated class-level interceptor classes as specified in annotation. For each, invocation is hierarchical from most general superclass.
  - DD class-level interceptor classes as specified in DD. For each, invocation is hierarchical from most general superclass.
  - Annotated method-level interceptor classes as specified in annotation. For each, invocation is hierarchical from most general superclass.
  - DD method-level interceptor classes as specified in DD. For each, invocation is hierarchical from most general superclass.
  - Bean’s superclasses AroundInvoke methods, most general superclass first.
  - Bean’s AroundInvoke method.

Hope that I have explained...

Thank you in advance.
Xavi Sanchez
Greenhorn

Joined: Mar 11, 2008
Posts: 15
Hi.

I'm taking the exam this week.

Could anyone confirm my deductions please?

Thanks.
Marcin Faryna
Greenhorn

Joined: Jul 16, 2009
Posts: 15
What about super-class annotated interceptors are they inherited?


SCJP 6, SCBCD 5
Marcin Faryna
Greenhorn

Joined: Jul 16, 2009
Posts: 15
I think i figured it out:
1.Default interceptors with order in DD (method level default interceptors can be invoked first if they are defined in such order in DD)
2.Bean class level annotated interceptors with order declared in annotation (if such interceptor has parent, this parent will be invoked first)
3.Bean parent class level annotated interceptors with order declared in annotation
4.DD class level interceptors order defined in DD
5.Bean method level annotated interceptors with order declared in annotation (if such interceptor has parent, this parent will be invoked first)
6.DD method level interceptors with order declared in annotation (if such interceptor has parent, this parent will be invoked first)
7.Bean class parent (if any) defined interceptor
8.Bean class itself defined interceptor

Hope that's all

Marcin Faryna
Greenhorn

Joined: Jul 16, 2009
Posts: 15
This order is valid for jboss.
seb tetris
Greenhorn

Joined: Jan 07, 2011
Posts: 4
Marcin Faryna wrote:What about super-class annotated interceptors are they inherited?


see 12.3.1
If an interceptor class itself has superclasses, the interceptor methods defined by the interceptor
class’s superclasses are invoked before the interceptor method defined by the interceptor class,
most general superclass first.

T. Huy Nguyen
Ranch Hand

Joined: Nov 02, 2010
Posts: 57
Hi,

Below is what I prepared for my exam. The > sign denotes the order of invocation. Hope it help.

- Invocation order:
+ Default interceptors > Class interceptors > Method interceptors > Bean’s interceptor methods
+ Within same group, invocation order is the same as order of specification. If DD is used to augment annotation, annotation > DD
+ Within same class (bean or interceptor class), super-classes' interceptor > current class’ interceptor. If an interceptor method is overridden by another method (regardless of whether that method is itself an interceptor method), it will not be invoked.

- DD interceptor-order element can be used to override the default order specified in annotation. However, when used, developer must specify the total ordering of interceptors

(https://sites.google.com/site/mostlyjava/scbcd/02-general-ejb-3-0-enterprise-bean-knowledge)

My material for SCJP (2008), SCWCD (2010), SCBCD (2010). About me
Marcin Faryna
Greenhorn

Joined: Jul 16, 2009
Posts: 15
Yes but there is specific situation which i cannot find in JSR220:



In this case in glassfish 3.0.1 we got:
ClassAInterceptor:perform
ClassBInterceptor:perform

but in jboss 5.1.0GA:
ClassBInterceptor:perform
ClassAInterceptor:perform

I presume that this is gap in specification and vendors implement this on their own.

T. Huy Nguyen
Ranch Hand

Joined: Nov 02, 2010
Posts: 57
I tend to agree with the result of Glassfish: If B extends A then whatever declared on A should execute first.

What do you think?
seb tetris
Greenhorn

Joined: Jan 07, 2011
Posts: 4
Marcin Faryna wrote:Yes but there is specific situation which i cannot find in JSR220:



In this case in glassfish 3.0.1 we got:
ClassAInterceptor:perform
ClassBInterceptor:perform

but in jboss 5.1.0GA:
ClassBInterceptor:perform
ClassAInterceptor:perform

I presume that this is gap in specification and vendors implement this on their own.



I agree that its a gap in the specification.
I can imagine that for a method in A that is not overridden by B only the AInterceptor is invoked. ( assuming the runttime type is B )
and if overridden first the A then the B interceptor.
and if B doesnt overrides only the BInterceptor.

 
wood burning stoves
 
subject: Business method interceptor methods (AroundInvoke methods) invocation order
 
Similar Threads
Interceptors - more than 1 @AroundInvoke - Multiple @Interceptors declared for a class/method?
multiple AroundInvoke
EJB Core spec 12.3.1 Multiple Business Method Interceptor Methods
Query rgd interceptor invocation order
Doubts - EJB 3.0