![]() ![]() ![]() ![]() ![]() ![]() ![]() |
WebLogic Server can participate in distributed transactions coordinated by third-party systems (referred to as foreign transaction managers). The WebLogic Server processing is done as part of the work of the external transaction. The foreign transaction manager then drives the WebLogic Server transaction manager as part of its commit processing. This is referred to as “importing” transactions into WebLogic Server.
The following sections describe the process for configuring and participating in foreign-managed transactions:
The WebLogic Server transaction manager exposes a javax.transaction.xa.XAResource
implementation via the weblogic.transaction.InterposedTransactionManager
interface. A foreign transaction manager can access the InterposedTransactionManager
interface to coordinate the WebLogic Server transaction manager XAResource during its commit processing.
When importing a transaction from a foreign transaction manager into the WebLogic Server transaction manager, you must register the WebLogic Server interposed transaction manager as a subordinate with the foreign transaction manager. The WebLogic Server transaction manager then acts as the coordinator for the imported transaction within WebLogic Server.
WebLogic Server supports two configuration schemes for importing transactions:
Although there are some differences in limitations and in implementation details, the basic behavior is the same for importing transactions in both configurations:
You can use the client interposed transaction manager in WebLogic Server to drive the two-phase commit process for transactions that are coordinated by a third-party transaction manager and include transaction participants within WebLogic Server, such as JMS resources and JDBC resources. The client interposed transaction manager is an implementation of the javax.transaction.xa.XAResource
interface. You access the client interposed transaction manager directly from the third-party application, typically from a gateway in the third-party application. The transaction manager in the third-party system then sends the prepare and commit messages to the gateway, which propagates the message to the WebLogic Server transaction manger. The WebLogic Server transaction manager then acts as a subordinate transaction manager and coordinates the transaction participants within WebLogic Server. Figure 12-1 shows the interaction between the two transaction managers and the client-side gateway.
Figure 12-2 shows the flow of interactions between a foreign transaction manager, WebLogic Server client-side JTA objects, and the WebLogic Server transaction manager.
To access the interposed transaction manager in WebLogic Server using a client-side gateway, you must perform the following steps:
In a client-side gateway, the you can get the WebLogic server interposed transaction manager's XAResource with the getClientInterposedTransactionManager
method. For example:
import javax.naming.Context;
import weblogic.transaction.InterposedTransactionManager;
import weblogic.transaction.TxHelper;
Context initialCtx;
String serverName;
InterposedTransactionManager itm = TxHelper.getClientInterposedTransactionManager(initialCtx, serverName);
The server name parameter is the name of the server that acts as the interposed transaction manager for the foreign transaction. When the foreign transaction manager performs crash recovery, it needs to contact the same WebLogic Server server to obtain the list of in-doubt transactions that were previously imported into WebLogic Server.
See the WebLogic Server Javadocs for the weblogic.transaction.TxHelper class for more information.
After you get the interposed transaction manager, you must get the XAResource object associated with the interposed transaction manager:
import javax.transaction.xa.XAResource;
XAResource xar = itm.getXAResource();
Note the following limitations when importing transactions using a client-side gateway:
TxHelper.getServerInterposedTransactionManager()
method in client-side gateways.
You can use the server interposed transaction manager in WebLogic Server to drive the two-phase commit process for transactions that are coordinated by a third-party transaction manager and include transaction participants within WebLogic Server, such as JMS resources and JDBC resources. The server interposed transaction manager is an implementation of the javax.transaction.xa.XAResource
interface. You access the server interposed transaction manager by creating a server-side gateway on WebLogic Server and then accessing the gateway from a third-party system. The transaction manager in the third-party system then sends the prepare and commit messages to the server-side gateway, which propagates the message to the WebLogic Server transaction manger. The WebLogic Server transaction manager then acts as a subordinate transaction manager and coordinates the transaction participants within WebLogic Server. Figure 12-3 shows the interaction between the two transaction managers and the server-side gateway.
To access the interposed transaction manager in WebLogic Server using a server-side gateway, you must perform the following steps:
In a server-side gateway, you can get the interposed transaction manager's XAResource as follows:
import javax.naming.Context;
import weblogic.transaction.InterposedTransactionManager;
import weblogic.transaction.TxHelper;
InterposedTransactionManager itm = TxHelper.getServerInterposedTransactionManager();
See the WebLogic Server Javadocs for the weblogic.transaction.TxHelper class for more information.
After you get the interposed transaction manager, you must get the XAResource. See Get the XAResource from the Interposed Transaction Manager.
Note the following limitations when importing transactions using a server-side gateway:
TxHelper.getClientInterposedTransactionManager()
method in a server-side gateway on a WebLogic Server server. Doing so will cause performance issues.
To import a foreign transaction into WebLogic Server, the foreign transaction manager or gateway can do the following:
xar.start(foreignXid, TMNOFLAGS);
This operation associates the current thread with the imported transaction. All subsequent calls made to other servers will propagate the imported WebLogic Server transaction, until the transaction is disassociated from the thread.
Note: | The flag is ignored by the WebLogic Server transaction manager. If the foreign Xid has already been imported previously on the same WebLogic Server server, WebLogic Server will associate the current thread with the previously imported WebLogic Server transaction. |
To disassociate the imported transaction from the current thread, the foreign transaction manager or gateway should do the following:
xar.end(foreignXid, TMSUCCESS);
Note that the WebLogic Server transaction manager ignores the flag.
Note the following processing limitations and behavior for imported transactions:
xar.start
on one client interposed transaction manager at a time. Attempting to call xar.start
on another client interposed transaction manager (before xar.end
was called on the first one) will throw an XAException
with XAER_RMERR
. With a server-side gateway, attempting to call xar.start
on a client or server interposed transaction manager will also throw a XAException
with XAER_RMERR
if there is already an active transaction associated with the current thread.
The foreign transaction manager should drive the interposed transaction manager in the 2PC protocol as it does the other XAResources. Note that the beforeCompletion
callbacks registered with the WebLogic Server JTA (e.g., the EJB container) are called when the foreign transaction manager prepares the interposed transaction manager's XAResource. The afterCompletion
callbacks are called during XAResource.commit
or XAResource.rollback
.
The WebLogic Server interposed transaction manager honors the XAResource contract as described in section 3.4 of the JTA 1.0.1B specification:
The WebLogic Server transaction manager logs a prepare
record for the imported transaction after all the WebLogic Server participants are successfully prepared. If there are more than one WebLogic Server participants for the imported transaction, the transaction manager logs a prepare record even if the XAResource.commit
is a one-phase commit.
During the crash recovery of the foreign transaction manager, the foreign transaction manager must get the XAResource of the WebLogic Server interposed transaction manager again, and call recover on it. The WebLogic Server interposed transaction manager then returns the list of prepared or heuristically completed transactions. The foreign transaction manager should then resolve those in-doubt transactions: either commit or rollback the prepared transactions, and call forget on the heuristically completed transactions.
![]() ![]() ![]() |