Oracle® Containers for J2EE Enterprise JavaBeans Developer's Guide 10g (10.1.3.1.0) Part Number B28221-02 |
|
|
View PDF |
You can designate an interceptor method on an interceptor class of an EJB 3.0 message-driven bean as a life cycle callback interceptor method.
To configure a life cycle callback interceptor method on an interceptor class, you must do the following:
Create an interceptor class.
This can be any POJO class.
An interceptor class must have a public no-argument constructor.
Implement the life cycle callback interceptor method.
Callback methods defined on a bean's interceptor class have the following signature:
Object <METHOD>(InvocationContext)
Associate a life cycle event with the callback interceptor method.
A life cycle event can only be associated with one callback interceptor method, but a life cycle callback interceptor method may be used to interpose on multiple callback events. For example, @PostConstruct
and @PreDestroy
may appear only once in an interceptor class but you may associate both @PostConstruct
and @PreDestroy
with the same callback interceptor method.
For more information, see the following:
Associate the interceptor class with your EJB 3.0 message-driven bean (see "Configuring an Interceptor Class for an EJB 3.0 MDB").
For more information, see the following:
You can specify an interceptor class method as an EJB 3.0 message-driven bean life cycle callback method using any of the following annotations:
Example 10-10 shows an interceptor class using @PostConstruct
and @PreDestroy
annotations to identify myPostConstructMethod
and myPreDestroyMethod
as life cycle callback interceptor methods. OC4J invokes the appropriate life cycle method only when the appropriate life cycle event occurs. OC4J invokes all other non-life cycle interceptor methods (such as myInterceptorMethod
) each time you invoke a message-driven bean business method (see "Configuring an Interceptor Class for an EJB 3.0 MDB").
Example 10-10 Interceptor Class
public class MyInterceptor { ... public void myInterceptorMethod (InvocationContext ctx) { ... ctx.proceed(); ... } @PostConstruct public void myPostContructMethod (InvocationContext ctx) { ... ctx.proceed(); ... } @PreDestroy public void myPreDestroyMethod (InvocationContext ctx) { ... ctx.proceed(); ... } }