[Design of EJB 3.0] - Re: UserTransactedStartedListener is not implemented in EJB3
by adrian@jboss.org
I think the way this does is pretty bad.
It requires each UserTransaction to implement a static method
to inject the transaction started listener
| //Registration for CachedConnectionManager so our UserTx can notify
| //on tx started.
| private static ServerVMClientUserTransaction.UserTransactionStartedListener tsl;
|
| /**
| * The <code>setUserTransactionStartedListener</code> method is called by
| * CachedConnectionManager on start and stop. The tsl is notified on
| * UserTransaction.begin so it (the CachedConnectionManager) can enroll
| * connections that are already checked out.
| *
| * @param newTsl a <code>ServerVMClientUserTransaction.UserTransactionStartedListener</code> value
| */
| public static void setUserTransactionStartedListener(ServerVMClientUserTransaction.UserTransactionStartedListener newTsl)
| {
| tsl = newTsl;
| }
|
Then the cached connection manager (CCM) needs to know about all listeners:
|
| protected void startService()
| throws Exception
| {
| tm = (TransactionManager) getServer().getAttribute(transactionManagerServiceName,
| "TransactionManager");
| TransactionSynchronizer.setTransactionManager(tm);
| ServerVMClientUserTransaction.getSingleton().registerTxStartedListener(this);
| EnterpriseContext.setUserTransactionStartedListener(this);
| }
|
It would be much better if the CCM had a single place to register the listener
and then each UserTransaction notified that single place of transaction start.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4059563#4059563
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4059563
17 years, 8 months
[Design of EJB 3.0] - UserTransactedStartedListener is not implemented in EJB3
by adrian@jboss.org
This relates to JBCTS-599 but I can explain it without reference to that.
There is a little known feature in JavaEE called lazy transaction enlistment.
It basically works with the UserTransaction where you retrieve a connection
before starting the transaction and then ut.begin() enlists the connection.
| // BMT EJB(3) method
| public void doSomething()
| {
| DataSource ds = ...
| Connection c = ds.getConnection(); // Not enlisted in transaction, there isn't one
| UserTransaction ut = ...
| ut.begin(); // the connection is enlisted in the transaction
| }
|
It even works across multiple transactions
| public void doSomething()
| {
| DataSource ds = ...
| Connection c = ds.getConnection(); // Not enlisted in transaction, there isn't one
| UserTransaction ut = ...
| ut.begin(); // the connection is enlisted in the transaction
| ut.commit(); // connections is unenlisted
| ut.begin(); connection is enlisted in the new/different transaction
| }
|
The problem is that EJB3 is not firing the transaction started events
from its user transaction.
Compare EJB2/EJB3:
org.jboss.ejb.EnterpriseContext/org.jboss.ejb3.tx.UserTransactionImpl
|
| public void begin()
| throws NotSupportedException, SystemException
| {
| TransactionManager tm = con.getTransactionManager();
|
| int oldTimeout = -1;
| if (tm instanceof TransactionTimeoutConfiguration)
| oldTimeout = ((TransactionTimeoutConfiguration) tm).getTransactionTimeout();
|
| // Set the timeout value
| tm.setTransactionTimeout(timeout);
|
| try
| {
| // Start the transaction
| tm.begin();
|
| // HERE!!!!!!!!!!!!! notify checked out connections
| if (tsl != null)
| tsl.userTransactionStarted();
|
| Transaction tx = tm.getTransaction();
| if (trace)
| log.trace("UserTx begin: " + tx);
|
In fact, if you compare the two classes you'll see that the EJB3
user transaction is incomplete in other ways (such as resetting
the transaction timeout after the begin).
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4059560#4059560
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4059560
17 years, 8 months