12.11.2014 Views

web server - Borland Technical Publications

web server - Borland Technical Publications

web server - Borland Technical Publications

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Transaction manager services<br />

EJBs and 2PC transactions<br />

With the introduction of messaging in the J2EE platform, a number of common<br />

scenarios now exist involving access to multiple resources from EJBs in a single<br />

transaction. As we know, when more than one resource is involved in a transaction, the<br />

OTS engine is needed to reliably complete the transaction using the two-phase commit<br />

protocol. Sample scenarios include:<br />

■<br />

■<br />

A session bean accesses two types of entity beans in a transaction where each are<br />

persisted in a different database.<br />

A session bean accesses an entity bean and in the same transaction does some<br />

messaging work, such as sending a message to a JMS queue.<br />

■<br />

In the onMessage method of a message-driven bean, access entity beans on<br />

message delivery.<br />

In each of the above examples, two heterogeneous resources need to be accessed<br />

from within a session bean or a message-driven bean as part of a single transaction.<br />

These EJBs have the REQUIRED transaction attribute defined and need access to the<br />

OTS engine. However, if the OTS engine is running, then all modules deployed to that<br />

Partition are able to discover it and can attempt to use it. The OTS engine will perform<br />

a one-phase commit when only one resource is registered in a transaction, but suffers<br />

the extra RMI overhead since it is an external process. Ideally, the in-process<br />

Transaction Manager should be used for EJBs not involved in a two-phase commit<br />

transaction. To better utilize the transaction services available in BES, a bean-level<br />

property, ejb.transactionManagerInstanceName may be specified for EJBs that require<br />

2PC transaction completion. This property provides the name of the OTS engine to be<br />

used by the EJB container doing transaction demarcation on any of the methods for the<br />

relevant bean. Both the Transaction Manager and the OTS engine may be available for<br />

all EJBs but only those that do not have ejb.transactionManagerInstanceName specified<br />

will discover the Transaction Manager.<br />

This property can be commonly used for session or message-driven beans since<br />

transactions are usually demarcated in a session bean facade or the onMessage method<br />

of a message-driven bean.<br />

To set the ejb.transactionManagerInstanceName property use the Management Console.<br />

Navigate to your deployed EJB module, right-click on it and select “DDEditor”. In the<br />

DDEditor select the required bean from the Navigation Pane. Select the “Properties”<br />

tab and add the ejb.transactionManagerInstanceName property. Define the property as a<br />

String and specify a unique name value such as “MyTwoPhaseEngine”.<br />

Next, you must modify the OTS engine factory name with the<br />

ejb.transactionManagerInstanceName value. In the Management Console, select the<br />

OTS engine from the “corbaSample” configuration, identified as the “OTS engine”<br />

managed object type. Right-click and select “Properties” from the drop-down menu. In<br />

the Properties dialog choose the Settings tab and modify the value for “Factory Name”.<br />

Click OK, and restart the service. The OTS engine may also be started from the<br />

command line, independent of a BES <strong>server</strong>. The factory name can be provided using<br />

property vbroker.ots.name as follows:<br />

prompt> ots -Dvbroker.ots.name=<br />

The EJB will now use the OTS engine named “MyTwoPhaseEngine”. As mentioned,<br />

the Partition may be hosting several J2EE modules, but only those beans that have<br />

ejb.transactionManagerInstanceName set go to the (non-default) OTS engine. Other<br />

beans in the Partition that require method invocation in a transaction, but do not require<br />

2PC, always find the Transaction Manager due to local service affinity.<br />

Chapter 19: Transaction management 171

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!