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

Sun Microsystems Inc.

Support for Distribution and Interoperability

Enterprise JavaBeans 2.0, Public Draft

Transaction interoperability

18.4.4 Obtaining stub and value classes

When a J2EE component (application client, JSP, servlet or enterprise bean) receives a reference to an EJBObject or EJBHome object through JNDI lookup or as a parameter or return value of an invocation on an enterprise bean, an instance of an RMI-IIOP stub class (proxy) for the enterprise bean’s home or remote RMI interface needs to be created. When a component receives a value object as a parameter or return value of an enterprise bean invocation, an instance of the value class needs to be created. The stub or value class must be available to the receiving container (the container which hosts the component which receives the reference or value type).

It is recommended that RMI-IIOP stub and value classes be designed in a portable manner so that they can be instantiated in a different vendor’s container. Stub classes should be generated using the portable stub APIs defined in the Java Language to IDL Mapping specification. Value classes are portable if they use only standard J2EE and J2SE APIs.

All RMI-IIOP stub and value classes that may be needed by a container are required to be installed in the container’s environment during deployment. Stub classes may be generated by the receiving container from the RMI interfaces for the bean provided in the client jar file specified in the ejb-cli- ent-jar element of the deployment descriptor for enterprise beans. Alternatively, the stub classes may be provided by the server EJB container in a product-specific way. Value classes may be obtained from the ejb-client-jar file for enterprise beans and the J2EE application archive file for other J2EE components.

Containers may optionally support run-time downloading of stub and value classes needed by the receiving container. The CORBA 2.3.1 specification and the Java Language to IDL Mapping specify how stub and value type implementations are to be downloaded: using codebase URLs that are either embedded in the EJBObject or EJBHome’s IOR, or sent in the IIOP message service context, or marshaled with the value type. The URLs for downloading may optionally include an HTTPS URL for secure downloading.

In order to develop portable applications, developers should ensure that each J2EE component is packaged along with all stub and value classes it may need for communicating with enterprise beans.

18.5 Transaction interoperability

Transaction interoperability between containers provided by different vendors is an optional feature in this version of the EJB specification. Vendors may choose to not implement the transaction interoperability requirements. However, vendors who choose to implement transaction interoperability must follow the requirements in sections 18.5.1 and 18.5.2, and vendors who choose not to implement transaction interoperability must follow the requirements in section 18.5.2.

18.5.1 Transaction interoperability requirements

A distributed transaction started by a web or EJB container must be able to propagate in a remote invocation to an enterprise bean in an EJB container provided by a different vendor, and the containers must participate in the distributed two-phase commit protocol.

5/31/00

364

Sun Microsystems Inc

Transaction interoperability

Enterprise JavaBeans 2.0, Public Draft

Support for Distribution and Interoperability

18.5.1.1 Transaction context wire format

Transaction context propagation from client to EJB container uses the implicit propagation mechanism described in the CORBA Object Transaction Service (OTS) v1.1 specification [ 8 ].

The transaction context format in IIOP messages is specified in the CosTransactions::PropagationContext structure described in the OTS specification. EJB containers that support transaction interoperability are required to be capable of producing and consuming transaction contexts in IIOP messages in the format described in the OTS specification. Web containers that support transaction interoperability are required to include client-side libraries which can produce the OTS transaction context for sending over IIOP.

Note that it is not necessary for containers to include the Java mappings of the OTS APIs. A container may implement the requirements in the OTS specification in any manner, for example using a non-Java OTS implementation, or an on-the-wire bridge between an existing transaction manager and the OTS protocol, or an OTS wrapper around an existing transaction manager.

The CORBA Messaging Service specification [ 16 ], section 9.5, describes changes to the OTS 1.1 specification [29]. The CosTransactions::PropagationContext structure must be included in IIOP messages sent by clients using the rules described in the Messaging Service’s changes to the OTS. The server should also process invocations on transactional EJBObject or EJBHome references using the rules described in the Messaging Service’s changes to the OTS.

18.5.1.2 Two-phase commit protocol

The object interaction diagram below illustrates the interactions between the client and server transaction managers for transaction context propagation, resource and synchronization object registration, and two-phase commit. This diagram is an example of the interactions between the various entities, it is not intended to be prescriptive.

[29]Note that the CORBA Messaging Service itself is not required. Only the changes to OTS contained in the Messaging Service document are needed. This section will reference the OTS1.2 specification when it is available, which will contain these changes.

365

5/31/00

Sun Microsystems Inc.

Support for Distribution and Interoperability

Enterprise JavaBeans 2.0, Public Draft

Transaction interoperability

client

client’s

server’s

EJB

EJB

Resource

transaction

transaction

container

manager

container

instance

Manager

manager

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

sending request

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

IIOP request message with transaction context

 

 

 

 

 

 

 

 

 

 

 

 

 

 

1

 

 

 

 

received request

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

register synchronization

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

register synchronization (optional)

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

2

 

 

 

 

 

 

 

 

invoke bean

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

access resource

 

 

 

 

 

 

 

 

 

 

enlist resource

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

register resource

3

sending reply

IIOP reply message

4

received reply

commit

before_completion

5

before_completion

ejbStore

flush state

prepare

6

prepare

commit

7

commit

5/31/00

366

Sun Microsystems Inc

Transaction interoperability

Enterprise JavaBeans 2.0, Public Draft

Support for Distribution and Interoperability

Containers that performed transactional work within the scope of a transaction must register an OTS Resource object with the transaction coordinator whose object reference is included in the propagated transaction context (step 3), and may also register an OTS Synchronization object (step 2). If the server container does not register an OTS Synchronization object, it must still ensure that the beforeCompletion method of session beans and ejbStore method of entity beans are called with the proper transaction context. Containers must participate in the two-phase commit and recovery procedures performed by the transaction coordinator / terminator (steps 6,7), as described by the OTS specification.

Compliant J2EE containers must not use nested transactions in interoperability scenarios.

18.5.1.3 Transactional attributes of enterprise bean references

The Messaging Service’s changes to OTS include the CosTSInteroperation::TransactionPolicyComponent structure which is encoded in IORs as a tagged component with component id 26[30]. EJBObject and EJBHome references must contain this TransactionPolicyComponent tagged component[31].

The transaction attributes of enterprise beans can be specified per method, while in OTS the entire CORBA object has the same OTS transaction policy. The rules below ensure that the transaction context will be propagated if any method of an enterprise bean needs to execute in the client’s transaction context. However, in some cases there may be extra performance overhead of propagating the client’s transaction context even if it will not be used by the enterprise bean method.

The following rules list the OTS transaction policy values which must be assigned to EJBHome and EJBObject references:

For session beans that use bean-managed transactions, the transaction policy value must be

Allows_shared.

If all methods of an EJB interface (Home or Remote) have the transaction attribute Mandatory, the CORBA object for that interface must have the transaction policy Requires_shared.

If all methods of an EJB interface (Home or Remote) have the transaction attribute Never, the CORBA object for that interface must have the transaction policy Allows_none.

CORBA objects for all other EJB interfaces must have the transaction policy Allows_shared.

The CosTransactions::Synchronization object registered by the EJB container with the transaction coordinator should have the transaction policy value Allows_shared, to allow enterprise beans to do transactional work during the beforeCompletion notification from the transaction coordinator.

[30]This component id is assigned by the OTS1.2 RTF at OMG.

[31]One way to include the TransactionPolicyComponent in IORs is to create the object reference using a POA which has the TransactionalPolicy POA policy. Note that POA APIs are not required to be supported by server containers.

367

5/31/00