Troubleshooting

   

The Message-Driven Bean and the Container

From the message bean's creation until its destruction, the container manages message-driven beans exclusively. All the services offered to the other two enterprise beans, such as security, transaction support, and concurrency, are also provided to the message-driven bean by the container.

The container interacts with the message-driven bean through a set of callback methods that are implemented in the message-driven bean. These callback methods are similar to the ones used by session and entity beans. The methods tell the bean instance when certain events are about to occur or have occurred.

The Message-Driven Bean Life Cycle

Figure 11.2 shows the life cycle for message-driven beans.

Figure 11.2. The life cycle of a message-driven bean.

graphics/11fig02.gif

Message-driven beans are normally created when the container first starts up. The vendor-specific deployment descriptor may give the bean deployer or assembler the ability to specify how many initial message-driven beans are available at startup and also how many maximum beans should be created. It's up to the container to ensure that the bean instances are available before JMS messages start arriving.

The container first calls the no-argument constructor for the bean. Next, the container calls the setMessageDrivenContext method and associates a MessageDrivenContext with the bean instance. Finally, the container calls the ejbCreate method on the instance. Here, you can put initialization code if your bean instance needs certain resources to complete the business logic. These resources could be things such as a JavaMail session or a JDBC connection.

Tip

There's no reason to have other constructors in the message-driven bean class, because the container will only call the no argument version.




Special Edition Using Enterprise JavaBeans 2.0
Special Edition Using Enterprise JavaBeans 2.0
ISBN: 0789725673
EAN: 2147483647
Year: 2000
Pages: 223

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net