2 Replies Latest reply on Oct 1, 2008 8:58 AM by Adrian Brock

    UserTransactedStartedListener

    Adrian Brock Master

      Within JCA we have a requirement to be told when UserTransactions start
      so we can do the "lazy enlist" processing:
      http://wiki.jboss.org/wiki/LazyJCAEnlistment

      The wiring of this processing is horrible. It is hardcoded into the CCM (CachedConnectionManager).

      
       protected void startService()
       throws Exception
       {
       tm = (TransactionManager) getServer().getAttribute(transactionManagerServiceName,
       "TransactionManager");
       TransactionSynchronizer.setTransactionManager(tm);
       ServerVMClientUserTransaction.getSingleton().registerTxStartedListener(this);
       EnterpriseContext.setUserTransactionStartedListener(this);
       }
      
       protected void stopService() throws Exception
       {
       ServerVMClientUserTransaction.getSingleton().unregisterTxStartedListener(this);
       EnterpriseContext.setUserTransactionStartedListener(null);
       }
      


      As you can see this has a number of problems:

      1) The CCM has to be configured with a transaction manager. Something we
      want to make optional in the web-profile

      2) It has to know implementation details of the EJB2 container

      3) It doesn't know about EJB3 or any other supplier of a UT implementation

        • 1. Re: UserTransactedStartedListener
          Adrian Brock Master

          What I propose to do is add a new registry bean to transaction-service.xml

          This will use the MC (un)install callbacks to keep track of UserTransactionStartedListeners
          meaning they don't have to be directly configured with a reference to the UTs or the TM.
          If they are there, they will be linked together, otherwise they won't.

          The new registry will also allow mulitple listeners. Currently the api(s) only allow a singleton.

          For now I propose that the registry still has the hardwiring shown above,
          but including whatever EJB3 does to register a listener.

          A fix to this other side of the api requires more work, e.g.
          having the UT suppliers implement some interface such that the MC can
          also do (un)install callbacks without the registry having to be pre-coded with a list
          of available implementataions.

          • 2. Re: UserTransactedStartedListener
            Adrian Brock Master

            As an aside there's still one other part of the CCM that needs changing
            such that it can work without a TM configured.

            This is the code that tries to hand off connection close checking to the
            end of the transaction if it exists and hasn't already ended.

             private CloseConnectionSynchronization getCloseConnectionSynchronization(boolean createIfNotFound)
             {
             try
             {
             Transaction tx = tm.getTransaction();
             if (tx != null)
             {
             TransactionSynchronizer.lock(tx);
             try
             {
             CloseConnectionSynchronization cas = (CloseConnectionSynchronization) TransactionSynchronizer.getCCMSynchronization(tx);
             if (cas == null && createIfNotFound && TxUtils.isActive(tx))
             {
             cas = new CloseConnectionSynchronization();
             TransactionSynchronizer.registerCCMSynchronization(tx, cas);
             }
             return cas;
             }
             finally
             {
             TransactionSynchronizer.unlock(tx);
             }
             }
             }
             catch (Throwable t)
             {
             log.debug("Unable to synchronize with transaction", t);
             }
             return null;
             }
            


            This obviously needs some rewrite in the way it works.
            i.e. it needs to handle the case where there is no TM

            I guess the easiest solution is to have transaction-jboss-beans.xml
            inject the TM into the TransactionSynchronizer and then have the CCM
            delegate all TM operations to the TransactionSynchronizer.

            But this solution has the problem that a JCA implemenation detail is configured
            inside the transaction manager config. Although this might be appropriate for
            easily removing TM support, it is not appropriate for the opposite case
            where the TM is used without JCA.