• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

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

 
Saloon Keeper
Posts: 2450
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 3412
320
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Saloon Keeper
Posts: 2450
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 3412
320
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Saloon Keeper
Posts: 2450
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

reply
    Bookmark Topic Watch Topic
  • New Topic