5 Replies Latest reply on Feb 3, 2005 10:20 AM by Charles Crouch

    Finding deployed datasources via JMX

    Charles Crouch Expert

      I'm looking to find all DataSources deployed into a JBoss instance via JMX.
      My question is whether querying the JBoss MBeanserver for MBeans which match the following patterns will return ConnectionManagers for all DataSources:

      jboss.jca:service=NoTxCM,*
      jboss.jca:service=LocalTxCM,*
      jboss.jca:service=XATxCM,*

      Testing with the -ds.xml files from jboss-4.0.1\docs\examples\jca indicates that for all DataSources a ConnectionManager is returned, and also no additional non-DataSource ConnectionManagers are returned.

      Thanks

        • 1. Re: Finding deployed datasources via JMX
          Scott Stark Master

          The definitive source for the datasource mbean names is the ConnectionFactoryTemplate.xsl used by the deployer which processes the *-ds.xml deployemnts.

           <xsl:template match="local-tx-datasource">
           <mbean code="org.jboss.resource.connectionmanager.TxConnectionManager"
           name="jboss.jca:service=LocalTxCM,name={jndi-name}"
           display-name="ConnectionManager for DataSource {jndi-name}">
          ...
          
           <xsl:template match="no-tx-datasource">
           <mbean code="org.jboss.resource.connectionmanager.NoTxConnectionManager"
           name="jboss.jca:service=NoTxCM,name={jndi-name}"
           display-name="ConnectionManager for DataSource {jndi-name}">
          ...
          
           <xsl:template match="xa-datasource">
           <mbean code="org.jboss.resource.connectionmanager.TxConnectionManager"
           name="jboss.jca:service=XATxCM,name={jndi-name}"
           display-name="ConnectionManager for DataSource {jndi-name}">
          
          ...
          
          


          However, the same base pattern is also used for the generic connection factory mappings:
           <!-- template for generic resource adapters supporting transactions -->
           <xsl:template match="tx-connection-factory">
           <mbean code="org.jboss.resource.connectionmanager.TxConnectionManager"
           name="jboss.jca:service=TxCM,name={jndi-name}"
           display-name="ConnectionManager for ConnectionFactory {jndi-name}">
          ...
          
           <xsl:template match="no-tx-connection-factory">
           <mbean code="org.jboss.resource.connectionmanager.NoTxConnectionManager"
           name="jboss.jca:service=NoTxCM,name={jndi-name}"
           display-name="ConnectionManager for ConnectionFactory {jndi-name}">
          ...
          
          


          You can't distinguish between a no-tx-connection-factory deployment and a no-tx-datasource deployment by looking at the mbean name alone. There are attributes that can be used to differentiate one from the other though. In 4.0.x a datasource has a JMXInvokerName attribute while a connection factory does not. This diff does not exist in 3.2. It would probably be better to explicitly tag the datasource as such with an additional jcaType=DataSource attribute in the name.


          • 2. Re: Finding deployed datasources via JMX
            Charles Crouch Expert

            Thanks very much.

            Since I'm concentrating on 4.0.x at the moment I don't mind using 4.0.x specific features. On 4.0.x searching for "jboss.jca:service=DataSourceBinding,*" returns MBeans which reference all deployed datasources. Looking at ConnectionFactoryTemplate.xsl appears to confirm this.

            I think I will use the search above to get all the DataSources then retrieve the ConnectionManager attribute which holds an ObjectName. I can then check this ObjectName to return only those of the appropriate type, e.g. where ObjectName.getKeyProperty("service") = LocalTxCM, NoTxCM, or XATxCM.

            Going forward I agree with your idea of adding a 'jcaType=DataSource' element to the ObjectName, it is a much cleaner solution. Would the name of the associated ConnectionManager MBean be the right one to update?

            Thanks

            • 3. Re: Finding deployed datasources via JMX
              Scott Stark Master

              Yes, the 3 *-datasource templates should be updated with an additional attribute to identify them as jdbc datasources.

              • 4. Re: Finding deployed datasources via JMX
                Adrian Brock Master

                The problem is that this will only work if the datasource is deployed by the shorthand

                <xxx-data-source/>

                which deploys managed connection factories (MCF) from JBoss's jdbc rars.

                Somebody can:
                1) Deploy it long hand with a
                <xx-connection-factory>

                2) Use somebody else's rar, e.g. people seem to want to do this for firebird which
                has its own rar?

                The same is true if you are looking at DataSourceBindings (only created when
                you use the xxx-data-source).

                A more reliable mechanism would be to query all the MCFs
                and check they expose javax.sql.DataSource as the ConnectionFactory interface:

                MBeanServer server = ...
                Set mcfNames = server.queryNames
                (
                 new ObjectName("jboss.jca:service=ManagedConnectionFactory,*"),
                 Query.eq(Query.attr("ConnectionFactoryInterface"), Query.value("javax.sql.DataSource"))
                ) ;
                



                • 5. Re: Finding deployed datasources via JMX
                  Charles Crouch Expert

                  Thanks Adrian. At the moment I will take a solution which only works with the shorthand DataSource deployment method, although one which works for all DataSources would definitely be superior.
                  I think you mean the ConnectionDefinition attribute on a ManagedConnectioFactory rather than the ConnectionFactoryInterface attribute, since this appears to be empty on jboss.jca:name=DefaultDS,service=ManagedConnectionFactory. One issue is that having a reference to the ManagedConnectionFactory is slightly less useful than a reference to the ConnectionManager. With the ConnectionManager I can dereference its ManagedConnectionPool attribute to get the corresponding MBean and then use an attribute on that to get to the ManagedConnectionFactory MBean. With just a reference to the ManagedConnectionFactory "going back up the tree" requires me to manually construct the ObjectNames of the ManagedConnectionPool and ConnectionManager, which is obviously more fragile.

                  Thanks