|
Summary: The XA specification and its Java version (JTA) introduce a standard way to control and manage distributed transactions among different participants.
OverviewThe XA specification and its Java version (JTA) introduce a standard way to control and manage distributed transactions among different participants. The JTA defines two major entities from our point of view: the Transaction Manager and XAResource. The Transaction Manager acts as a transaction coordinator and responds to the transaction context (start, end, suspend and resume) and its completion using a 2PC protocol. The XAResource represents the resource manager and responds to answers from 2PC commands sent by the Transaction Manager.
Transaction SequenceThe typical transaction sequence should look like this:
When the T.M. starts or recovers, it should call recover() on all the known XAResources, which should return all the prepared transaction XIDs. XA vs. Jini TransactionThe XA API (JTA) differs from the Jini Transaction API in two major respects:
Using XA Global Transactions without JCAGigaSpaces can participate in global (XA) transactions, even when it is not connected with JCA. Involving the space in XA transactions requires the following:
Involving Space with Global Transactions without JCAThe code example below is run in the WebLogic AppServer, but it can be modified to work with other vendors as well. To create the XAResource, do as follows: LocalTransactionManager gigaspacesTM = LocalTransactionManager)LocalTransactionManager.getInstance(spaceInstance);
xaRes = new XAResourceImpl(gigaspacesTM, (ActionMaker)spaceInstance);
In the transacted EJB method, you enlist the XAResource to the current transaction: javax.transaction.Transaction txn = weblogic.transaction.TransactionHelper.getTransactionHelper().getTransaction(); txn.enlistResource(xaRes); ExampleThe ReplicatedSessionBean example write() method can be run in a global transaction. To test it:
|
(works on Firefox 2 and Internet Explorer 7)
