Life Cycle of a Message-Driven Bean

The EJB container controls the lifecycle of a Message-driven bean. The Message-driven bean instance lifecycle has three states, as shown in Figure 10.1:

  • Does Not Exist— The Message-driven bean has not been instantiated yet or is awaiting garbage collection.

  • Method Ready Pool— A pool of Message-driven bean instances, similar to the instance pool used for stateless session beans.

  • Processing a message— The Message-driven bean has been instantiated and is handling a message.

Figure 10.1. The Message-driven bean life cycle.


After constructing the new instance of the Message-driven bean object, the container invokes the following methods:

  • The bean's setMessageDrivenContext() method with a reference to its EJB context. The Message-driven bean should store its MessageDrivenContext reference in an instance field.

  • The bean's ejbCreate() method. The Message-driven bean's ejbCreate() method takes no arguments and is invoked only once when the bean is first instantiated.

The Message-Driven Bean Context

The javax.ejb.MessageDrivenContext interface (see the class diagram in Figure 10.2). provides the Message-driven bean with access to its runtime context. This is similar to the SessionContext and EntityContext interfaces for Session and Entity beans.

Figure 10.2. The MessageDrivenContext class diagram.


Note that all the EJBContext methods are available to a Message-driven bean, but because the Message-driven bean does not have a local or remote interface, calls to getEJBHome() and getEJBLocalHome() will throw a java.lang.IllegalStateException.

Because Message-driven beans are anonymous and run within the context of the container, and the container does not have a client security identity or role, calls to the getCallerPrincipal() and IsCallerInRole() methods will also cause an IllegalStateException.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.59.209.131