In the specification in the section 12.1.Overview (page 301 in my version) I found this text :
It is possible to carry state across multiple interceptor method invocations for a single business method invocation or lifecycle callback event for a bean in the context data of the InvocationContext
What I understand is : if I invoke more interceptor methods with the same call (business method) I can preserve the state. The same logic for the life cycle methods.
Or more simple the state is preserved as long as I am in the same InvocationContext.
Am I right ?
These objects can be shared between the different interceptors.
If you use
invocationContext.getContextData().put("objectname","object") in one interceptor.
You will retrieve the value with
invocationContext.getContextData().get("objectname") in the next interceptors in the invocation chain.
An Interceptor can have state or not. By state I mean fields (can base its logic on the fields values).
IMHO no, with only one exception, the interceptors for the statefull bean.
I base this assumption on the next extract from "12.2 Interceptor Life Cycle"
The lifecycle of an interceptor instance is the same as that of the bean instance with which it is associated. When the bean instance is created, interceptor instances are created for each interceptor class defined for the bean. These interceptor instances are destroyed when the bean instance is removed.
Am I right ?