Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Enterprise JavaBeans™ Specification, Version 2.0 - Sun Microsystems.pdf
Скачиваний:
14
Добавлен:
24.05.2014
Размер:
2.71 Mб
Скачать

Sun Microsystems Inc

Overview

Enterprise JavaBeans 2.0, Public Draft

Example Message-driven Bean Scenario

Chapter 15 Example Message-driven Bean Scenario

This chapter describes an example development and deployment scenario of a message-driven bean. We use the scenario to explain the responsibilities of the bean provider and those of the container provider.

The classes generated by the container provider’s tools in this scenario should be considered illustrative rather than prescriptive. Container providers are free to implement the contract between a mes- sage-driven bean and its container in a different way, provided that it achieves an equivalent effect (from the perspectives of the bean provider and the client-side programmer).

15.1 Overview

Wombat Inc. has developed the StockInfoBean message-driven Bean. The StockInfoBean is deployed in a container provided by the Acme Corporation.

15.2 Inheritance relationship

An example of the inheritance relationship between the interfaces and classes is illustrated in the following diagram:

295

5/31/00

Sun Microsystems Inc.

Example Message-driven Bean Scenario

Enterprise JavaBeans 2.0, Public Draft

Inheritance relationship

Figure 64 Example of Inheritance Relationships Between EJB Classes

java.io.Serializable

JDK

javax.jms.MessageListener

JMS

EnterpriseBean Enterprise

JavaBeans

MessageDrivenBean

enterprise bean provider (Wombat Inc.)

StockInfoBean

 

container

 

provider

AcmeBean

(Acme)

produced by Acme tools

AcmeStockInfoBean

extends or implements interface

extends implementation, code generation, or delegation

Java interface

Java class

5/31/00

296

Sun Microsystems Inc

Inheritance relationship

Enterprise JavaBeans 2.0, Public Draft

Example Message-driven Bean Scenario

15.2.1 What the message-driven Bean provider is responsible for

Wombat Inc. is responsible for providing the following:

Write the business logic in the message-driven Bean class (StockInfoBean), defining the onMessage method that is invoked when the bean is to service a JMS message. The mes- sage-driven Bean must implement the javax.ejb.MessageDrivenBean interface, and define the ejbCreate() method invoked at an EJB object creation.

Define a deployment descriptor that specifies any declarative metadata that the mes- sage-driven Bean provider wishes to pass with the Bean to the next stage of the development/deployment workflow.

15.2.2 Classes supplied by container provider

The following classes are supplied by the container provider Acme Corp:

The AcmeBean class provides additional state and methods to allow Acme’s container to manage its message-driven Bean instances.

15.2.3 What the container provider is responsible for

The tools provided by Acme Corporation are responsible for the following:

Generate the implementation of the message-driven Bean class suitable for the Acme container (AcmeStockInfoBean). AcmeStockInfoBean includes the business logic from the StockInfoBean class mixed with the services defined in the AcmeBean class. Acme tools can use inheritance, delegation, and code generation to achieve a mix-in of the two classes.

Many of the above classes and tools are container-specific (i.e., they reflect the way Acme Corp implemented them). Other container providers may use different mechanisms to produce their runtime classes, which will likely be different from those generated by Acme’s tools.

297

5/31/00

Sun Microsystems Inc.

Example Message-driven Bean Scenario

Enterprise JavaBeans 2.0, Public Draft

Inheritance relationship

5/31/00

298