Skip Headers
Oracle® Containers for J2EE Enterprise JavaBeans Developer's Guide
10g (10.1.3.5.0)

Part Number E13981-01
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Index
Index
Go to Feedback page
Contact Us

Go to previous page
Previous
Go to next page
Next
View PDF

Configuring a Life Cycle Callback Interceptor Method on an Interceptor Class of an EJB 3.0 MDB

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:

  1. Create an interceptor class.

    This can be any POJO class.

    An interceptor class must have a public no-argument constructor.

  2. Implement the life cycle callback interceptor method.

    Callback methods defined on a bean's interceptor class have the following signature:

    Object <METHOD>(InvocationContext)
    
  3. 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:

  4. 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:

Using Annotations

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:

  • @PostConstruct

  • @PreDestroy

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();
        ...
    }
}