4 Replies Latest reply on Feb 7, 2010 11:17 PM by Yong Hao Gao

    CachedConnectionManager API issue

    Yong Hao Gao Master
      Hi guys,

      In AS 4.x the org.jboss.resource.connectionmanager.CachedConnectionManager has a method called setTransactionManagerServiceName(ObjectName). But in AS 5.x this method no longer exists.
      I'm having this issue in update JBoss Messaging's dependency to AS 5. Currently JBM uses this api in its tests, as showed in the following code:

         private void startCachedConnectionManager(ObjectName on) throws Exception
         {
            CachedConnectionManager ccm = new CachedConnectionManager();

            // dependencies
            ccm.setTransactionManagerServiceName(TRANSACTION_MANAGER_OBJECT_NAME);

            mbeanServer.registerMBean(ccm, on);
            mbeanServer.invoke(on, "start", new Object[0], new String[0]);
            log.debug("started " + on);
         }

      As the method setTransactionManagerServiceName(ObjectName), I don't know how to adapt the above code to the new JCA apis. Can you give some advice?

      Thanks

      Howard



        • 1. Re: CachedConnectionManager API issue
          Vicky Kak Master

          gaohoward wrote:

          As the method setTransactionManagerServiceName(ObjectName), I don't know how to adapt the above code to the new JCA apis. Can you give some advice?


           

          We could inject the tm like this

           

          TransactionManager tm = (TransactionManager) getServer().getAttribute(TRANSACTION_MANAGER_OBJECT_NAME
          ,"TransactionManager");

          ccm.setTransactionManager(tm);

           

          But this will not help you as the following would not behave well

                mbeanServer.invoke(on, "start", new Object[0], new String[0]);

           

          We may land up in code change in the CCM.

          Before we take a deep look into it, can you explain what exactly your test case is doing?

          1 of 1 people found this helpful
          • 2. Re: CachedConnectionManager API issue
            Yong Hao Gao Master
            Hi Vicky,

            Thanks for look after my question. JBM 1.x has a test framework to simulate a JBoss server runtime environment. The simulated server can be configured to selectively start a set of services such as
            Transactions, Remoting, Datasources, JCA services etc for different tests. The above mentioned method is used to start a JCA service, like:
                    
                     if (jca)
                     {
                        startCachedConnectionManager(CACHED_CONNECTION_MANAGER_OBJECT_NAME);
                       
                        // DefaultDS specific
                        startManagedConnectionFactory(DEFAULTDS_MANAGED_CONNECTION_FACTORY_OBJECT_NAME);
                        startManagedConnectionPool(
                              DEFAULTDS_MANAGED_CONNECTION_POOL_OBJECT_NAME,
                              DEFAULTDS_MANAGED_CONNECTION_FACTORY_OBJECT_NAME,
                              "ByContainer");
                        startConnectionManager(DEFAULTDS_CONNECTION_MANAGER_OBJECT_NAME,
                              true, true, TRANSACTION_MANAGER_OBJECT_NAME,
                              CachedConnectionManagerMBean.OBJECT_NAME,
                              DEFAULTDS_MANAGED_CONNECTION_POOL_OBJECT_NAME);
                        startWrapperDataSourceService();
                     }

            where CACHED_CONNECTION_MANAGER_OBJECT_NAME = new ObjectName("jboss.jca:service=CachedConnectionManager");
                  DEFAULTDS_MANAGED_CONNECTION_FACTORY_OBJECT_NAME = new ObjectName("jboss.jca:name=DefaultDS,service=ManagedConnectionFactory");
                  DEFAULTDS_MANAGED_CONNECTION_POOL_OBJECT_NAME = new ObjectName("jboss.jca:name=DefaultDS,service=ManagedConnectionPool");
                  DEFAULTDS_CONNECTION_MANAGER_OBJECT_NAME = new ObjectName("jboss.jca:name=DefaultDS,service=LocalTxCM");
                  TRANSACTION_MANAGER_OBJECT_NAME = new ObjectName("jboss:service=TransactionManager");

            My understanding is that it simulates a JCA start up in a JBoss server. This works with AS 4 lib set. Now I need this work with AS 5 too. It turned out AS 5 has changed the API. I don't know how to do it.

            I attached the source file (ServiceContainer) that contains the above code piece for your info.

            Thanks.
            • 3. Re: CachedConnectionManager API issue
              Vicky Kak Master

              gaohoward wrote:


              My understanding is that it simulates a JCA start up in a JBoss server. This works with AS 4 lib set. Now I need this work with AS 5 too. It turned out AS 5 has changed the API. I don't know how to do it.

               

              The code basically plugs in the JCA infrastruture MBeans for the testcase.

              You can knock off the following call

              mbeanServer.invoke(on, "start", new Object[0], new String[0]);
              


              This basically was calling the startService() operation in 4.x implementation which had been doing this

               

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

               

              With Jboss5 we only need to set the TM which can be done by calling the

              setTransactionManager() on the CachedConnectionManager implenetation, check code
              https://svn.jboss.org/repos/jbossas/trunk/connector/src/main/java/org/jboss/resource/connectionmanager/CachedConnectionManager.java

              The other parts are knocked off as needed for this
              https://jira.jboss.org/jira/browse/JBAS-6159

              So what I had pointed before should be helpful, you should knockoff the call on start() operation on the CCM in your testcase.

              Also I am wondering if you really need to plugin the CCM, the CCM is used to track the connection taken by the meta-ware objects.
              I am not sure if your test case need it, this is what you will have to check.

              Go ahead and try the approach which I had suggested and let us know if you see red signal.
              • 4. Re: CachedConnectionManager API issue
                Yong Hao Gao Master

                Thanks Vicky, I'll try it.

                 

                Howard