I am reading EJB 3.1 specification and came across text containing "Interceptors" eg:
4.3.4 Session Bean Lifecycle Callback Interceptor Methods
The following lifecycle event callbacks are supported for session beans. Lifecycle callback interceptor
methods may be defined directly on the bean class or on a separate interceptor class.
So,I have couple questions on this .They are :
1.What exactly does "Interceptor" mean ? 2.How are Interceptor related to EJB ? 3.Are Life-cycle methods of different types of EJB called as Interceptors ?
Just for curiosity: are you also reading a book aside the specs? Otherwise the specs can be quite tough to read and understand.
1.What exactly does "Interceptor" mean ?
2.How are Interceptor related to EJB ?
3.Are Life-cycle methods of different types of EJB called as Interceptors ?
1) An interceptor gives you the possibility to get "in between" the call to a certain method (just before and just after a call). Interceptors for EJBs are defined in their own specs JSR-318 Interceptors ("Specification"). Interceptors are also described for other EE-components in JSR-299.
2) It is a service of the container where the container will call the interceptor method on any EJB or on specific EJB's. You can for example add logging functionality to all you EJBs without having to interfere with the business logic inside the EJB. Have a look at the example (ch. 4.12) in my notes ScbcdLinks.
3) No. You can intercept a call to a lifecycle method with an interceptor.