Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

a mix of different types of interceptors at the method level is allowed or not?  RSS feed

 
Ranch Hand
Posts: 1701
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From JSR 318 and Interceptor 1.1 documents, I do not see these documents specify that EJB containers allow a mix of lifecycle callback and method level business method interceptors. For example,





Question: Are both AroundInvInteceptor and MyLifeCycleInterceptor allowed to intercept myInitMethod() ?
The specifications do not say this is not allowed. Does it mean it is up to the EJB containers to decide if it is allowed or not?
 
Creator of Enthuware JWS+ V6
Bartender
Posts: 3121
259
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

The specifications do not say this is not allowed. Does it mean it is up to the EJB containers to decide if it is allowed or not?


The specification does specify how to intercept a PostConstruct method, so I would be surprised if the AroundInvoke interceptor would work here. The logical way to implement this is to ignore the AroundInvoke interceptor.
 
Himai Minh
Ranch Hand
Posts: 1701
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
According to Interceptor 1.1 specification, p.11


If an interceptor class that is only used as a method level interceptor defines lifecycle callback interceptor methods, those lifecycle callback interceptor method are not invoked.


This specification is talking about one interceptor class having two different types of interceptor methods (around-invoke and lifecycle interceptors).

I came up with an example of an interceptor class:



The @PostConstruct method of MyInterceptor won't be invoked as MyInterceptor is used as a method level interceptor.

However, in my previous example, there are two different interceptors, MyLifeCycleInterceptor and AroundInvokeInterceptor. The specification does not say the case when two different types of interceptors trying to intercept a method.
 
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender
Posts: 3121
259
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I was trying to say is that the specifications specify how to intercept a lifecycle callback event (e.g. PostConstruct, PreDestroy). That is with a @PostConstruct or @PreDestroy annotated method inside an Interceptor class.

My interpretation of this is that is no other way to intercept such a method and therefore the @AroundInvoke interceptor on top of a a lifecycle callback event would likely to be ignored.
 
Himai Minh
Ranch Hand
Posts: 1701
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Regarding to a mix of interceptor, I can demo this using Ivan's example in his chapter 6.



The result is:
1. The initialize() method is only intercepted by the @PostContruct method defined in LogInterceptor, but the @AroundInvoke method of the MyAroundInvokeInterceptor is ignored.
2. retrieveMessage() method is intercepted by the @AroundInvoke of MyAroundInvokeInterceptor.
Here is the output from the console:


LogInterceptor - constructor
Info: MyDefaultInterceptor.postContruct
Info: *** SingletonSessionBeanA - initialized
Info: MyDefaultInterceptor intercepting : SingletonSessionBeanA. retrieveMessage
Info: LogInterceptorSuperclass intercepting SingletonSessionBeanA.retrieveMessage
Info: LogInterceptor - entering method: retrieveMessage
Info: MyAroundInvoke - entering method: retrieveMessage
Info: *** retrieve message :Message from SingletonSessionBeanA-[no message set] Wed Mar 11 18:09:34 EDT 2015
Info: MyAroundInvoke- exiting method: retrieveMessage
Info: LogInterceptor- exiting method: retrieveMessage

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!